You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-commits@db.apache.org by br...@apache.org on 2005/11/29 11:39:20 UTC
svn commit: r349701 - in
/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/methods:
SupportedCollectionMethods.java SupportedMapMethods.java
Author: brazil
Date: Tue Nov 29 02:39:17 2005
New Revision: 349701
URL: http://svn.apache.org/viewcvs?rev=349701&view=rev
Log:
JDO-223: SupportedMapMethods miss queries calling isEmpty() and size(). SupportedCollectionMethods must be extended by queries calling contains() and size().
Modified:
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/methods/SupportedCollectionMethods.java
incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/methods/SupportedMapMethods.java
Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/methods/SupportedCollectionMethods.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/methods/SupportedCollectionMethods.java?rev=349701&r1=349700&r2=349701&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/methods/SupportedCollectionMethods.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/methods/SupportedCollectionMethods.java Tue Nov 29 02:39:17 2005
@@ -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 @@
* <UL>
* <LI>isEmpty</LI>
* <LI>contains</LI>
+ * <LI>size</LI>
* </UL>
*/
@@ -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 <code>main</code> 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);
- }
- finally {
- cleanupCompanyModel(pm);
- pm.close();
- pm = null;
- }
+ 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]);
}
-
- /** */
- void runTestIsEmpty(PersistenceManager pm, CompanyModelReader reader) {
- Query q;
- Object result;
- Collection expected;
- Transaction tx = pm.currentTransaction();
- tx.begin();
+ /** */
+ 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]);
+ }
+ }
- 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();
+ /** */
+ 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()
+ */
+ 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;
}
}
Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/methods/SupportedMapMethods.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/methods/SupportedMapMethods.java?rev=349701&r1=349700&r2=349701&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/methods/SupportedMapMethods.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/jdoql/methods/SupportedMapMethods.java Tue Nov 29 02:39:17 2005
@@ -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 @@
* <li> get(Object)
* <li> containsKey(Object)
* <li> containsValue(Object)
+ * <li> isEmpty()
+ * <li> size()
* </ul>
*/
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,37 +160,53 @@
/** */
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]);
}
- /**
- * @see JDO_Test#localSetUp()
- */
- protected void localSetUp() {
- loadCompanyModel(getPM(), COMPANY_TESTDATA);
- addTearDownClass(CompanyModelReader.getTearDownClasses());
+ /** */
+ public void testIsEmpty() {
+ int index = 3;
+ executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index],
+ expectedResult[index]);
+ executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index],
+ expectedResult[index]);
}
/** */
- private void executeQuery(int index) {
- Object[] expectedResultValues =
- getCompanyModelInstances(expectedResult[index]);
+ public void testSize() {
+ int index = 4;
executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index],
- expectedResultValues);
+ expectedResult[index]);
executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index],
- expectedResultValues);
+ expectedResult[index]);
}
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ loadCompanyModel(getPM(), COMPANY_TESTDATA);
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ }
}