db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c..@apache.org
Subject svn commit: r677080 - in /db/jdo/trunk/tck2/src/java/org/apache/jdo/tck: AbstractReaderTest.java mapping/AbstractRelationshipTest.java mapping/CompletenessTest.java query/QueryTest.java
Date Tue, 15 Jul 2008 22:44:37 GMT
Author: clr
Date: Tue Jul 15 15:44:36 2008
New Revision: 677080

URL: http://svn.apache.org/viewvc?rev=677080&view=rev
Log:
JDO-555 refactor Query and Completeness tests for security

Added:
    db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/AbstractReaderTest.java   (with props)
Modified:
    db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/AbstractRelationshipTest.java
    db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/CompletenessTest.java
    db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/QueryTest.java

Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/AbstractReaderTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/AbstractReaderTest.java?rev=677080&view=auto
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/AbstractReaderTest.java (added)
+++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/AbstractReaderTest.java Tue Jul 15 15:44:36
2008
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.beans.factory.xml.XmlBeanFactory;
+
+/*
+ * Abstract class for managed relationship tests
+ */
+public class AbstractReaderTest extends JDO_Test {
+
+    /** The list of all objects in the bean collection. */
+    protected List rootOids;
+
+    /** The name of the root object in the bean collection. */
+    protected static final String rootName = "root";
+
+    /** The name of the file containing the bean collection (test data). */
+    protected final String inputFilename = System.getProperty("jdo.tck.testdata");
+
+    /** The map of String (bean name) to Object (bean). */
+    protected Map oidMap = new HashMap();
+
+    /** Get the named bean from the bean factory.
+     * 
+     * @param reader the xml bean reader
+     * @param name the name of the bean
+     * @return the named object
+     */
+    protected Object getBean(final XmlBeanFactory reader, final String name) {
+        return AccessController.doPrivileged(
+            new PrivilegedAction() {
+                public Object run() {
+                    return reader.getBean(name);
+                }
+            }
+        );
+    }
+
+    /** Get the root object from the bean factory.
+     * 
+     * @param reader the xml bean reader
+     * @return the List of objects
+     */
+    protected List getRootList(XmlBeanFactory reader) {
+        return (List) getBean(reader, rootName);
+    }
+
+    /** Get the named object from the Map of objects.
+     * 
+     * @param name the bean name
+     * @return the named object
+     */
+    protected Object getOidByName(String name) {
+        return oidMap.get((Object)name);
+    }
+
+}

Propchange: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/AbstractReaderTest.java
------------------------------------------------------------------------------
    svn:eol-style = LF

Modified: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/AbstractRelationshipTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/AbstractRelationshipTest.java?rev=677080&r1=677079&r2=677080&view=diff
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/AbstractRelationshipTest.java (original)
+++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/AbstractRelationshipTest.java Tue
Jul 15 15:44:36 2008
@@ -18,30 +18,20 @@
 package org.apache.jdo.tck.mapping;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 
-import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.AbstractReaderTest;
 import org.apache.jdo.tck.pc.company.CompanyFactoryRegistry;
 import org.apache.jdo.tck.pc.company.CompanyModelReader;
 
 /*
  * Abstract class for managed relationship tests
  */
