Index: test/java/org/apache/jdo/tck/query/jdoql/methods/SupportedCollectionMethods.java =================================================================== --- test/java/org/apache/jdo/tck/query/jdoql/methods/SupportedCollectionMethods.java (Revision 348914) +++ test/java/org/apache/jdo/tck/query/jdoql/methods/SupportedCollectionMethods.java (Arbeitskopie) @@ -16,16 +16,15 @@ package org.apache.jdo.tck.query.jdoql.methods; -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; @@ -41,6 +40,7 @@ * */ @@ -50,6 +50,105 @@ private static final String ASSERTION_FAILED = "Assertion A14.6.2-36 (SupportedCollectionMethods) 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(VARIABLE) + new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ "employees.contains(e) && e.personid == 1", + /*VARIABLES*/ "Employee e", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null), + // contains(PARAMETER) + new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ "employees.contains(e)", + /*VARIABLES*/ null, + /*PARAMETERS*/ "Employee e", + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null), + // !isEmpty + new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ "!employees.isEmpty()", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null), + // isEmpty + new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "team.isEmpty()", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null), + // size + new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ "employees.size() == 3", + /*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(VARIABLE) + getCompanyModelInstancesAsList(new String[]{"dept1"}), + // contains(PARAMETER) + getCompanyModelInstancesAsList(new String[]{"dept1"}), + // !isEmpty + getCompanyModelInstancesAsList(new String[]{"dept1", "dept2"}), + // isEmpty + getCompanyModelInstancesAsList(new String[]{ + "emp1", "emp3", "emp4", "emp5"}), + // size + getCompanyModelInstancesAsList(new String[]{"dept1"}) + }; + /** * The main is called when the class * is directly executed from the command line. @@ -60,67 +159,72 @@ } /** */ - public void test() { - pm = getPM(); + public void testContains() { + int index = 0; + executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], + expectedResult[index]); + executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], + expectedResult[index]); - try { - // read test data - CompanyModelReader reader = loadCompanyModel(pm, COMPANY_TESTDATA); - runTestIsEmpty(pm, reader); - runTestContains(pm, reader); + index++; + Object[] parameters = new Object[]{ + getParameter(Employee.class, "personid == 1", true)}; + executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], + parameters, expectedResult[index]); + executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], + parameters, expectedResult[index]); + } + + /** */ + public void testIsEmpty() { + for (int index = 2; index < 4; index++) { + executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], + expectedResult[index]); + executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], + expectedResult[index]); } - finally { - cleanupCompanyModel(pm); - pm.close(); - pm = null; - } } - + /** */ - void runTestIsEmpty(PersistenceManager pm, CompanyModelReader reader) { - Query q; - Object result; - Collection expected; + public void testSize() { + int index = 4; + executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], + expectedResult[index]); + executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], + expectedResult[index]); + } - Transaction tx = pm.currentTransaction(); - tx.begin(); - - q = pm.newQuery(Department.class, "!employees.isEmpty()"); - result = q.execute(); - expected = new HashSet(); - expected.add(reader.getDepartment("dept1")); - expected.add(reader.getDepartment("dept2")); - checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected); - - q = pm.newQuery(Employee.class, "team.isEmpty()"); - result = q.execute(); - expected = new HashSet(); - expected.add(reader.getFullTimeEmployee("emp1")); - expected.add(reader.getPartTimeEmployee("emp3")); - expected.add(reader.getPartTimeEmployee("emp4")); - expected.add(reader.getFullTimeEmployee("emp5")); - checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected); - - tx.commit(); + /** + * @see JDO_Test#localSetUp() + */ + protected void localSetUp() { + loadCompanyModel(getPM(), COMPANY_TESTDATA); + addTearDownClass(CompanyModelReader.getTearDownClasses()); } - + /** */ - void runTestContains(PersistenceManager pm, CompanyModelReader reader) { - Query q; + private Object getParameter( + Class candidateClass, String filter, boolean unique) { Object result; - Collection expected; - - Transaction tx = pm.currentTransaction(); - tx.begin(); - - q = pm.newQuery(Department.class); - q.setFilter("employees.contains(e) && e.personid == 1"); - q.declareVariables("Employee e"); - result = q.execute(); - expected = new HashSet(); - expected.add(reader.getDepartment("dept1")); - checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected); - - tx.commit(); + PersistenceManager pm = getPM(); + Transaction transaction = pm.currentTransaction(); + transaction.begin(); + try { + Query query = filter == null ? pm.newQuery(candidateClass) : + pm.newQuery(candidateClass, filter); + if (unique) { + query.setUnique(unique); + } + try { + result = query.execute(); + } finally { + query.closeAll(); + } + } finally { + if (transaction.isActive()) { + transaction.rollback(); + } + } + return result; } } Index: test/java/org/apache/jdo/tck/query/jdoql/methods/SupportedMapMethods.java =================================================================== --- test/java/org/apache/jdo/tck/query/jdoql/methods/SupportedMapMethods.java (Revision 348914) +++ test/java/org/apache/jdo/tck/query/jdoql/methods/SupportedMapMethods.java (Arbeitskopie) @@ -16,6 +16,8 @@ package org.apache.jdo.tck.query.jdoql.methods; +import java.util.ArrayList; + import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Person; @@ -36,6 +38,8 @@ *
  • get(Object) *
  • containsKey(Object) *
  • containsValue(Object) + *
  • isEmpty() + *
  • size() * */ public class SupportedMapMethods extends QueryTest { @@ -49,6 +53,7 @@ * single string queries and as API queries. */ private static final QueryElementHolder[] VALID_QUERIES = { + // get new QueryElementHolder( /*UNIQUE*/ null, /*RESULT*/ null, @@ -63,6 +68,7 @@ /*ORDER BY*/ null, /*FROM*/ null, /*TO*/ null), + // containsKey new QueryElementHolder( /*UNIQUE*/ null, /*RESULT*/ null, @@ -77,6 +83,7 @@ /*ORDER BY*/ null, /*FROM*/ null, /*TO*/ null), + // containsValue new QueryElementHolder( /*UNIQUE*/ null, /*RESULT*/ null, @@ -90,14 +97,55 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, + /*TO*/ null), + // isEmpty + new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ "phoneNumbers.isEmpty()", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null), + // size + new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ "phoneNumbers.size() == 2", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, /*TO*/ null) }; - /** The expected results of valid queries. */ - private static String[][] expectedResult = { - {"emp1"}, - {"emp1", "emp2", "emp3", "emp4", "emp5"}, - {"emp1"} + /** + * The expected results of valid queries. + */ + private Object[] expectedResult = { + // get + getCompanyModelInstancesAsList(new String[]{"emp1"}), + // containsKey + getCompanyModelInstancesAsList(new String[]{ + "emp1", "emp2", "emp3", "emp4", "emp5"}), + // containsValue + getCompanyModelInstancesAsList(new String[]{"emp1"}), + // isEmpty + new ArrayList(), + // size + getCompanyModelInstancesAsList(new String[]{ + "emp1", "emp2", "emp3", "emp4", "emp5"}) }; /** @@ -112,21 +160,48 @@ /** */ public void testGet() { int index = 0; - executeQuery(index); + executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], + expectedResult[index]); + executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], + expectedResult[index]); } /** */ public void testContainsKey() { int index = 1; - executeQuery(index); + executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], + expectedResult[index]); + executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], + expectedResult[index]); } /** */ public void testContainsValue() { int index = 2; - executeQuery(index); + executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], + expectedResult[index]); + executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], + expectedResult[index]); } + /** */ + public void testIsEmpty() { + int index = 3; + executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], + expectedResult[index]); + executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], + expectedResult[index]); + } + + /** */ + public void testSize() { + int index = 4; + executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], + expectedResult[index]); + executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], + expectedResult[index]); + } + /** * @see JDO_Test#localSetUp() */ @@ -134,15 +209,4 @@ loadCompanyModel(getPM(), COMPANY_TESTDATA); addTearDownClass(CompanyModelReader.getTearDownClasses()); } - - /** */ - private void executeQuery(int index) { - Object[] expectedResultValues = - getCompanyModelInstances(expectedResult[index]); - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResultValues); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResultValues); - } - }