db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bra...@apache.org
Subject svn commit: r351768 [2/4] - in /incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query: ./ api/ delete/ jdoql/ jdoql/keywords/ jdoql/methods/ jdoql/operators/ jdoql/parameters/ jdoql/variables/ result/ sql/
Date Fri, 02 Dec 2005 16:20:55 GMT
Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/delete/DeleteCallback.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/delete/DeleteCallback.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/delete/DeleteCallback.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/delete/DeleteCallback.java Fri Dec  2 08:19:42 2005
@@ -109,9 +109,9 @@
      * The expected results of valid queries.
      */
     private List[] expectedResult = {
-            getCompanyModelInstancesAsList(new String[]{
+            getTransientCompanyModelInstancesAsList(new String[]{
                     "emp1", "emp2", "emp3", "emp4", "emp5"}),
-            getMylibInstancesAsList(new String[]{
+            getTransientMylibInstancesAsList(new String[]{
                     "primitiveTypesPositive", 
                     "primitiveTypesNegative",
                     "primitiveTypesCharacterStringLiterals"})
@@ -150,9 +150,9 @@
      * @see JDO_Test#localSetUp()
      */
     protected void localSetUp() {
-        loadCompanyModel(getPM(), COMPANY_TESTDATA);
+        loadAndPersistCompanyModel(getPM());
         addTearDownClass(CompanyModelReader.getTearDownClasses());
-        loadMylib(getPM(), MYLIB_TESTDATA);
+        loadAndPersistMylib(getPM());
         addTearDownClass(MylibReader.getTearDownClasses());
     }
     

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/delete/DeletePersistentAll.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/delete/DeletePersistentAll.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/delete/DeletePersistentAll.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/delete/DeletePersistentAll.java Fri Dec  2 08:19:42 2005
@@ -139,7 +139,7 @@
      * @see JDO_Test#localSetUp()
      */
     protected void localSetUp() {
-        loadCompanyModel(getPM(), COMPANY_TESTDATA);
+        loadAndPersistCompanyModel(getPM());
         addTearDownClass(CompanyModelReader.getTearDownClasses());
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/delete/DeleteQueryElements.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/delete/DeleteQueryElements.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/delete/DeleteQueryElements.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/delete/DeleteQueryElements.java Fri Dec  2 08:19:42 2005
@@ -203,7 +203,7 @@
     };
     
     /** Parameters of valid queries. */
-    private static Object[][] parameters = {
+    private Object[][] parameters = {
         {new BigDecimal("2500000")}
     };
             
@@ -244,7 +244,7 @@
      * @see JDO_Test#localSetUp()
      */
     protected void localSetUp() {
-        loadCompanyModel(getPM(), COMPANY_TESTDATA);
+        loadAndPersistCompanyModel(getPM());
         addTearDownClass(CompanyModelReader.getTearDownClasses());
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/AssignmentPrePostIncrementDecrementNotSupported.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/AssignmentPrePostIncrementDecrementNotSupported.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/AssignmentPrePostIncrementDecrementNotSupported.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/AssignmentPrePostIncrementDecrementNotSupported.java Fri Dec  2 08:19:42 2005
@@ -19,7 +19,6 @@
 
 import javax.jdo.JDOUserException;
 import javax.jdo.PersistenceManager;
-import javax.jdo.PersistenceManagerFactory;
 import javax.jdo.Query;
 
 import org.apache.jdo.tck.pc.mylib.PCPoint;
@@ -56,10 +55,8 @@
     }
 
     /** */
-    public void test() {
-        PersistenceManagerFactory pmf = getPMF();
-        pm = pmf.getPersistenceManager();
-        initDatabase(pm, PCPoint.class);
+    public void testNegative() {
+        PersistenceManager pm = getPM();
         
         runTestUnsupportedOperators01(pm, "x = 1");
         runTestUnsupportedOperators01(pm, "x += 1");

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/Cast.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/Cast.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/Cast.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/Cast.java Fri Dec  2 08:19:42 2005
@@ -16,16 +16,11 @@
 
 package org.apache.jdo.tck.query.jdoql;
 
-import java.util.Collection;
-import java.util.HashSet;
-
-import javax.jdo.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-
+import org.apache.jdo.tck.JDO_Test;
 import org.apache.jdo.tck.pc.company.CompanyModelReader;
 import org.apache.jdo.tck.pc.company.Department;
 import org.apache.jdo.tck.pc.company.Employee;
+import org.apache.jdo.tck.query.QueryElementHolder;
 import org.apache.jdo.tck.query.QueryTest;
 import org.apache.jdo.tck.util.BatchTestRunner;
 
@@ -47,6 +42,49 @@
     private static final String ASSERTION_FAILED = 
         "Assertion A14.6.2-38 (Cast) failed: ";
     
+    /** 
+     * The array of valid queries which may be executed as 
+     * single string queries and as API queries.
+     */
+    private static final QueryElementHolder[] VALID_QUERIES = {
+        new QueryElementHolder(
+        /*UNIQUE*/      null,
+        /*RESULT*/      null,
+        /*INTO*/        null, 
+        /*FROM*/        Employee.class,
+        /*EXCLUDE*/     null,
+        /*WHERE*/       "((FullTimeEmployee)this).salary > 15000.0",
+        /*VARIABLES*/   null,
+        /*PARAMETERS*/  null,
+        /*IMPORTS*/     "import org.apache.jdo.tck.pc.company.FullTimeEmployee",
+        /*GROUP BY*/    null,
+        /*ORDER BY*/    null,
+        /*FROM*/        null,
+        /*TO*/          null),
+        new QueryElementHolder(
+        /*UNIQUE*/      null,
+        /*RESULT*/      null,
+        /*INTO*/        null, 
+        /*FROM*/        Department.class,
+        /*EXCLUDE*/     null,
+        /*WHERE*/       "employees.contains(e) && ((FullTimeEmployee)e).salary > 15000.0",
+        /*VARIABLES*/   "Employee e",
+        /*PARAMETERS*/  null,
+        /*IMPORTS*/     "import org.apache.jdo.tck.pc.company.FullTimeEmployee",
+        /*GROUP BY*/    null,
+        /*ORDER BY*/    null,
+        /*FROM*/        null,
+        /*TO*/          null)
+    };
+        
+    /** 
+     * The expected results of valid queries.
+     */
+    private Object[] expectedResult = {
+        getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp5"}),
+        getTransientCompanyModelInstancesAsList(new String[]{"dept1", "dept2"})
+    };
+    
     /**
      * The <code>main</code> is called when the class
      * is directly executed from the command line.
@@ -57,49 +95,20 @@
     }
     
     /** */
-    public void test() {
-        pm = getPM();
-        
-        try {
-            // read test data
-            CompanyModelReader reader = loadCompanyModel(pm, COMPANY_TESTDATA);
-            runTest(pm, reader);
-        }
-        finally {
-            cleanupCompanyModel(pm);
-            pm.close();
-            pm = null;
+    public void testPositive() {
+        for (int i = 0; i < VALID_QUERIES.length; i++) {
+            executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], 
+                    expectedResult[i]);
+            executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], 
+                    expectedResult[i]);
         }
     }
     
-    /** */
-    void runTest(PersistenceManager pm, CompanyModelReader reader) {
-        Query q;
-        Object result;
-        Collection expected;
-        
-        Transaction tx = pm.currentTransaction();
-        tx.begin();
-                
-        q = pm.newQuery(Employee.class);
-        q.declareImports("import org.apache.jdo.tck.pc.company.FullTimeEmployee");
-        q.setFilter("((FullTimeEmployee)this).salary > 15000.0");
-        result = q.execute();
-        expected = new HashSet();
-        expected.add(reader.getFullTimeEmployee("emp1"));
-        expected.add(reader.getFullTimeEmployee("emp5"));
-        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
-        
-        q = pm.newQuery(Department.class);
-        q.declareVariables("Employee e");
-        q.declareImports("import org.apache.jdo.tck.pc.company.FullTimeEmployee");
-        q.setFilter("employees.contains(e) && ((FullTimeEmployee)e).salary > 15000.0");
-        result = q.execute();
-        expected = new HashSet();
-        expected.add(reader.getDepartment("dept1"));
-        expected.add(reader.getDepartment("dept2"));
-        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
-        
-        tx.commit();
+    /**
+     * @see JDO_Test#localSetUp()
+     */
+    protected void localSetUp() {
+        loadAndPersistCompanyModel(getPM());
+        addTearDownClass(CompanyModelReader.getTearDownClasses());
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/CharacterAndStringLiterals.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/CharacterAndStringLiterals.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/CharacterAndStringLiterals.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/CharacterAndStringLiterals.java Fri Dec  2 08:19:42 2005
@@ -118,7 +118,7 @@
      * The expected results of valid queries.
      */
     private Object[] expectedResult = {
-        getMylibInstancesAsList(new String[]{
+        getTransientMylibInstancesAsList(new String[]{
             "primitiveTypesCharacterStringLiterals"})
     };
     
@@ -156,7 +156,7 @@
      * @see JDO_Test#localSetUp()
      */
     protected void localSetUp() {
-        loadMylib(getPM(), MYLIB_TESTDATA);
+        loadAndPersistMylib(getPM());
         addTearDownClass(MylibReader.getTearDownClasses());
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/ComparingCollectionFieldToNull.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/ComparingCollectionFieldToNull.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/ComparingCollectionFieldToNull.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/ComparingCollectionFieldToNull.java Fri Dec  2 08:19:42 2005
@@ -16,15 +16,10 @@
 
 package org.apache.jdo.tck.query.jdoql;
 
-import java.util.Collection;
-import java.util.HashSet;
-
-import javax.jdo.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-
+import org.apache.jdo.tck.JDO_Test;
 import org.apache.jdo.tck.pc.company.CompanyModelReader;
 import org.apache.jdo.tck.pc.company.Employee;
+import org.apache.jdo.tck.query.QueryElementHolder;
 import org.apache.jdo.tck.query.QueryTest;
 import org.apache.jdo.tck.util.BatchTestRunner;
 
@@ -49,6 +44,37 @@
     private static final String ASSERTION_FAILED = 
         "Assertion A14.6.2-36 (ComparingCollectionFieldToNull) failed: ";
     
+    /** 
+     * The array of valid queries which may be executed as 
+     * single string queries and as API queries.
+     */
+    private static final QueryElementHolder[] VALID_QUERIES = {
+        new QueryElementHolder(
+        /*UNIQUE*/      null,
+        /*RESULT*/      null,
+        /*INTO*/        null, 
+        /*FROM*/        Employee.class,
+        /*EXCLUDE*/     null,
+        /*WHERE*/       "personid == 1 && projects == null",
+        /*VARIABLES*/   null,
+        /*PARAMETERS*/  null,
+        /*IMPORTS*/     null,
+        /*GROUP BY*/    null,
+        /*ORDER BY*/    null,
+        /*FROM*/        null,
+        /*TO*/          null)
+    };
+    
+    /** 
+     * The expected results of valid queries.
+     */
+    private Object[] expectedResult = {
+        // emp1 should be in the query result set,
+        // if the JDO Implentation supports null values for Collections
+        getTransientCompanyModelInstancesAsList(
+            isNullCollectionSupported() ? new String[]{"emp1"} : new String[]{})
+    };
+    
     /**
      * The <code>main</code> is called when the class
      * is directly executed from the command line.
@@ -59,44 +85,26 @@
     }
     
     /** */
-    public void test() {
-        pm = getPM();
-        
-        try {
-            // read test data
-            CompanyModelReader reader = loadCompanyModel(pm, COMPANY_TESTDATA);
-            runTest(pm, reader);
-        }
-        finally {
-            cleanupCompanyModel(pm);
-            pm.close();
-            pm = null;
+    public void testPositive() {
+        for (int i = 0; i < VALID_QUERIES.length; i++) {
+            executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], 
+                    expectedResult[i]);
+            executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], 
+                    expectedResult[i]);
         }
     }
     
-    /** */
-    void runTest(PersistenceManager pm, CompanyModelReader reader) {
-        Query q;
-        Object result;
-        Collection expected;
-
-        Transaction tx = pm.currentTransaction();
-        tx.begin();
-        Employee emp1 = reader.getFullTimeEmployee("emp1");
-        emp1.setProjects(null);
-        tx.commit();
-        
-        tx.begin();
-        q = pm.newQuery(Employee.class);
-        q.setFilter("personid == 1 && projects == null");
-        result = q.execute();
-        expected = new HashSet();
-        // emp1 should be in the query result set,
-        // if the JDO Implentation supports null values for Collections
-        if (isNullCollectionSupported())
-            expected.add(emp1);
-        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
-        
-        tx.commit();
+    /**
+     * @see JDO_Test#localSetUp()
+     */
+    protected void localSetUp() {
+        loadAndPersistCompanyModel(getPM());
+        Employee employee = (Employee) getPersistentCompanyModelInstance("emp1");
+        if (isNullCollectionSupported()) {
+            getPM().currentTransaction().begin();
+            employee.setProjects(null);
+            getPM().currentTransaction().commit();
+        }
+        addTearDownClass(CompanyModelReader.getTearDownClasses());
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/ComparingPersistentAndNonPersistentInstance.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/ComparingPersistentAndNonPersistentInstance.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/ComparingPersistentAndNonPersistentInstance.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/ComparingPersistentAndNonPersistentInstance.java Fri Dec  2 08:19:42 2005
@@ -16,15 +16,10 @@
 
 package org.apache.jdo.tck.query.jdoql;
 
-import java.util.Collection;
-import java.util.HashSet;
-
-import javax.jdo.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-
+import org.apache.jdo.tck.JDO_Test;
 import org.apache.jdo.tck.pc.company.CompanyModelReader;
 import org.apache.jdo.tck.pc.company.Employee;
+import org.apache.jdo.tck.query.QueryElementHolder;
 import org.apache.jdo.tck.query.QueryTest;
 import org.apache.jdo.tck.util.BatchTestRunner;
 
@@ -47,6 +42,55 @@
     private static final String ASSERTION_FAILED = 
         "Assertion A14.6.2-36 (ComparingPersistentAndNonPersistentInstance) failed: ";
     
+    /** 
+     * The array of valid queries which may be executed as 
+     * single string queries and as API queries.
+     */
+    private static final QueryElementHolder[] VALID_QUERIES = {
+        new QueryElementHolder(
+        /*UNIQUE*/      null,
+        /*RESULT*/      null,
+        /*INTO*/        null, 
+        /*FROM*/        Employee.class,
+        /*EXCLUDE*/     null,
+        /*WHERE*/       "this == param",
+        /*VARIABLES*/   null,
+        /*PARAMETERS*/  "Employee param",
+        /*IMPORTS*/     null,
+        /*GROUP BY*/    null,
+        /*ORDER BY*/    null,
+        /*FROM*/        null,
+        /*TO*/          null),
+        new QueryElementHolder(
+        /*UNIQUE*/      null,
+        /*RESULT*/      null,
+        /*INTO*/        null, 
+        /*FROM*/        Employee.class,
+        /*EXCLUDE*/     null,
+        /*WHERE*/       "this.personid == param.personid",
+        /*VARIABLES*/   null,
+        /*PARAMETERS*/  "Employee param",
+        /*IMPORTS*/     null,
+        /*GROUP BY*/    null,
+        /*ORDER BY*/    null,
+        /*FROM*/        null,
+        /*TO*/          null)
+    };
+    
+    /** 
+     * The expected results of valid queries.
+     */
+    private Object[] expectedResult = {
+            getTransientCompanyModelInstancesAsList(new String[]{}),
+            getTransientCompanyModelInstancesAsList(new String[]{"emp1"})
+    };
+    
+    /** Parameters of valid queries. */
+    private Object[][] parameters = {
+        {getTransientCompanyModelInstance("emp1")},
+        {getTransientCompanyModelInstance("emp1")}
+    };
+            
     /**
      * The <code>main</code> is called when the class
      * is directly executed from the command line.
@@ -57,61 +101,20 @@
     }
     
     /** */
-    public void test() {
-        pm = getPM();
-        
-        try {
-            // read test data
-            CompanyModelReader reader = loadCompanyModel(pm, COMPANY_TESTDATA);
-            runTest(pm, reader);
-        }
-        finally {
-            cleanupCompanyModel(pm);
-            pm.close();
-            pm = null;
+    public void testPositive() {
+        for (int i = 0; i < VALID_QUERIES.length; i++) {
+            executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], 
+                    parameters[i], expectedResult[i]);
+            executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], 
+                    parameters[i], expectedResult[i]);
         }
     }
     
-    /** */
-    void runTest(PersistenceManager pm, CompanyModelReader reader) {
-        Query q;
-        Object result;
-        Collection expected;
-
-        Transaction tx = pm.currentTransaction();
-        tx.begin();
-        Employee transientEmp1 = reader.getFullTimeEmployee("emp1");
-        // access the Employee values to make sure they are loaded
-        transientEmp1.toString();
-        pm.makeTransient(transientEmp1);
-        tx.commit();
-        
-        tx.begin();
-
-        // query comparing persistent instance (this) with
-        // non-persistent instance (param) => 
-        // result should be empty
-        q = pm.newQuery(Employee.class, "this == param");
-        q.declareParameters("Employee param");
-        result = q.execute(transientEmp1);
-        expected = new HashSet();
-        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
-
-        // Get the persistent employee with personid 1 
-        Collection tmp = 
-            (Collection)pm.newQuery(Employee.class, "personid == 1").execute();
-        Employee persistentEmp1 = (Employee)tmp.iterator().next();
-
-        // query comparing the personid field of a persistent instance
-        // (this) with the ipersonid of the non-persistent instance (param) => 
-        // result should include persistent employee with personid 1
-        q = pm.newQuery(Employee.class, "this.personid == param.personid");
-        q.declareParameters("Employee param");
-        result = q.execute(transientEmp1);
-        expected = new HashSet();
-        expected.add(persistentEmp1);
-        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
-        
-        tx.commit();
+    /**
+     * @see JDO_Test#localSetUp()
+     */
+    protected void localSetUp() {
+        loadAndPersistCompanyModel(getPM());
+        addTearDownClass(CompanyModelReader.getTearDownClasses());
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/DenoteUniquenessInFilter.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/DenoteUniquenessInFilter.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/DenoteUniquenessInFilter.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/DenoteUniquenessInFilter.java Fri Dec  2 08:19:42 2005
@@ -16,15 +16,10 @@
 
 package org.apache.jdo.tck.query.jdoql;
 
-import java.util.Collection;
-import java.util.HashSet;
-
-import javax.jdo.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-
+import org.apache.jdo.tck.JDO_Test;
 import org.apache.jdo.tck.pc.company.CompanyModelReader;
 import org.apache.jdo.tck.pc.company.Department;
+import org.apache.jdo.tck.query.QueryElementHolder;
 import org.apache.jdo.tck.query.QueryTest;
 import org.apache.jdo.tck.util.BatchTestRunner;
 
@@ -54,6 +49,89 @@
     private static final String ASSERTION_FAILED = 
         "Assertion A14.6.2-2 (DenoteUniquenessInFilter) failed: ";
     
+    /** 
+     * The array of valid queries which may be executed as 
+     * single string queries and as API queries.
+     */
+    private static final QueryElementHolder[] VALID_QUERIES = {
+        // Uniqueness not specified.
+        // emp1 qualifies for both contains clause => result is dept1
+        new QueryElementHolder(
+        /*UNIQUE*/      null,
+        /*RESULT*/      null,
+        /*INTO*/        null, 
+        /*FROM*/        Department.class,
+        /*EXCLUDE*/     null,
+        /*WHERE*/       "employees.contains(e1) && (e1.personid == 1 && " +
+                        "(employees.contains(e2) && (e2.weeklyhours == 40)))",
+        /*VARIABLES*/   "Employee e1; Employee e2",
+        /*PARAMETERS*/  null,
+        /*IMPORTS*/     null,
+        /*GROUP BY*/    null,
+        /*ORDER BY*/    null,
+        /*FROM*/        null,
+        /*TO*/          null),
+        // Uniqueness specified.
+        // Only emp3 qualifies for both contains clause.
+        // Condition e1 != e2 violated => result is empty
+        new QueryElementHolder(
+        /*UNIQUE*/      null,
+        /*RESULT*/      null,
+        /*INTO*/        null, 
+        /*FROM*/        Department.class,
+        /*EXCLUDE*/     null,
+        /*WHERE*/       "employees.contains(e1) && (e1.personid == 3 && " +
+                        "(employees.contains(e2) && (e2.weeklyhours == 19 && " +
+                        "e1 != e2)))",
+        /*VARIABLES*/   "Employee e1; Employee e2",
+        /*PARAMETERS*/  null,
+        /*IMPORTS*/     null,
+        /*GROUP BY*/    null,
+        /*ORDER BY*/    null,
+        /*FROM*/        null,
+        /*TO*/          null),
+        // Uniqueness specified.
+        // Only emp1 matches the first contains clause.
+        // emp1 and emp2 match the second contains clause.
+        // Thus, there are two different values for e1 and e2
+        // satifying the entire filter => result is dept1
+        new QueryElementHolder(
+        /*UNIQUE*/      null,
+        /*RESULT*/      null,
+        /*INTO*/        null, 
+        /*FROM*/        Department.class,
+        /*EXCLUDE*/     null,
+        /*WHERE*/       "employees.contains(e1) && (e1.personid == 1 && " +
+                        "(employees.contains(e2) && (e2.weeklyhours == 40 && " +
+                        "e1 != e2)))",
+        /*VARIABLES*/   "Employee e1; Employee e2",
+        /*PARAMETERS*/  null,
+        /*IMPORTS*/     null,
+        /*GROUP BY*/    null,
+        /*ORDER BY*/    null,
+        /*FROM*/        null,
+        /*TO*/          null)
+    };
+        
+    /** 
+     * The expected results of valid queries.
+     */
+    private Object[] expectedResult = {
+        // Uniqueness not specified.
+        // emp1 qualifies for both contains clause => result is dept1
+        getTransientCompanyModelInstancesAsList(new String[]{"dept1"}),
+        // Uniqueness specified.
+        // Only emp3 qualifies for both contains clause.
+        // Condition e1 != e2 violated => result is empty
+        getTransientCompanyModelInstancesAsList(new String[]{}),
+        // Uniqueness specified.
+        // Only emp1 matches the first contains clause.
+        // emp1 and emp2 match the second contains clause.
+        // Thus, there are two different values for e1 and e2
+        // satifying the entire filter => result is dept1
+        getTransientCompanyModelInstancesAsList(new String[]{"dept1"})
+    };
+    
     /**
      * The <code>main</code> is called when the class
      * is directly executed from the command line.
@@ -64,70 +142,20 @@
     }
     
     /** */
-    public void test() {
-        pm = getPM();
-        
-        try {
-            // read test data
-            CompanyModelReader reader = 
-                loadCompanyModel(pm, COMPANY_TESTDATA);
-            runTest(pm, reader);
-        }
-        finally {
-            cleanupCompanyModel(pm);
-            pm.close();
-            pm = null;
+    public void testPositive() {
+        for (int i = 0; i < VALID_QUERIES.length; i++) {
+            executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], 
+                    expectedResult[i]);
+            executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], 
+                    expectedResult[i]);
         }
     }
     
-    /** */
-    void runTest(PersistenceManager pm, CompanyModelReader reader) {
-        Query q;
-        Object result;
-        Collection expected;
-        String filter;
-        
-        Transaction tx = pm.currentTransaction();
-        tx.begin();
-        
-        // Scenario: only employee with personid 1 has a medicalInsurance
-        
-        // Uniqueness not specified => employee 1 qualifies => return dept1
-        filter = 
-            "employees.contains(e1) && (e1.personid == 1 && " +
-            "(employees.contains(e2) && (e2.medicalInsurance != null)))";
-        q = pm.newQuery(Department.class, filter);
-        q.declareVariables("Employee e1; Employee e2");
-        result = q.execute();
-        expected = new HashSet();
-        expected.add(reader.getDepartment("dept1"));
-        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
-        
-        // Uniqueness specified => there is only a single employee qualifying =>
-        // e1 != e2 does not apply => result is empty
-        filter = 
-            "employees.contains(e1) && (e1.personid == 1 && " +
-            "(employees.contains(e2) && (e2.medicalInsurance != null &&" + 
-            "e1 != e2)))";
-        q = pm.newQuery(Department.class, filter);
-        q.declareVariables("Employee e1; Employee e2");
-        result = q.execute();
-        expected = new HashSet();
-        expected.add(reader.getDepartment("dept1"));
-        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
-        
-        // Changed second contains to look for null medicalInsurance => 
-        // employee 1 and 2 match the two conditions => return dept1
-        filter = 
-            "employees.contains(e1) && (e1.personid == 1 && " +
-            "(employees.contains(e2) && (e2.medicalInsurance == null &&" + 
-            "e1 != e2)))";
-        q = pm.newQuery(Department.class, filter);
-        q.declareVariables("Employee e1; Employee e2");
-        result = q.execute();
-        expected = new HashSet();
-        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
-        
-        tx.commit();
+    /**
+     * @see JDO_Test#localSetUp()
+     */
+    protected void localSetUp() {
+        loadAndPersistCompanyModel(getPM());
+        addTearDownClass(CompanyModelReader.getTearDownClasses());
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/ExecutingMultipleQueriesSimultaneouslyIsThreadSafe.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/ExecutingMultipleQueriesSimultaneouslyIsThreadSafe.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/ExecutingMultipleQueriesSimultaneouslyIsThreadSafe.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/ExecutingMultipleQueriesSimultaneouslyIsThreadSafe.java Fri Dec  2 08:19:42 2005
@@ -25,6 +25,7 @@
 import javax.jdo.Query;
 import javax.jdo.Transaction;
 
+import org.apache.jdo.tck.JDO_Test;
 import org.apache.jdo.tck.pc.mylib.PCPoint;
 import org.apache.jdo.tck.util.BatchTestRunner;
 import org.apache.jdo.tck.util.ThreadExceptionHandler;
@@ -62,19 +63,8 @@
     }
 
     /** */
-    public void test() {
-        pm = getPM();
-
-        if (debug) logger.debug("\ninitDatabase");
-        initDatabase(pm, PCPoint.class);
-        executeMultipleQueries(pm);
-        
-        pm.close();
-        pm = null;
-    }
-    
-    /** */
-    void executeMultipleQueries(PersistenceManager pm) {
+    public void testPositive() {
+        PersistenceManager pm = getPM();
         Transaction tx = pm.currentTransaction();
         try {
             tx.begin();
@@ -185,5 +175,13 @@
         public void run() {
             ExecutingMultipleQueriesSimultaneouslyIsThreadSafe.this.executeQueries(pm);
         }
+    }
+
+    /**
+     * @see JDO_Test#localSetUp()
+     */
+    protected void localSetUp() {
+        loadAndPersistPCPoints(getPM());
+        addTearDownClass(PCPoint.class);
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/ExecutingQueryWhenNoTransactionNoNontransactionalRead.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/ExecutingQueryWhenNoTransactionNoNontransactionalRead.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/ExecutingQueryWhenNoTransactionNoNontransactionalRead.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/ExecutingQueryWhenNoTransactionNoNontransactionalRead.java Fri Dec  2 08:19:42 2005
@@ -17,7 +17,10 @@
 
 package org.apache.jdo.tck.query.jdoql;
 
-import javax.jdo.*;
+import javax.jdo.Extent;
+import javax.jdo.JDOUserException;
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
 
 import org.apache.jdo.tck.pc.mylib.PCPoint;
 import org.apache.jdo.tck.query.QueryTest;
@@ -54,15 +57,11 @@
     }
 
     /** */
-    public void test() {
-        pm = getPM();
+    public void testNegative() {
+        PersistenceManager pm = getPM();
         
-        initDatabase(pm, PCPoint.class);
         pm.currentTransaction().setNontransactionalRead(false);
         runTestNewQuery(pm);
-
-        pm.close();
-        pm = null;
     }
 
     /** */

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/IdentifiersEqualFieldNames.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/IdentifiersEqualFieldNames.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/IdentifiersEqualFieldNames.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/IdentifiersEqualFieldNames.java Fri Dec  2 08:19:42 2005
@@ -80,8 +80,8 @@
      * The expected results of valid queries.
      */
     private Object[] expectedResult = {
-        getCompanyModelInstancesAsList(new String[]{"emp1"}),
-        getCompanyModelInstancesAsList(new String[]{
+        getTransientCompanyModelInstancesAsList(new String[]{"emp1"}),
+        getTransientCompanyModelInstancesAsList(new String[]{
                 "emp1", "emp2", "emp3", "emp4", "emp5"})
     };
             
@@ -108,7 +108,7 @@
      * @see JDO_Test#localSetUp()
      */
     protected void localSetUp() {
-        loadCompanyModel(getPM(), COMPANY_TESTDATA);
+        loadAndPersistCompanyModel(getPM());
         addTearDownClass(CompanyModelReader.getTearDownClasses());
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/IgnoreCacheFalse.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/IgnoreCacheFalse.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/IgnoreCacheFalse.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/IgnoreCacheFalse.java Fri Dec  2 08:19:42 2005
@@ -67,6 +67,7 @@
      */
     protected void localSetUp() {
         super.localSetUp();
+        loadAndPersistPrimitiveTypes(getPM());
         addTearDownClass(PrimitiveTypes.class);
     }
     
@@ -75,7 +76,6 @@
         pm = getPM();
         
         try {
-            loadPrimitiveTypes(pm);
             // set ignoreCache flag
             pm.setIgnoreCache(false);
             runTestNewInstance(pm);

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/MultipleActiveQueryInstanceInSamePersistenceManager.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/MultipleActiveQueryInstanceInSamePersistenceManager.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/MultipleActiveQueryInstanceInSamePersistenceManager.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/MultipleActiveQueryInstanceInSamePersistenceManager.java Fri Dec  2 08:19:42 2005
@@ -22,8 +22,8 @@
 
 import javax.jdo.PersistenceManager;
 import javax.jdo.Query;
-import javax.jdo.Transaction;
 
+import org.apache.jdo.tck.JDO_Test;
 import org.apache.jdo.tck.pc.mylib.PCPoint;
 import org.apache.jdo.tck.query.QueryTest;
 import org.apache.jdo.tck.util.BatchTestRunner;
@@ -56,20 +56,8 @@
         BatchTestRunner.run(MultipleActiveQueryInstanceInSamePersistenceManager.class);
     }
 
-    /** */
-    public void test() {
-        pm = getPM();
-
-        initDatabase(pm, PCPoint.class);
-        runTestMultipleActiveQueryInstanceInSamePersistenceManager(pm);
-
-        pm.close();
-        pm = null;
-    }
-
-    /** */
-    void runTestMultipleActiveQueryInstanceInSamePersistenceManager(
-        PersistenceManager pm) {
+    public void testPositive() {
+        PersistenceManager pm = getPM();
         if (debug) 
             logger.debug("\nExecuting test MultipleActiveQueryInstanceInSamePersistenceManager()...");
 
@@ -115,6 +103,14 @@
         expected2 = getFromInserted(expected2);
         checkQueryResultWithoutOrder(ASSERTION_FAILED, results2, expected2);
         pm.currentTransaction().commit();
+    }
+
+    /**
+     * @see JDO_Test#localSetUp()
+     */
+    protected void localSetUp() {
+        loadAndPersistPCPoints(getPM());
+        addTearDownClass(PCPoint.class);
     }
 }
 

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/MultipleIdenticalImports.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/MultipleIdenticalImports.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/MultipleIdenticalImports.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/MultipleIdenticalImports.java Fri Dec  2 08:19:42 2005
@@ -23,9 +23,11 @@
 import javax.jdo.Query;
 import javax.jdo.Transaction;
 
+import org.apache.jdo.tck.JDO_Test;
 import org.apache.jdo.tck.pc.company.CompanyModelReader;
 import org.apache.jdo.tck.pc.company.Department;
 import org.apache.jdo.tck.pc.company.Employee;
+import org.apache.jdo.tck.query.QueryElementHolder;
 import org.apache.jdo.tck.query.QueryTest;
 import org.apache.jdo.tck.util.BatchTestRunner;
 
@@ -55,22 +57,83 @@
         BatchTestRunner.run(MultipleIdenticalImports.class);
     }
 
-    /** */
-    public void test() {
-        pm = getPM();
-        
-        try {
-            // read test data
-            CompanyModelReader reader = loadCompanyModel(pm, COMPANY_TESTDATA);
-            runTest(pm, reader);
-        }
-        finally {
-            cleanupCompanyModel(pm);
-            pm.close();
-            pm = null;
-        }
-    }
-
+    /** 
+     * The array of valid queries which may be executed as 
+     * single string queries and as API queries.
+     */
+    private static final QueryElementHolder[] VALID_QUERIES = {
+        // Import Department twice
+        new QueryElementHolder(
+        /*UNIQUE*/      null,
+        /*RESULT*/      null,
+        /*INTO*/        null, 
+        /*FROM*/        Employee.class,
+        /*EXCLUDE*/     null,
+        /*WHERE*/       "department == d",
+        /*VARIABLES*/   null,
+        /*PARAMETERS*/  "Department d",
+        /*IMPORTS*/     "import org.apache.jdo.tck.pc.company.Department; " +
+                        "import org.apache.jdo.tck.pc.company.Department;",
+        /*GROUP BY*/    null,
+        /*ORDER BY*/    null,
+        /*FROM*/        null,
+        /*TO*/          null),
+        // Import Department explictly and per type-import-on-demand
+        new QueryElementHolder(
+        /*UNIQUE*/      null,
+        /*RESULT*/      null,
+        /*INTO*/        null, 
+        /*FROM*/        Employee.class,
+        /*EXCLUDE*/     null,
+        /*WHERE*/       "department == d",
+        /*VARIABLES*/   null,
+        /*PARAMETERS*/  "Department d",
+        /*IMPORTS*/     "import org.apache.jdo.tck.pc.company.Department; " +
+                        "import org.apache.jdo.tck.pc.company.*",
+        /*GROUP BY*/    null,
+        /*ORDER BY*/    null,
+        /*FROM*/        null,
+        /*TO*/          null),
+        // type-import-on-demand twice
+        new QueryElementHolder(
+        /*UNIQUE*/      null,
+        /*RESULT*/      null,
+        /*INTO*/        null, 
+        /*FROM*/        Employee.class,
+        /*EXCLUDE*/     null,
+        /*WHERE*/       "department == d",
+        /*VARIABLES*/   null,
+        /*PARAMETERS*/  "Department d",
+        /*IMPORTS*/     "import org.apache.jdo.tck.pc.company.*; " +
+                        "import org.apache.jdo.tck.pc.company.*",
+        /*GROUP BY*/    null,
+        /*ORDER BY*/    null,
+        /*FROM*/        null,
+        /*TO*/          null)
+    };
+    
+    /** 
+     * The expected results of valid queries.
+     */
+    private Object[] expectedResult = {
+        // Import Department twice
+        getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp2", "emp3"}),
+        // Import Department explictly and per type-import-on-demand
+        getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp2", "emp3"}),
+        // type-import-on-demand twice
+        getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp2", "emp3"})
+    };
+    
+    /** Parameters of valid queries. */
+    private Object[][] parameters = {
+        // Import Department twice
+        {getPersistentCompanyModelInstance("dept1")},
+        // Import Department explictly and per type-import-on-demand
+        {getPersistentCompanyModelInstance("dept1")},
+        // type-import-on-demand twice
+        {getPersistentCompanyModelInstance("dept1")}
+    };
+            
     /** */
     void runTest(PersistenceManager pm, CompanyModelReader reader) {
         Query query;
@@ -111,5 +174,23 @@
 
         tx.commit();
         tx = null;
+    }
+    
+    /** */
+    public void testPositive() {
+        for (int i = 0; i < VALID_QUERIES.length; i++) {
+            executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], 
+                    parameters[i], expectedResult[i]);
+            executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], 
+                    parameters[i], expectedResult[i]);
+        }
+    }
+    
+    /**
+     * @see JDO_Test#localSetUp()
+     */
+    protected void localSetUp() {
+        loadAndPersistCompanyModel(getPM());
+        addTearDownClass(CompanyModelReader.getTearDownClasses());
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NamespaceOfIdentifiers.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NamespaceOfIdentifiers.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NamespaceOfIdentifiers.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NamespaceOfIdentifiers.java Fri Dec  2 08:19:42 2005
@@ -22,6 +22,7 @@
 import javax.jdo.PersistenceManager;
 import javax.jdo.Transaction;
 
+import org.apache.jdo.tck.JDO_Test;
 import org.apache.jdo.tck.pc.mylib.PrimitiveTypes;
 import org.apache.jdo.tck.query.QueryTest;
 import org.apache.jdo.tck.util.BatchTestRunner;
@@ -54,23 +55,9 @@
         BatchTestRunner.run(NamespaceOfIdentifiers.class);
     }
     
-   /** */
-    public void test() {
-        pm = getPM();
-
-        try {
-            loadPrimitiveTypes(pm);
-            runTest(pm);
-        }
-        finally {
-            cleanupDatabase(pm, PrimitiveTypes.class);
-            pm.close();
-            pm = null;
-        }
-    }
-    
     /** */
-    void runTest(PersistenceManager pm) {
+    public void testPositive() {
+        PersistenceManager pm = getPM();
         Transaction tx = pm.currentTransaction();
         tx.begin();
 
@@ -95,5 +82,13 @@
              pm, instance9, ASSERTION_FAILED);
 
         tx.commit();
+    }
+
+    /**
+     * @see JDO_Test#localSetUp()
+     */
+    protected void localSetUp() {
+        loadAndPersistPrimitiveTypes(getPM());
+        addTearDownClass(PrimitiveTypes.class);
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NavigationThroughACollectionField.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NavigationThroughACollectionField.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NavigationThroughACollectionField.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NavigationThroughACollectionField.java Fri Dec  2 08:19:42 2005
@@ -16,15 +16,10 @@
 
 package org.apache.jdo.tck.query.jdoql;
 
-import java.util.Collection;
-import java.util.HashSet;
-
-import javax.jdo.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-
+import org.apache.jdo.tck.JDO_Test;
 import org.apache.jdo.tck.pc.company.CompanyModelReader;
 import org.apache.jdo.tck.pc.company.Department;
+import org.apache.jdo.tck.query.QueryElementHolder;
 import org.apache.jdo.tck.query.QueryTest;
 import org.apache.jdo.tck.util.BatchTestRunner;
 
@@ -47,6 +42,34 @@
     private static final String ASSERTION_FAILED = 
         "Assertion A14.6.2-10 (NavigationThroughACollectionField) failed: ";
     
+    /** 
+     * The array of valid queries which may be executed as 
+     * single string queries and as API queries.
+     */
+    private static final QueryElementHolder[] VALID_QUERIES = {
+        new QueryElementHolder(
+        /*UNIQUE*/      null,
+        /*RESULT*/      null,
+        /*INTO*/        null, 
+        /*FROM*/        Department.class,
+        /*EXCLUDE*/     null,
+        /*WHERE*/       "employees.contains(e) && e.firstname == \"emp1First\"",
+        /*VARIABLES*/   "Employee e",
+        /*PARAMETERS*/  null,
+        /*IMPORTS*/     null,
+        /*GROUP BY*/    null,
+        /*ORDER BY*/    null,
+        /*FROM*/        null,
+        /*TO*/          null)
+    };
+        
+    /** 
+     * The expected results of valid queries.
+     */
+    private Object[] expectedResult = {
+        getTransientCompanyModelInstancesAsList(new String[]{"dept1"})
+    };
+    
     /**
      * The <code>main</code> is called when the class
      * is directly executed from the command line.
@@ -57,38 +80,20 @@
     }
     
     /** */
-    public void test() {
-        pm = getPM();
-        
-        try {
-            // read test data
-            CompanyModelReader reader = loadCompanyModel(pm, COMPANY_TESTDATA);
-            runTest(pm, reader);
-        }
-        finally {
-            cleanupCompanyModel(pm);
-            pm.close();
-            pm = null;
+    public void testPositive() {
+        for (int i = 0; i < VALID_QUERIES.length; i++) {
+            executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], 
+                    expectedResult[i]);
+            executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], 
+                    expectedResult[i]);
         }
     }
     
-    /** */
-    void runTest(PersistenceManager pm, CompanyModelReader reader) {
-        Query q;
-        Object result;
-        Collection expected;
-        
-        Transaction tx = pm.currentTransaction();
-        tx.begin();
-        
-        q = pm.newQuery(Department.class);
-        q.declareVariables("Employee e");
-        q.setFilter("employees.contains(e) && e.firstname == \"emp1First\"");
-        result = q.execute();
-        expected = new HashSet();
-        expected.add(reader.getDepartment("dept1"));
-        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
-        
-        tx.commit();
+    /**
+     * @see JDO_Test#localSetUp()
+     */
+    protected void localSetUp() {
+        loadAndPersistCompanyModel(getPM());
+        addTearDownClass(CompanyModelReader.getTearDownClasses());
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NavigationThroughANullValuedField.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NavigationThroughANullValuedField.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NavigationThroughANullValuedField.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NavigationThroughANullValuedField.java Fri Dec  2 08:19:42 2005
@@ -16,16 +16,11 @@
 
 package org.apache.jdo.tck.query.jdoql;
 
-import java.util.Collection;
-import java.util.HashSet;
-
-import javax.jdo.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-
+import org.apache.jdo.tck.JDO_Test;
 import org.apache.jdo.tck.pc.company.CompanyModelReader;
 import org.apache.jdo.tck.pc.company.Department;
 import org.apache.jdo.tck.pc.company.Employee;
+import org.apache.jdo.tck.query.QueryElementHolder;
 import org.apache.jdo.tck.query.QueryTest;
 import org.apache.jdo.tck.util.BatchTestRunner;
 
@@ -50,6 +45,63 @@
     private static final String ASSERTION_FAILED = 
         "Assertion A14.6.2-9 (NavigationThroughANullValuedField) failed: ";
     
+    /** 
+     * The array of valid queries which may be executed as 
+     * single string queries and as API queries.
+     */
+    private static final QueryElementHolder[] VALID_QUERIES = {
+        // navigation through reference relationship field
+        // the relationship medicalInsurence is not set for emp2 and emp3 =>
+        // they should not be part of the result
+        new QueryElementHolder(
+        /*UNIQUE*/      null,
+        /*RESULT*/      null,
+        /*INTO*/        null, 
+        /*FROM*/        Employee.class,
+        /*EXCLUDE*/     null,
+        /*WHERE*/       "medicalInsurance.carrier == \"Carrier1\"",
+        /*VARIABLES*/   null,
+        /*PARAMETERS*/  null,
+        /*IMPORTS*/     null,
+        /*GROUP BY*/    null,
+        /*ORDER BY*/    null,
+        /*FROM*/        null,
+        /*TO*/          null),
+        // navigation through collection relationship field
+        // employees emp2 and emp3 do not have a medicalInsurence, but emp1 
+        // matches the filter such that dept1 qualifies for inclusion in the 
+        // result set.
+        new QueryElementHolder(
+        /*UNIQUE*/      null,
+        /*RESULT*/      null,
+        /*INTO*/        null, 
+        /*FROM*/        Department.class,
+        /*EXCLUDE*/     null,
+        /*WHERE*/       "employees.contains(e) && e.medicalInsurance.carrier == \"Carrier1\"",
+        /*VARIABLES*/   "Employee e",
+        /*PARAMETERS*/  null,
+        /*IMPORTS*/     null,
+        /*GROUP BY*/    null,
+        /*ORDER BY*/    null,
+        /*FROM*/        null,
+        /*TO*/          null)
+    };
+        
+    /** 
+     * The expected results of valid queries.
+     */
+    private Object[] expectedResult = {
+        // navigation through reference relationship field
+        // the relationship medicalInsurence is not set for emp2 and emp3 =>
+        // they should not be part of the result
+        getTransientCompanyModelInstancesAsList(new String[]{"emp1"}),
+        // navigation through collection relationship field
+        // employees emp2 and emp3 do not have a medicalInsurence, but emp1 
+        // matches the filter such that dept1 qualifies for inclusion in the 
+        // result set.
+        getTransientCompanyModelInstancesAsList(new String[]{"dept1"})
+    };
+    
     /**
      * The <code>main</code> is called when the class
      * is directly executed from the command line.
@@ -60,52 +112,20 @@
     }
     
     /** */
-    public void test() {
-        pm = getPM();
-        
-        try {
-            // read test data
-            CompanyModelReader reader = loadCompanyModel(pm, COMPANY_TESTDATA);
-            runTest(pm, reader);
-        }
-        finally {
-            cleanupCompanyModel(pm);
-            pm.close();
-            pm = null;
+    public void testPositive() {
+        for (int i = 0; i < VALID_QUERIES.length; i++) {
+            executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], 
+                    expectedResult[i]);
+            executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], 
+                    expectedResult[i]);
         }
     }
     
-    /** */
-    void runTest(PersistenceManager pm, CompanyModelReader reader) {
-        Query q;
-        Object result;
-        Collection expected;
-        
-        Transaction tx = pm.currentTransaction();
-        tx.begin();
-        
-        // navigation through reference relationship field
-        // the relationship medicalInsurence is not set for emp2 and emp3 =>
-        // they should not be part of the result
-        q = pm.newQuery(Employee.class);
-        q.setFilter("medicalInsurance.carrier == \"Carrier1\"");
-        result = q.execute();
-        expected = new HashSet();
-        expected.add(reader.getFullTimeEmployee("emp1"));
-        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
-        
-        // navigation through collection relationship field
-        // employees emp2 and emp3 do not have a medicalInsurence, but emp1 
-        // matches the filter such that dept1 qualifies for inclusion in the 
-        // result set.
-        q = pm.newQuery(Department.class);
-        q.declareVariables("Employee e");
-        q.setFilter("employees.contains(e) && e.medicalInsurance.carrier == \"Carrier1\"");
-        result = q.execute();
-        expected = new HashSet();
-        expected.add(reader.getDepartment("dept1"));
-        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
-        
-        tx.commit();
+    /**
+     * @see JDO_Test#localSetUp()
+     */
+    protected void localSetUp() {
+        loadAndPersistCompanyModel(getPM());
+        addTearDownClass(CompanyModelReader.getTearDownClasses());
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NavigationThroughReferencesUsesDotOperator.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NavigationThroughReferencesUsesDotOperator.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NavigationThroughReferencesUsesDotOperator.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NavigationThroughReferencesUsesDotOperator.java Fri Dec  2 08:19:42 2005
@@ -16,16 +16,11 @@
 
 package org.apache.jdo.tck.query.jdoql;
 
-import java.util.Collection;
-import java.util.HashSet;
-
-import javax.jdo.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-
+import org.apache.jdo.tck.JDO_Test;
 import org.apache.jdo.tck.pc.company.CompanyModelReader;
 import org.apache.jdo.tck.pc.company.Employee;
 import org.apache.jdo.tck.pc.company.MedicalInsurance;
+import org.apache.jdo.tck.query.QueryElementHolder;
 import org.apache.jdo.tck.query.QueryTest;
 import org.apache.jdo.tck.util.BatchTestRunner;
 
@@ -47,6 +42,54 @@
     private static final String ASSERTION_FAILED = 
         "Assertion A14.6.2-13 (NavigationThroughReferencesUsesDotOperator) failed: ";
     
+    /** 
+     * The array of valid queries which may be executed as 
+     * single string queries and as API queries.
+     */
+    private static final QueryElementHolder[] VALID_QUERIES = {
+        // navigation through one relationship
+        new QueryElementHolder(
+        /*UNIQUE*/      null,
+        /*RESULT*/      null,
+        /*INTO*/        null, 
+        /*FROM*/        Employee.class,
+        /*EXCLUDE*/     null,
+        /*WHERE*/       "medicalInsurance.carrier == \"Carrier1\"",
+        /*VARIABLES*/   null,
+        /*PARAMETERS*/  null,
+        /*IMPORTS*/     null,
+        /*GROUP BY*/    null,
+        /*ORDER BY*/    null,
+        /*FROM*/        null,
+        /*TO*/          null),
+        // navigation through multiple relationships
+        new QueryElementHolder(
+        /*UNIQUE*/      null,
+        /*RESULT*/      null,
+        /*INTO*/        null, 
+        /*FROM*/        MedicalInsurance.class,
+        /*EXCLUDE*/     null,
+        /*WHERE*/       "this.employee.department.name == \"Development\"",
+        /*VARIABLES*/   null,
+        /*PARAMETERS*/  null,
+        /*IMPORTS*/     null,
+        /*GROUP BY*/    null,
+        /*ORDER BY*/    null,
+        /*FROM*/        null,
+        /*TO*/          null)
+    };
+        
+    /** 
+     * The expected results of valid queries.
+     */
+    private Object[] expectedResult = {
+        // navigation through one relationship
+        getTransientCompanyModelInstancesAsList(new String[]{"emp1"}),
+        // navigation through multiple relationships
+        getTransientCompanyModelInstancesAsList(new String[]{
+                "medicalIns1", "medicalIns2", "medicalIns3"})
+    };
+    
     /**
      * The <code>main</code> is called when the class
      * is directly executed from the command line.
@@ -57,48 +100,20 @@
     }
     
     /** */
-    public void test() {
-        pm = getPM();
-        
-        try {
-            // read test data
-            CompanyModelReader reader = loadCompanyModel(pm, COMPANY_TESTDATA);
-            runTest(pm, reader);
-        }
-        finally {
-            cleanupCompanyModel(pm);
-            pm.close();
-            pm = null;
+    public void testPositive() {
+        for (int i = 0; i < VALID_QUERIES.length; i++) {
+            executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], 
+                    expectedResult[i]);
+            executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], 
+                    expectedResult[i]);
         }
     }
     
-    /** */
-    void runTest(PersistenceManager pm, CompanyModelReader reader) {
-        Query q;
-        Object result;
-        Collection expected;
-        
-        Transaction tx = pm.currentTransaction();
-        tx.begin();
-        
-        // navigation through one relationship
-        q = pm.newQuery(Employee.class);
-        q.setFilter("medicalInsurance.carrier == \"Carrier1\"");
-        result = q.execute();
-        expected = new HashSet();
-        expected.add(reader.getFullTimeEmployee("emp1"));
-        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
-        
-        // navigation through multiple relationships
-        q = pm.newQuery(MedicalInsurance.class);
-        q.setFilter("this.employee.department.name == \"Development\"");
-        result = q.execute();
-        expected = new HashSet();
-        expected.add(reader.getMedicalInsurance("medicalIns1"));
-        expected.add(reader.getMedicalInsurance("medicalIns2"));
-        expected.add(reader.getMedicalInsurance("medicalIns3"));
-        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
-        
-        tx.commit();
+    /**
+     * @see JDO_Test#localSetUp()
+     */
+    protected void localSetUp() {
+        loadAndPersistCompanyModel(getPM());
+        addTearDownClass(CompanyModelReader.getTearDownClasses());
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NegativeRange.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NegativeRange.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NegativeRange.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NegativeRange.java Fri Dec  2 08:19:42 2005
@@ -151,7 +151,7 @@
      * @see JDO_Test#localSetUp()
      */
     protected void localSetUp() {
-        loadCompanyModel(getPM(), COMPANY_TESTDATA);
+        loadAndPersistCompanyModel(getPM());
         addTearDownClass(CompanyModelReader.getTearDownClasses());
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NullCollectionsAndContainsMethod.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NullCollectionsAndContainsMethod.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NullCollectionsAndContainsMethod.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NullCollectionsAndContainsMethod.java Fri Dec  2 08:19:42 2005
@@ -16,16 +16,11 @@
 
 package org.apache.jdo.tck.query.jdoql;
 
-import java.util.Collection;
-import java.util.HashSet;
-
-import javax.jdo.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.company.CompanyModelReader;
 import org.apache.jdo.tck.pc.company.Employee;
 import org.apache.jdo.tck.pc.company.Project;
-import org.apache.jdo.tck.pc.company.CompanyModelReader;
+import org.apache.jdo.tck.query.QueryElementHolder;
 import org.apache.jdo.tck.query.QueryTest;
 import org.apache.jdo.tck.util.BatchTestRunner;
 
@@ -48,6 +43,62 @@
     private static final String ASSERTION_FAILED = 
         "Assertion A14.6.2-35 (NullCollectionsAndContainsMethod) failed: ";
     
+    /** 
+     * The array of valid queries which may be executed as 
+     * single string queries and as API queries.
+     */
+    private static final QueryElementHolder[] VALID_QUERIES = {
+        // contains 
+        new QueryElementHolder(
+        /*UNIQUE*/      null,
+        /*RESULT*/      null,
+        /*INTO*/        null, 
+        /*FROM*/        Employee.class,
+        /*EXCLUDE*/     null,
+        /*WHERE*/       "personid == 1 && projects.contains(p)",
+        /*VARIABLES*/   null,
+        /*PARAMETERS*/  "org.apache.jdo.tck.pc.company.Project p",
+        /*IMPORTS*/     null,
+        /*GROUP BY*/    null,
+        /*ORDER BY*/    null,
+        /*FROM*/        null,
+        /*TO*/          null),
+        // contains 
+        new QueryElementHolder(
+        /*UNIQUE*/      null,
+        /*RESULT*/      null,
+        /*INTO*/        null, 
+        /*FROM*/        Employee.class,
+        /*EXCLUDE*/     null,
+        /*WHERE*/       "!team.contains(null)",
+        /*VARIABLES*/   null,
+        /*PARAMETERS*/  null,
+        /*IMPORTS*/     null,
+        /*GROUP BY*/    null,
+        /*ORDER BY*/    null,
+        /*FROM*/        null,
+        /*TO*/          null),
+    };
+    
+    /** 
+     * The expected results of valid queries.
+     */
+    private Object[] expectedResult = {
+        // contains 
+        getTransientCompanyModelInstancesAsList(new String[]{}),
+        // contains 
+        getTransientCompanyModelInstancesAsList(new String[]{
+                "emp1", "emp2", "emp3", "emp4", "emp5"})
+    };
+    
+    /** Parameters of valid queries. */
+    private Object[][] parameters = {
+        // contains 
+        {new Project(999l, "TestProject", null)},
+        // contains 
+        null
+    };
+            
     /**
      * The <code>main</code> is called when the class
      * is directly executed from the command line.
@@ -58,54 +109,24 @@
     }
     
     /** */
-    public void test() {
-        pm = getPM();
-                
-        try {
-            // read test data
-            CompanyModelReader reader = loadCompanyModel(pm, COMPANY_TESTDATA);
-            runTest(pm, reader);
-        }
-        finally {
-            cleanupCompanyModel(pm);
-            pm.close();
-            pm = null;
+    public void testPositive() {
+        for (int i = 0; i < VALID_QUERIES.length; i++) {
+            executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], 
+                    parameters[i], expectedResult[i]);
+            executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], 
+                    parameters[i], expectedResult[i]);
         }
     }
     
-    /** */
-    void runTest(PersistenceManager pm, CompanyModelReader reader) {
-        Query q;
-        Object result;
-        Collection expected;
-        
-        Transaction tx = pm.currentTransaction();
-        tx.begin();
-        Employee emp1 = reader.getFullTimeEmployee("emp1");
+    /**
+     * @see JDO_Test#localSetUp()
+     */
+    protected void localSetUp() {
+        loadAndPersistCompanyModel(getPM());
+        getPM().currentTransaction().begin();
+        Employee emp1 = (Employee) getPersistentCompanyModelInstance("emp1");
         emp1.setProjects(null);
-        tx.commit();
-        
-        tx = pm.currentTransaction();
-        tx.begin();
-        
-        // contains 
-        q = pm.newQuery(Employee.class, "personid == 1 && projects.contains(p)");
-        q.declareParameters("org.apache.jdo.tck.pc.company.Project p");
-        result = q.execute(new Project(999l, "TestProject", null));
-        expected = new HashSet();
-        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
-                
-        // contains 
-        q = pm.newQuery(Employee.class, "!team.contains(null)");
-        result = q.execute();
-        expected = new HashSet();
-        expected.add(reader.getFullTimeEmployee("emp1"));
-        expected.add(reader.getFullTimeEmployee("emp2"));
-        expected.add(reader.getPartTimeEmployee("emp3"));
-        expected.add(reader.getPartTimeEmployee("emp4"));
-        expected.add(reader.getFullTimeEmployee("emp5"));
-        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
-            
-        tx.commit();
+        getPM().currentTransaction().commit();
+        addTearDownClass(CompanyModelReader.getTearDownClasses());
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NullCollectionsAndIsEmpty.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NullCollectionsAndIsEmpty.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NullCollectionsAndIsEmpty.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/NullCollectionsAndIsEmpty.java Fri Dec  2 08:19:42 2005
@@ -16,15 +16,10 @@
 
 package org.apache.jdo.tck.query.jdoql;
 
-import java.util.Collection;
-import java.util.HashSet;
-
-import javax.jdo.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-
-import org.apache.jdo.tck.pc.company.Employee;
+import org.apache.jdo.tck.JDO_Test;
 import org.apache.jdo.tck.pc.company.CompanyModelReader;
+import org.apache.jdo.tck.pc.company.Employee;
+import org.apache.jdo.tck.query.QueryElementHolder;
 import org.apache.jdo.tck.query.QueryTest;
 import org.apache.jdo.tck.util.BatchTestRunner;
 
@@ -46,6 +41,36 @@
     private static final String ASSERTION_FAILED = 
         "Assertion A14.6.2-34 (NullCollectionsAndIsEmpty) failed: ";
     
+    /** 
+     * The array of valid queries which may be executed as 
+     * single string queries and as API queries.
+     */
+    private static final QueryElementHolder[] VALID_QUERIES = {
+        // isEmpty
+        new QueryElementHolder(
+        /*UNIQUE*/      null,
+        /*RESULT*/      null,
+        /*INTO*/        null, 
+        /*FROM*/        Employee.class,
+        /*EXCLUDE*/     null,
+        /*WHERE*/       "personid == 1 && projects.isEmpty()",
+        /*VARIABLES*/   null,
+        /*PARAMETERS*/  null,
+        /*IMPORTS*/     null,
+        /*GROUP BY*/    null,
+        /*ORDER BY*/    null,
+        /*FROM*/        null,
+        /*TO*/          null),
+    };
+    
+    /** 
+     * The expected results of valid queries.
+     */
+    private Object[] expectedResult = {
+        // isEmpty
+        getTransientCompanyModelInstancesAsList(new String[]{"emp1"})
+    };
+    
     /**
      * The <code>main</code> is called when the class
      * is directly executed from the command line.
@@ -56,43 +81,24 @@
     }
     
     /** */
-    public void test() {
-        pm = getPM();
-                
-        try {
-            // read test data
-            CompanyModelReader reader = loadCompanyModel(pm, COMPANY_TESTDATA);
-            runTest(pm, reader);
-        }
-        finally {
-            cleanupCompanyModel(pm);
-            pm.close();
-            pm = null;
+    public void testPositive() {
+        for (int i = 0; i < VALID_QUERIES.length; i++) {
+            executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], 
+                    expectedResult[i]);
+            executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], 
+                    expectedResult[i]);
         }
     }
     
-    /** */
-    void runTest(PersistenceManager pm, CompanyModelReader reader) {
-        Query q;
-        Object result;
-        Collection expected;
-        
-        Transaction tx = pm.currentTransaction();
-        tx.begin();
-        Employee emp1 = reader.getFullTimeEmployee("emp1");
+    /**
+     * @see JDO_Test#localSetUp()
+     */
+    protected void localSetUp() {
+        loadAndPersistCompanyModel(getPM());
+        getPM().currentTransaction().begin();
+        Employee emp1 = (Employee) getPersistentCompanyModelInstance("emp1");
         emp1.setProjects(null);
-        tx.commit();
-        
-        tx = pm.currentTransaction();
-        tx.begin();
-        
-        // isEmpty
-        q = pm.newQuery(Employee.class, "personid == 1 && projects.isEmpty()");
-        result = q.execute();
-        expected = new HashSet();
-        expected.add(emp1);
-        checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected);
-            
-        tx.commit();
+        getPM().currentTransaction().commit();
+        addTearDownClass(CompanyModelReader.getTearDownClasses());
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/OrderingSpecification.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/OrderingSpecification.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/OrderingSpecification.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/OrderingSpecification.java Fri Dec  2 08:19:42 2005
@@ -25,6 +25,7 @@
 import javax.jdo.Query;
 import javax.jdo.Transaction;
 
+import org.apache.jdo.tck.JDO_Test;
 import org.apache.jdo.tck.pc.fieldtypes.AllTypes;
 import org.apache.jdo.tck.pc.mylib.PCPoint;
 import org.apache.jdo.tck.query.QueryTest;
@@ -66,16 +67,12 @@
     }
 
     /** */
-    public void test() {
-        pm = getPM();
+    public void testPositive() {
+        PersistenceManager pm = getPM();
 
-        initDatabase(pm, PCPoint.class);
         runTestOrderingSpecification01(pm);
         runTestOrderingSpecification02(pm);
         checkOrderingTypes(pm);
-        
-        pm.close();
-        pm = null;
     }
 
     /** */
@@ -188,5 +185,13 @@
             if ((tx != null) && tx.isActive())
                 tx.rollback();
         }
+    }
+
+    /**
+     * @see JDO_Test#localSetUp()
+     */
+    protected void localSetUp() {
+        loadAndPersistPCPoints(getPM());
+        addTearDownClass(PCPoint.class);
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/ParenthesesMarkOperatorPrecedence.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/ParenthesesMarkOperatorPrecedence.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/ParenthesesMarkOperatorPrecedence.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/ParenthesesMarkOperatorPrecedence.java Fri Dec  2 08:19:42 2005
@@ -24,6 +24,7 @@
 import javax.jdo.Query;
 import javax.jdo.Transaction;
 
+import org.apache.jdo.tck.JDO_Test;
 import org.apache.jdo.tck.pc.mylib.PCPoint;
 import org.apache.jdo.tck.query.QueryTest;
 import org.apache.jdo.tck.util.BatchTestRunner;
@@ -55,10 +56,9 @@
     }
 
     /** */
-    public void test() {
-        pm = getPM();
+    public void testPositive() {
+        PersistenceManager pm = getPM();
 
-        initDatabase(pm, PCPoint.class);
         runTestParenthesesMarkOperatorPrecedence01(pm);
         runTestParenthesesMarkOperatorPrecedence02(pm);
         runTestParenthesesMarkOperatorPrecedence03(pm);
@@ -68,9 +68,6 @@
         runTestParenthesesMarkOperatorPrecedence07(pm);
         runTestParenthesesMarkOperatorPrecedence08(pm);
         runTestParenthesesMarkOperatorPrecedence09(pm);
-
-        pm.close();
-        pm = null;
     }
 
     /** */
@@ -375,6 +372,14 @@
             if ((tx != null) && tx.isActive())
                 tx.rollback();
         }
+    }
+
+    /**
+     * @see JDO_Test#localSetUp()
+     */
+    protected void localSetUp() {
+        loadAndPersistPCPoints(getPM());
+        addTearDownClass(PCPoint.class);
     }
 }
 

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/PositiveRange.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/PositiveRange.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/PositiveRange.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/PositiveRange.java Fri Dec  2 08:19:42 2005
@@ -106,13 +106,13 @@
      * The expected results of valid queries.
      */
     private Object[] expectedResult = {
-        getCompanyModelInstancesAsList(new String[]{
+        getTransientCompanyModelInstancesAsList(new String[]{
                 "emp1", "emp2", "emp3", "emp4", "emp5"}),
-        getCompanyModelInstancesAsList(new String[]{
+        getTransientCompanyModelInstancesAsList(new String[]{
                 "emp1", "emp2", "emp3", "emp4"}),
-        getCompanyModelInstancesAsList(new String[]{
+        getTransientCompanyModelInstancesAsList(new String[]{
                 "emp2", "emp3", "emp4", "emp5"}),
-        getCompanyModelInstancesAsList(new String[]{
+        getTransientCompanyModelInstancesAsList(new String[]{
                 "emp2", "emp3", "emp4"})
     };
             
@@ -139,7 +139,7 @@
      * @see JDO_Test#localSetUp()
      */
     protected void localSetUp() {
-        loadCompanyModel(getPM(), COMPANY_TESTDATA);
+        loadAndPersistCompanyModel(getPM());
         addTearDownClass(CompanyModelReader.getTearDownClasses());
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/QueryIsSerializable.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/QueryIsSerializable.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/QueryIsSerializable.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/QueryIsSerializable.java Fri Dec  2 08:19:42 2005
@@ -29,6 +29,7 @@
 import javax.jdo.Query;
 import javax.jdo.Transaction;
 
+import org.apache.jdo.tck.JDO_Test;
 import org.apache.jdo.tck.pc.mylib.PCPoint;
 import org.apache.jdo.tck.query.QueryTest;
 import org.apache.jdo.tck.util.BatchTestRunner;
@@ -62,16 +63,12 @@
     }
 
     /** */
-    public void test() throws Exception {
-        pm = getPM();
+    public void testPositive() throws Exception {
+        PersistenceManager pm = getPM();
 
-        initDatabase(pm, PCPoint.class);
         runTestQueryIsSerializable01(pm);
         runTestQueryIsSerializable02(pm);
         runTestQueryIsSerializable03(pm);
-        
-        pm.close();
-        pm = null;
     }
 
     /** */
@@ -182,6 +179,14 @@
             if ((tx != null) && tx.isActive())
                 tx.rollback();
         }
+    }
+
+    /**
+     * @see JDO_Test#localSetUp()
+     */
+    protected void localSetUp() {
+        loadAndPersistPCPoints(getPM());
+        addTearDownClass(PCPoint.class);
     }
 }
 

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/QueryResultPassedToAnotherQuery.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/QueryResultPassedToAnotherQuery.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/QueryResultPassedToAnotherQuery.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/QueryResultPassedToAnotherQuery.java Fri Dec  2 08:19:42 2005
@@ -25,6 +25,7 @@
 import javax.jdo.Query;
 import javax.jdo.Transaction;
 
+import org.apache.jdo.tck.JDO_Test;
 import org.apache.jdo.tck.pc.mylib.PCPoint;
 import org.apache.jdo.tck.query.QueryTest;
 import org.apache.jdo.tck.util.BatchTestRunner;
@@ -58,10 +59,9 @@
     Collection resultCln;
 
     /** */
-    public void test() {
-        pm = getPM();
+    public void testPositive() {
+        PersistenceManager pm = getPM();
 
-        initDatabase(pm, PCPoint.class);
         setResultCollection(pm);
         runTestQueryResultPassedToAnotherQuery01(pm);
         runTestQueryResultPassedToAnotherQuery02(pm);
@@ -81,6 +81,10 @@
             query.setClass(PCPoint.class);
             query.setCandidates(pm.getExtent(PCPoint.class, false));
             resultCln = (Collection)query.execute();
+            // Create a new collection for the result collection.
+            // This ensures that the result collection may be iterated
+            // outside of the scope of the current transaction.
+            resultCln = new ArrayList(resultCln);
             
             tx.commit();
             tx = null;
@@ -186,5 +190,13 @@
             if ((tx != null) && tx.isActive())
                 tx.rollback();
         }
+    }
+
+    /**
+     * @see JDO_Test#localSetUp()
+     */
+    protected void localSetUp() {
+        loadAndPersistPCPoints(getPM());
+        addTearDownClass(PCPoint.class);
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/QueryWithNoFilter.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/QueryWithNoFilter.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/QueryWithNoFilter.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/QueryWithNoFilter.java Fri Dec  2 08:19:42 2005
@@ -24,6 +24,7 @@
 import javax.jdo.Query;
 import javax.jdo.Transaction;
 
+import org.apache.jdo.tck.JDO_Test;
 import org.apache.jdo.tck.pc.mylib.PCPoint;
 import org.apache.jdo.tck.query.QueryTest;
 import org.apache.jdo.tck.util.BatchTestRunner;
@@ -56,18 +57,8 @@
     }
 
     /** */
-    public void test() {
-        pm = getPM();
-
-        initDatabase(pm, PCPoint.class);
-        runTestQueryWithNoFilter(pm);
-
-        pm.close();
-        pm = null;
-    }
-
-    /** */
-    void runTestQueryWithNoFilter(PersistenceManager pm) {
+    public void testPositive() {
+        PersistenceManager pm = getPM();
         if(debug) logger.debug("\nExecuting test QueryWithNoFilter() ...");
 
         Transaction tx = pm.currentTransaction();
@@ -102,5 +93,13 @@
             if ((tx != null) && tx.isActive())
                 tx.rollback();
         }
+    }
+
+    /**
+     * @see JDO_Test#localSetUp()
+     */
+    protected void localSetUp() {
+        loadAndPersistPCPoints(getPM());
+        addTearDownClass(PCPoint.class);
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/RangeAsString.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/RangeAsString.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/RangeAsString.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/RangeAsString.java Fri Dec  2 08:19:42 2005
@@ -106,13 +106,13 @@
      * The expected results of valid queries.
      */
     private Object[] expectedResult = {
-        getCompanyModelInstancesAsList(new String[]{
+        getTransientCompanyModelInstancesAsList(new String[]{
                 "emp1", "emp2", "emp3", "emp4", "emp5"}),
-        getCompanyModelInstancesAsList(new String[]{
+        getTransientCompanyModelInstancesAsList(new String[]{
                 "emp1", "emp2", "emp3", "emp4"}),
-        getCompanyModelInstancesAsList(new String[]{
+        getTransientCompanyModelInstancesAsList(new String[]{
                 "emp2", "emp3", "emp4", "emp5"}),
-        getCompanyModelInstancesAsList(new String[]{
+        getTransientCompanyModelInstancesAsList(new String[]{
                 "emp2", "emp3", "emp4"})
     };
             
@@ -139,7 +139,7 @@
      * @see JDO_Test#localSetUp()
      */
     protected void localSetUp() {
-        loadCompanyModel(getPM(), COMPANY_TESTDATA);
+        loadAndPersistCompanyModel(getPM());
         addTearDownClass(CompanyModelReader.getTearDownClasses());
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/SeparateNamespaceForTypeNames.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/SeparateNamespaceForTypeNames.java?rev=351768&r1=351767&r2=351768&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/SeparateNamespaceForTypeNames.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/SeparateNamespaceForTypeNames.java Fri Dec  2 08:19:42 2005
@@ -16,17 +16,11 @@
 
 package org.apache.jdo.tck.query.jdoql;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-
-import javax.jdo.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-
+import org.apache.jdo.tck.JDO_Test;
 import org.apache.jdo.tck.pc.company.CompanyModelReader;
 import org.apache.jdo.tck.pc.company.Department;
 import org.apache.jdo.tck.pc.company.Employee;
+import org.apache.jdo.tck.query.QueryElementHolder;
 import org.apache.jdo.tck.query.QueryTest;
 import org.apache.jdo.tck.util.BatchTestRunner;
 
@@ -49,6 +43,61 @@
     private static final String ASSERTION_FAILED = 
         "Assertion A14.4-1 (SeparateNamespaceForTypeNames) failed: ";
     
+    /** 
+     * The array of valid queries which may be executed as 
+     * single string queries and as API queries.
+     */
+    private static final QueryElementHolder[] VALID_QUERIES = {
+        // query having a parameter with the same name as a type
+        new QueryElementHolder(
+        /*UNIQUE*/      null,
+        /*RESULT*/      null,
+        /*INTO*/        null, 
+        /*FROM*/        Employee.class,
+        /*EXCLUDE*/     null,
+        /*WHERE*/       "department == Department",
+        /*VARIABLES*/   null,
+        /*PARAMETERS*/  "Department Department",
+        /*IMPORTS*/     "import org.apache.jdo.tck.pc.company.Department",
+        /*GROUP BY*/    null,
+        /*ORDER BY*/    null,
+        /*FROM*/        null,
+        /*TO*/          null),
+        // query having a parameter with the same name as a type
+        new QueryElementHolder(
+        /*UNIQUE*/      null,
+        /*RESULT*/      null,
+        /*INTO*/        null, 
+        /*FROM*/        Department.class,
+        /*EXCLUDE*/     null,
+        /*WHERE*/       "employees.contains(Employee) && Employee.firstname == \"emp1First\"",
+        /*VARIABLES*/   "Employee Employee",
+        /*PARAMETERS*/  null,
+        /*IMPORTS*/     "import org.apache.jdo.tck.pc.company.Employee",
+        /*GROUP BY*/    null,
+        /*ORDER BY*/    null,
+        /*FROM*/        null,
+        /*TO*/          null),
+    };
+    
+    /** 
+     * The expected results of valid queries.
+     */
+    private Object[] expectedResult = {
+        // query having a parameter with the same name as a type
+        getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp2", "emp3"}),
+        // query having a parameter with the same name as a type
+        getTransientCompanyModelInstancesAsList(new String[]{"dept1"})
+    };
+    
+    /** Parameters of valid queries. */
+    private Object[][] parameters = {
+        // query having a parameter with the same name as a type
+        {getPersistentCompanyModelInstance("dept1")},
+        // query having a parameter with the same name as a type
+        null
+    };
+            
     /**
      * The <code>main</code> is called when the class
      * is directly executed from the command line.
@@ -59,53 +108,20 @@
     }
 
     /** */
-    public void test() {
-        pm = getPM();
-        
-        try {
-            // read test data
-            CompanyModelReader reader = loadCompanyModel(pm, COMPANY_TESTDATA);
-            runTest(pm, reader);
-        }
-        finally {
-            cleanupCompanyModel(pm);
-            pm.close();
-            pm = null;
+    public void testPositive() {
+        for (int i = 0; i < VALID_QUERIES.length; i++) {
+            executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], 
+                    parameters[i], expectedResult[i]);
+            executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], 
+                    parameters[i], expectedResult[i]);
         }
     }
-
-    /** */
-    void runTest(PersistenceManager pm, CompanyModelReader reader) {
-        Transaction tx = pm.currentTransaction();
-        tx.begin();
-        Department dept1 = reader.getDepartment("dept1");
-
-
-        // query having a parameter with the same name as a type
-        Query query = pm.newQuery(Employee.class);
-        query.declareImports("import org.apache.jdo.tck.pc.company.Department");
-        query.declareParameters("Department Department");
-        query.setFilter("department == Department");
-        Object results = query.execute(dept1);
-
-        Collection expected = new HashSet();
-        expected.add(reader.getFullTimeEmployee("emp1"));
-        expected.add(reader.getFullTimeEmployee("emp2"));
-        expected.add(reader.getPartTimeEmployee("emp3"));
-        checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
-
-        // query having a parameter with the same name as a type
-        query = pm.newQuery(Department.class);
-        query.declareImports("import org.apache.jdo.tck.pc.company.Employee");
-        query.declareVariables("Employee Employee");
-        query.setFilter("employees.contains(Employee) && Employee.firstname == \"emp1First\"");
-        results = query.execute();
-
-        expected = new ArrayList();
-        expected.add(dept1);
-        checkQueryResultWithoutOrder(ASSERTION_FAILED, results, expected);
-
-        tx.commit();
-        tx = null;
+    
+    /**
+     * @see JDO_Test#localSetUp()
+     */
+    protected void localSetUp() {
+        loadAndPersistCompanyModel(getPM());
+        addTearDownClass(CompanyModelReader.getTearDownClasses());
     }
 }



Mime
View raw message