-public class AbstractRelationshipTest extends JDO_Test {
-    
-    /** */
-    protected List rootOids;
-    
-    /** */
-    protected final String inputFilename = System.getProperty("jdo.tck.testdata");
+public class AbstractRelationshipTest extends AbstractReaderTest {
     
     protected CompanyModelReader reader = null;
     
-    protected Map oidMap = new HashMap();
-    
     /** */
     protected final boolean isTestToBePerformed = isTestToBePerformed();
     
@@ -49,14 +39,14 @@
      * @see JDO_Test#localSetUp()
      */
     protected void localSetUp() {
-        if (isTestToBePerformed) {
+        if (isTestToBePerformed()) {
             getPM();
             CompanyFactoryRegistry.registerFactory(pm);
             reader = new CompanyModelReader(inputFilename);
             addTearDownClass(reader.getTearDownClassesFromFactory());
             // persist test data
             pm.currentTransaction().begin();
-            List rootList = reader.getRootList();
+            List rootList = getRootList(reader);
             pm.makePersistentAll(rootList);
             rootOids = new ArrayList();
             for (Iterator i = rootList.iterator(); i.hasNext(); ) {
@@ -81,9 +71,5 @@
             cleanupPM();
         }
     }
-    
-    protected Object getOidByName(String name) {
-        return oidMap.get((Object)name);
-    }
-    
+
 }

Modified: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/CompletenessTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/CompletenessTest.java?rev=677080&r1=677079&r2=677080&view=diff
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/CompletenessTest.java (original)
+++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/mapping/CompletenessTest.java Tue Jul 15
15:44:36 2008
@@ -21,7 +21,7 @@
 import java.util.Iterator;
 import java.util.List;
 
-import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.AbstractReaderTest;
 import org.apache.jdo.tck.pc.company.CompanyFactoryRegistry;
 import org.apache.jdo.tck.pc.company.CompanyModelReader;
 import org.apache.jdo.tck.util.BatchTestRunner;
@@ -40,21 +40,12 @@
  *<B>Assertion Description: </B>
  */
 
-public class CompletenessTest extends JDO_Test {
+public class CompletenessTest extends AbstractReaderTest {
 
     /** */
     private static final String ASSERTION_FAILED = 
         "Assertion A18-[not identified] failed: ";
     
-    /** */
-    private final boolean isTestToBePerformed = isTestToBePerformed();
-
-    /** */
-    protected List rootOids;
-    
-    /** */
-    protected final String inputFilename = System.getProperty("jdo.tck.testdata");
-    
     /**
      * The <code>main</code> is called when the class
      * is directly executed from the command line.
@@ -68,14 +59,14 @@
      * @see JDO_Test#localSetUp()
      */
     protected void localSetUp() {
-        if (isTestToBePerformed) {
+        if (isTestToBePerformed()) {
             getPM();
             CompanyFactoryRegistry.registerFactory(pm);
             CompanyModelReader reader = new CompanyModelReader(inputFilename);
             addTearDownClass(reader.getTearDownClassesFromFactory());
             // persist test data
             pm.currentTransaction().begin();
-            List rootList = reader.getRootList();
+            List rootList = getRootList(reader);
             pm.makePersistentAll(rootList);
             rootOids = new ArrayList();
             for (Iterator i = rootList.iterator(); i.hasNext(); ) {
@@ -89,12 +80,12 @@
 
     /** */
     public void test() {
-        if (isTestToBePerformed) {
+        if (isTestToBePerformed()) {
             // register the default factory
             CompanyFactoryRegistry.registerFactory();
             // get new obj graph to compare persistent graph with
             CompanyModelReader reader = new CompanyModelReader(inputFilename);
-            List rootList = reader.getRootList();
+            List rootList = getRootList(reader);
             
             getPM();
             pm.currentTransaction().begin();

Modified: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/QueryTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/QueryTest.java?rev=677080&r1=677079&r2=677080&view=diff
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/QueryTest.java (original)
+++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/query/QueryTest.java Tue Jul 15 15:44:36
2008
@@ -34,9 +34,7 @@
 import javax.jdo.Query;
 import javax.jdo.Transaction;
 
-import junit.framework.AssertionFailedError;
-
-import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.AbstractReaderTest;
 import org.apache.jdo.tck.pc.company.CompanyModelReader;
 import org.apache.jdo.tck.pc.mylib.MylibReader;
 import org.apache.jdo.tck.pc.mylib.PCPoint;
@@ -44,7 +42,7 @@
 import org.apache.jdo.tck.util.ConversionHelper;
 import org.apache.jdo.tck.util.EqualityHelper;
 
-public abstract class QueryTest extends JDO_Test {
+public abstract class QueryTest extends AbstractReaderTest {
 
     /** */
     public static final String SERIALZED_QUERY = "query.ser";
@@ -209,7 +207,7 @@
      */
     public CompanyModelReader loadAndPersistCompanyModel(PersistenceManager pm) {
         makePersistentAll(
-            pm, getCompanyModelReaderForPersistentInstances().getRootList());
+            pm, getRootList(getCompanyModelReaderForPersistentInstances()));
         return getCompanyModelReaderForPersistentInstances();
     }
     
@@ -221,7 +219,7 @@
      */
     public MylibReader loadAndPersistMylib(PersistenceManager pm) {
         makePersistentAll(
-            pm, getMylibReaderForPersistentInstances().getRootList());
+            pm, getRootList(getMylibReaderForPersistentInstances()));
         return getMylibReaderForPersistentInstances();
     }
 
@@ -251,7 +249,7 @@
      */
     protected Object getPersistentCompanyModelInstance(String beanName) {
         return beanName == null ? null :
-            getCompanyModelReaderForPersistentInstances().getBean(beanName);
+            getBean(getCompanyModelReaderForPersistentInstances(),beanName);
     }
     
     /**
@@ -261,7 +259,7 @@
      */
     protected Object getTransientCompanyModelInstance(String beanName) {
         return beanName == null ? null :
-            getCompanyModelReaderForTransientInstances().getBean(beanName);
+            getBean(getCompanyModelReaderForTransientInstances(),beanName);
     }
     
     /**
@@ -323,7 +321,7 @@
      */
     protected Object getPersistentMylibInstance(String beanName) {
         return beanName == null ? 
-                null : getMylibReaderForPersistentInstances().getBean(beanName);
+                null : getBean(getMylibReaderForPersistentInstances(),beanName);
     }
     
     /**
@@ -333,7 +331,7 @@
      */
     protected Object getTransientMylibInstance(String beanName) {
         return beanName == null ? 
-                null : getMylibReaderForTransientInstances().getBean(beanName);
+                null : getBean(getMylibReaderForTransientInstances(),beanName);
     }
     
     /**
@@ -968,7 +966,7 @@
     private void compile(String assertion, 
             QueryElementHolder queryElementHolder, boolean asSingleString,  
             String singleStringQuery, boolean positive) {
-        PersistenceManager pm = getPM();
+        getPM();
         try {
             Query query;
             if (queryElementHolder != null) {
@@ -1011,7 +1009,7 @@
      */
     protected void compile(String assertion, 
             Query query, String queryText, boolean positive) {
-        PersistenceManager pm = getPM();
+        getPM();
         Transaction tx = pm.currentTransaction();
         tx.begin();
         try {
@@ -1128,7 +1126,7 @@
     private Object execute(String assertion, 
             QueryElementHolder queryElementHolder, boolean asSingleString,
             Object parameters, Object expectedResult) {
-        PersistenceManager pm = getPM();
+        getPM();
         Query query = asSingleString ?
                 queryElementHolder.getSingleStringQuery(pm) :
                     queryElementHolder.getAPIQuery(pm);
@@ -1248,7 +1246,7 @@
             String singleStringQuery, boolean hasOrdering,
             Object parameters, Object expectedResult, boolean positive) {
         Object result = null;
-        PersistenceManager pm = getPM();
+        getPM();
         Transaction tx = pm.currentTransaction();
         tx.begin();
         try {
@@ -1392,7 +1390,7 @@
     private void delete(String assertion, 
             QueryElementHolder queryElementHolder, boolean asSingleString,
             Object parameters, long expectedNrOfDeletedObjects) {
-        PersistenceManager pm = getPM();
+        getPM();
         Query query = asSingleString ?
                 queryElementHolder.getSingleStringQuery(pm) :
                     queryElementHolder.getAPIQuery(pm);
@@ -1425,7 +1423,7 @@
             String singleStringQuery, Object parameters, 
             long expectedNrOfDeletedObjects) {
         boolean positive = expectedNrOfDeletedObjects >= 0;
-        PersistenceManager pm = getPM();
+        getPM();
         Transaction tx = pm.currentTransaction();
         tx.begin();
         try {



Mime
View raw message