Index: test/java/org/apache/jdo/tck/pc/company/CompanyModelReader.java
===================================================================
--- test/java/org/apache/jdo/tck/pc/company/CompanyModelReader.java (Revision 332256)
+++ test/java/org/apache/jdo/tck/pc/company/CompanyModelReader.java (Arbeitskopie)
@@ -23,8 +23,9 @@
import java.util.Locale;
import java.util.TimeZone;
+import org.apache.jdo.tck.util.ConversionHelper;
+import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.beans.propertyeditors.CustomDateEditor;
-import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.InputStreamResource;
@@ -258,5 +259,9 @@
public static Class[] getTearDownClasses() {
return tearDownClasses;
}
+
+ public static Date stringToUtilDate(String value) {
+ return ConversionHelper.toUtilDate(DATE_PATTERN, "America/New_York", Locale.US, value);
+ }
}
Index: test/java/org/apache/jdo/tck/query/QueryTest.java
===================================================================
--- test/java/org/apache/jdo/tck/query/QueryTest.java (Revision 332256)
+++ test/java/org/apache/jdo/tck/query/QueryTest.java (Arbeitskopie)
@@ -24,6 +24,7 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import javax.jdo.Extent;
import javax.jdo.JDOFatalInternalException;
@@ -32,6 +33,8 @@
import javax.jdo.Query;
import javax.jdo.Transaction;
+import junit.framework.AssertionFailedError;
+
import org.apache.jdo.tck.JDO_Test;
import org.apache.jdo.tck.pc.company.Company;
import org.apache.jdo.tck.pc.company.CompanyModelReader;
@@ -42,6 +45,8 @@
import org.apache.jdo.tck.pc.mylib.MylibReader;
import org.apache.jdo.tck.pc.mylib.PCPoint;
import org.apache.jdo.tck.pc.mylib.PrimitiveTypes;
+import org.apache.jdo.tck.util.ConversionHelper;
+import org.apache.jdo.tck.util.EqualityHelper;
public abstract class QueryTest extends JDO_Test {
@@ -189,7 +194,8 @@
CompanyModelReader reader = new CompanyModelReader(COMPANY_TESTDATA);
Object[] result = new Object[beanNames.length];
for (int i = 0; i < beanNames.length; i++) {
- result[i] = reader.getBean(beanNames[i]);
+ result[i] = beanNames[i] == null ?
+ null : reader.getBean(beanNames[i]);
}
return result;
}
@@ -345,6 +351,10 @@
}
if (!compareOrderedResults((Collection)result, expected)) {
String lf = System.getProperty("line.separator");
+ result =
+ ConversionHelper.convertsElementsOfTypeObjectArray(result);
+ expected =
+ ConversionHelper.convertsElementsOfTypeObjectArray(expected);
fail(assertion,
"Wrong query result: " + lf +
"query returns: " + result + lf +
@@ -368,11 +378,7 @@
}
Object firstObject = firstIterator.next();
Object secondObject = secondIterator.next();
- if (firstObject == null) {
- if (secondObject != null) {
- return false;
- }
- } else if (!firstObject.equals(secondObject)) {
+ if (!equals(firstObject, secondObject)) {
return false;
}
}
@@ -397,11 +403,14 @@
result.getClass().getName());
}
- if (((Collection)result).size() != expected.size() ||
- !((Collection)result).containsAll(expected)) {
+ if (!equalsCollection((Collection)result, expected)) {
+ result =
+ ConversionHelper.convertsElementsOfTypeObjectArray(result);
+ expected =
+ ConversionHelper.convertsElementsOfTypeObjectArray(expected);
fail(assertion, "Wrong query result" +
- "\nexpected: " + new ArrayList(expected) +
- "\ngot: " + new ArrayList((Collection)result));
+ "\nexpected: " + expected +
+ "\ngot: " + result);
}
}
@@ -411,14 +420,132 @@
Object expected) {
if ((result != null && expected == null) ||
(result == null && expected != null) ||
- (result != null && expected != null && !result.equals(expected))) {
- String lf = System.getProperty("line.separator");
- fail(assertion, "Wrong query result: " + lf +
- "query returns: " + result + lf +
- "expected result: " + expected);
+ (result != null && expected != null)) {
+ if (!equals(result, expected)) {
+ String lf = System.getProperty("line.separator");
+ result = ConversionHelper.
+ convertsElementsOfTypeObjectArray(result);
+ expected = ConversionHelper.
+ convertsElementsOfTypeObjectArray(expected);
+ fail(assertion, "Wrong query result: " + lf +
+ "query returns: " + result + lf +
+ "expected result: " + expected);
+ }
}
}
+ private boolean equals(Object o1, Object o2) {
+ boolean result = true;
+ if ((o1 instanceof Object[]) && (o2 instanceof Object[])) {
+ result = equalsObjectArray((Object[])o1, (Object[])o2);
+ } else if ((o1 instanceof Collection) && (o2 instanceof Collection)) {
+ result = equalsCollection((Collection)o1, (Collection)o2);
+ } else if ((o1 instanceof Map) && (o2 instanceof Map)) {
+ result = equalsMap((Map)o1, (Map)o2);
+ }else if ((o1 instanceof Float) && (o2 instanceof Float)) {
+ result = closeEnough(((Float)o1).floatValue(),
+ ((Float)o2).floatValue());
+ } else if ((o1 instanceof Double) && (o2 instanceof Double)) {
+ result = closeEnough(((Double)o1).floatValue(),
+ ((Double)o2).floatValue());
+ } else if ((o1 instanceof BigDecimal) && (o2 instanceof BigDecimal)) {
+ result = ((BigDecimal)o1).compareTo(o2) == 0;
+ } else if (o1 != null) {
+ result = o1.equals(o2);
+ } else if (o2 != null) {
+ result = o2.equals(o1);
+ }
+ return result;
+ }
+
+ private boolean equalsObjectArray(Object[] o1, Object[] o2) {
+ boolean result = true;
+ if (o1.length != o2.length) {
+ result = false;
+ } else {
+ for (int i = 0; i < o1.length; i++ ) {
+ if (!equals(o1[i], o2[i])) {
+ result = false;
+ break;
+ }
+ }
+ }
+ return result;
+ }
+
+ private boolean equalsCollection(Collection o1, Collection o2) {
+ boolean result = true;
+ if (o1.size() != o2.size()) {
+ result = false;
+ } else {
+ for (Iterator i = o1.iterator(); i.hasNext(); ) {
+ Object oo1 = i.next();
+ if (!contains(o2, oo1)) {
+ result = false;
+ break;
+ }
+ }
+ }
+ return result;
+ }
+
+ private boolean equalsMap(Map o1, Map o2) {
+ boolean result = true;
+ if (o1.size() != o2.size()) {
+ result = false;
+ } else if (!equalsCollection(o1.keySet(), o2.keySet()) ||
+ !equalsCollection(o1.values(), o2.values())) {
+ result = false;
+ }
+ return result;
+ }
+
+ private boolean contains(Collection col, Object o) {
+ for (Iterator i = col.iterator(); i.hasNext(); ) {
+ if (equals(o, i.next())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /** Returns true if the specified float values are close
+ * enough to be considered to be equal for a deep equals
+ * comparison. Floating point values are not exact, so comparing them
+ * using == might not return useful results. This method
+ * checks that both double values are within some percent of each
+ * other.
+ * @param d1 one double to be tested for close enough
+ * @param d2 the other double to be tested for close enough
+ * @return true if the specified values are close enough.
+ */
+ public boolean closeEnough(double d1, double d2) {
+ if (d1 == d2)
+ return true;
+
+ double diff = Math.abs(d1 - d2);
+ return diff < Math.abs((d1 + d2) * EqualityHelper.DOUBLE_EPSILON);
+ }
+
+ /**
+ * Returns true if the specified float values are close
+ * enough to be considered to be equal for a deep equals
+ * comparison. Floating point values are not exact, so comparing them
+ * using == might not return useful results. This method
+ * checks that both float values are within some percent of each
+ * other.
+ * @param f1 one float to be tested for close enough
+ * @param f2 the other float to be tested for close enough
+ * @return true if the specified values are close enough.
+ */
+ public boolean closeEnough(float f1, float f2) {
+ if (f1 == f2)
+ return true;
+
+ float diff = Math.abs(f1 - f2);
+ return diff < Math.abs((f1 + f2) * EqualityHelper.FLOAT_EPSILON);
+ }
+
// Debugging helper methods
/** */
Index: test/java/org/apache/jdo/tck/query/jdoql/parameters/ImplicitParameters.java
===================================================================
--- test/java/org/apache/jdo/tck/query/jdoql/parameters/ImplicitParameters.java (Revision 332256)
+++ test/java/org/apache/jdo/tck/query/jdoql/parameters/ImplicitParameters.java (Arbeitskopie)
@@ -23,6 +23,7 @@
import org.apache.jdo.tck.query.QueryElementHolder;
import org.apache.jdo.tck.query.QueryTest;
import org.apache.jdo.tck.util.BatchTestRunner;
+import org.apache.jdo.tck.util.ConversionHelper;
/**
*Title: Implicit parameters.
@@ -127,7 +128,7 @@
public void testResult() {
int index = 0;
Object[] pcInstances =
- getCompanyModelInstances(toStringArray(expectedResult[index]));
+ getCompanyModelInstances(ConversionHelper.toStringArray(expectedResult[index]));
Object[] expectedResultValues = new Object[pcInstances.length];
String parameter = "parameterInResult";
for (int i = 0; i < expectedResultValues.length; i++) {
@@ -140,7 +141,7 @@
public void testFilter() {
int index = 1;
Object[] expectedResultValues =
- getCompanyModelInstances(toStringArray(expectedResult[index]));
+ getCompanyModelInstances(ConversionHelper.toStringArray(expectedResult[index]));
executeQuery(index, new Object[] {"emp1First"}, expectedResultValues);
}
@@ -154,7 +155,7 @@
public void testRange() {
int index = 3;
Object[] expectedResultValues =
- getCompanyModelInstances(toStringArray(expectedResult[index]));
+ getCompanyModelInstances(ConversionHelper.toStringArray(expectedResult[index]));
executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index],
new Object[] {new Long(0), new Long(5)}, expectedResultValues);
}
@@ -174,11 +175,4 @@
executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index],
parameters, expectedResultValues);
}
-
- /** */
- private String[] toStringArray(Object[] array) {
- String[] result = new String[array.length];
- System.arraycopy(array, 0, result, 0, result.length);
- return result;
- }
}
Index: test/java/org/apache/jdo/tck/query/result/Unique.java
===================================================================
--- test/java/org/apache/jdo/tck/query/result/Unique.java (Revision 0)
+++ test/java/org/apache/jdo/tck/query/result/Unique.java (Revision 0)
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.result;
+
+import javax.jdo.Query;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.company.CompanyModelReader;
+import org.apache.jdo.tck.pc.company.Person;
+import org.apache.jdo.tck.query.QueryElementHolder;
+import org.apache.jdo.tck.query.QueryTest;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *Title: Unique.
+ *
+ *Keywords: query
+ *
+ *Assertion ID: A14.6.11-1.
+ *
+ *Assertion Description:
+ * When the value of the Unique flag is true,
+ * then the result of a query is a single value,
+ * with null used to indicate that none of the instances
+ * in the candidates satisfied the filter.
+ * If more than one instance satisfies the filter,
+ * and the range is not limited to one result,
+ * then execute throws a JDOUserException.
+ */
+public class Unique extends QueryTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.11-1 (Unique) 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*/ Boolean.TRUE,
+ /*RESULT*/ null,
+ /*INTO*/ null,
+ /*FROM*/ Person.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "personid == 1",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+ new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ null,
+ /*INTO*/ null,
+ /*FROM*/ Person.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "personid == 0",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+ new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ null,
+ /*INTO*/ null,
+ /*FROM*/ Person.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ "personid ASCENDING",
+ /*FROM*/ "0",
+ /*TO*/ "1"),
+ };
+
+ /** The expected results of valid queries. */
+ private static String[][] expectedResult = {
+ {"emp1"},
+ {null},
+ {"emp1"}
+ };
+
+ /**
+ * The main is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(Unique.class);
+ }
+
+ /** */
+ public void testPositive() {
+ for (int i = 0; i < VALID_QUERIES.length; i++) {
+ Object[] expectedResultValues =
+ getCompanyModelInstances(expectedResult[i]);
+ executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i],
+ expectedResultValues);
+ executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i],
+ expectedResultValues);
+ }
+ }
+
+ public void testNegative() {
+ String singleString = "SELECT UNIQUE FROM " + Person.class.getName();
+
+ Query query = getPM().newQuery(Person.class);
+ query.setUnique(true);
+ execute(ASSERTION_FAILED, query, singleString, true, false, null, null);
+
+ query = getPM().newQuery(singleString);
+ execute(ASSERTION_FAILED, query, singleString, true, false, null, null);
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ loadCompanyModel(getPM(), COMPANY_TESTDATA);
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ }
+}
Index: test/java/org/apache/jdo/tck/query/result/NPEInResultExpr.java
===================================================================
--- test/java/org/apache/jdo/tck/query/result/NPEInResultExpr.java (Revision 0)
+++ test/java/org/apache/jdo/tck/query/result/NPEInResultExpr.java (Revision 0)
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.result;
+
+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;
+
+/**
+ *Title: NullPointerException in Result Expression.
+ *
+ *Keywords: query
+ *
+ *Assertion ID: A14.6.9-4.
+ *
+ *Assertion Description:
+ * If any result is a navigational expression,
+ * and a non-terminal field or variable has a null value for a particular set
+ * of conditions (the result calculation would throw NullPointerException),
+ * then the result is null for that result expression.
+ */
+public class NPEInResultExpr extends QueryTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.9-4 (NPEInResultExpr) 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*/ "manager.lastname",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "employee.manager.lastname",
+ /*INTO*/ null,
+ /*FROM*/ Department.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "employees.contains(employee)",
+ /*VARIABLES*/ "Employee employee",
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null)
+ };
+
+ /** The expected results of valid queries. */
+ private static Object[][] expectedResult = {
+ //Note: None of the entries below are bean names!
+ {"emp2Last", null, "emp2Last", "emp2Last", "emp2Last"},
+ {"emp2Last", null, "emp2Last", "emp2Last", "emp2Last"}
+ };
+
+ /**
+ * The main is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(NPEInResultExpr.class);
+ }
+
+ /** */
+ public void testPositive() {
+ for (int i = 0; i < VALID_QUERIES.length; i++) {
+ Object[] expectedResultValues =
+ expectedResult[i] instanceof String[] ?
+ getCompanyModelInstances((String[])expectedResult[i]) :
+ expectedResult[i];
+ executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i],
+ expectedResultValues);
+ executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i],
+ expectedResultValues);
+ }
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ loadCompanyModel(getPM(), COMPANY_TESTDATA);
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ }
+}
Index: test/java/org/apache/jdo/tck/query/result/DistinctQuery.java
===================================================================
--- test/java/org/apache/jdo/tck/query/result/DistinctQuery.java (Revision 0)
+++ test/java/org/apache/jdo/tck/query/result/DistinctQuery.java (Revision 0)
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.result;
+
+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;
+
+/**
+ *Title: Disctinct Query.
+ *
+ *Keywords: query
+ *
+ *Assertion ID: A14.6.9-1.
+ *
+ *Assertion Description:
+ * If distinct is specified, the query result does not include any duplicates.
+ * If the result parameter specifies more than one result expression,
+ * duplicates are those with matching values for each result expression.
+ */
+public class DistinctQuery extends QueryTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.9-1 (DistinctQuery) 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*/ "department",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "DISTINCT department",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "department.deptid, department.name",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "DISTINCT department.deptid, department.name",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null)
+ };
+
+ /** The expected results of valid queries. */
+ private static Object[][] expectedResult = {
+ new String[]{"dept1", "dept1", "dept1", "dept2", "dept2"},
+ new String[]{"dept1", "dept2"},
+ {new Object[]{new Long(1),"Development"},
+ new Object[]{new Long(1),"Development"},
+ new Object[]{new Long(1),"Development"},
+ new Object[]{new Long(2),"Human Resources"},
+ new Object[]{new Long(2),"Human Resources"}},
+ {new Object[]{new Long(1),"Development"},
+ new Object[]{new Long(2),"Human Resources"}}
+ };
+
+ /**
+ * The main is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(DistinctQuery.class);
+ }
+
+ /** */
+ public void testPositive() {
+ for (int i = 0; i < VALID_QUERIES.length; i++) {
+ Object[] expectedResultValues =
+ expectedResult[i] instanceof String[] ?
+ getCompanyModelInstances((String[])expectedResult[i]) :
+ expectedResult[i];
+ executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i],
+ expectedResultValues);
+ executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i],
+ expectedResultValues);
+ }
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ loadCompanyModel(getPM(), COMPANY_TESTDATA);
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ }
+}
Index: test/java/org/apache/jdo/tck/query/result/ResultClassRequirements.java
===================================================================
--- test/java/org/apache/jdo/tck/query/result/ResultClassRequirements.java (Revision 0)
+++ test/java/org/apache/jdo/tck/query/result/ResultClassRequirements.java (Revision 0)
@@ -0,0 +1,460 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.result;
+
+import java.math.BigDecimal;
+import java.util.Map;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.company.CompanyModelReader;
+import org.apache.jdo.tck.pc.company.FullTimeEmployee;
+import org.apache.jdo.tck.pc.company.Project;
+import org.apache.jdo.tck.query.QueryElementHolder;
+import org.apache.jdo.tck.query.QueryTest;
+import org.apache.jdo.tck.query.result.classes.LongString;
+import org.apache.jdo.tck.query.result.classes.NoArgsConstructor;
+import org.apache.jdo.tck.query.result.classes.NoFieldsNoMethods;
+import org.apache.jdo.tck.query.result.classes.PublicLongField;
+import org.apache.jdo.tck.query.result.classes.PublicPutMethod;
+import org.apache.jdo.tck.util.BatchTestRunner;
+import org.apache.jdo.tck.util.ConversionHelper;
+
+/**
+ *Title: Result Class Requirements.
+ *
+ *Keywords: query
+ *
+ *Assertion ID: A14.6.12-1.
+ *
+ *Assertion Description:
+ * The result class may be one of the java.lang classes ...
+ */
+public class ResultClassRequirements extends QueryTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.12-1 (ResultClassRequirements) failed: ";
+
+ /**
+ * The array of valid queries which may be executed as
+ * single string queries and as API queries.
+ */
+ private static final QueryElementHolder[] VALID_QUERIES = {
+ // Long
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "personid",
+ /*INTO*/ Long.class,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // Double
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "salary",
+ /*INTO*/ Double.class,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // BigDecimal
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "budget",
+ /*INTO*/ BigDecimal.class,
+ /*FROM*/ Project.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // java.util.Date
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "hiredate",
+ /*INTO*/ java.util.Date.class,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // Map
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "phoneNumbers",
+ /*INTO*/ Map.class,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // user defined result class
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "personid AS l, lastname AS s",
+ /*INTO*/ LongString.class,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // constructor
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "new StringIntResult(personid, lastname)",
+ /*INTO*/ LongString.class,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // public fields
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "personid AS l",
+ /*INTO*/ PublicLongField.class,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // public put method
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "personid, lastname",
+ /*INTO*/ PublicPutMethod.class,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null)
+ };
+
+ /**
+ * The array of invalid queries which may be executed as
+ * single string queries and as API queries.
+ */
+ private static final QueryElementHolder[] INVALID_QUERIES = {
+ // TCK class, invalid property
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "personid, lastname",
+ /*INTO*/ LongString.class,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // JDK class
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "personid, lastname",
+ /*INTO*/ Long.class,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // JDK class, non assignment compatible
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "lastname",
+ /*INTO*/ Long.class,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // TCK class, non assignment compatible
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "personid AS l, salary AS s",
+ /*INTO*/ LongString.class,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // TCK class, non existing constructor
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "new LongString(personid)",
+ /*INTO*/ LongString.class,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // TCK class, no no-args constructor
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "personid",
+ /*INTO*/ NoArgsConstructor.class,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // TCK class, no no-args constructor
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "personid",
+ /*INTO*/ NoFieldsNoMethods.class,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+ };
+
+ // Two dimensional arrays to be converted to maps
+ // in the expected result.
+ private static Object[][] phoneNumbers1 =
+ {{"home", "1111"},
+ {"work", "123456-1"}};
+ private static Object[][] phoneNumbers2 =
+ {{"home", "2222"},
+ {"work", "123456-2"}};
+ private static Object[][] phoneNumbers5 =
+ {{"home", "3363"},
+ {"work", "126456-3"}};
+ private static Object[][] publicPutMethod1 =
+ {{"personid", new Long(1)}, {"lastname", "emp1Last"}};
+ private static Object[][] publicPutMethod2 =
+ {{"personid", new Long(2)}, {"lastname", "emp2Last"}};
+ private static Object[][] publicPutMethod5 =
+ {{"personid", new Long(5)}, {"lastname", "emp5Last"}};
+
+ /** The expected results of valid queries. */
+ private static Object[][] expectedResult = {
+ // Long
+ {new Long(1), new Long(2), new Long(5)},
+ // Double
+ {new Double(20000.0), new Double(10000.0), new Double(45000.0)},
+ // BigDecimal
+ {new BigDecimal("2500000.99"), new BigDecimal("50000.00"),
+ new BigDecimal("2000.99")},
+ // java.util.Date
+ {CompanyModelReader.stringToUtilDate("1/Jan/1999"),
+ CompanyModelReader.stringToUtilDate("1/Jul/2003"),
+ CompanyModelReader.stringToUtilDate("15/Aug/1998")},
+ // Map
+ {ConversionHelper.arrayToMap(phoneNumbers1),
+ ConversionHelper.arrayToMap(phoneNumbers2),
+ ConversionHelper.arrayToMap(phoneNumbers5)},
+ // LongString
+ {new LongString(1, "emp1Last"), new LongString(2, "emp2Last"),
+ new LongString(5, "emp5Last")},
+ // LongString constructor
+ {new LongString(1, "emp1Last"), new LongString(2, "emp2Last"),
+ new LongString(5, "emp5Last")},
+ // public fields
+ {new PublicLongField(1), new PublicLongField(2), new PublicLongField(5)},
+ // public put method
+ {new PublicPutMethod(ConversionHelper.arrayToMap(publicPutMethod1)),
+ new PublicPutMethod(ConversionHelper.arrayToMap(publicPutMethod2)),
+ new PublicPutMethod(ConversionHelper.arrayToMap(publicPutMethod5))}
+ };
+
+ /**
+ * The main is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(ResultClassRequirements.class);
+ }
+
+ /** */
+ public void testLong() {
+ int index = 0;
+ executeQuery(index);
+ }
+
+ /** */
+ public void testDouble() {
+ int index = 1;
+ executeQuery(index);
+ }
+
+ /** */
+ public void testBigDecimal() {
+ int index = 2;
+ executeQuery(index);
+ }
+
+ /** */
+ public void testDate() {
+ int index = 3;
+ executeQuery(index);
+ }
+
+ /** */
+ public void testMap() {
+ int index = 4;
+ executeQuery(index);
+ }
+
+ /** */
+ public void testUserDefinedResultClass() {
+ int index = 5;
+ executeQuery(index);
+ }
+
+ /** */
+ public void testConstructor() {
+ int index = 6;
+ executeQuery(index);
+ }
+
+ /** */
+ public void testFields() {
+ int index = 7;
+ executeQuery(index);
+ }
+
+ /** */
+ public void testPut() {
+ int index = 8;
+ executeQuery(index);
+ }
+
+ /** */
+ public void testNegative() {
+ for (int i = 0; i < INVALID_QUERIES.length; i++) {
+ compileAPIQuery(ASSERTION_FAILED, INVALID_QUERIES[i], false);
+ compileSingleStringQuery(ASSERTION_FAILED, INVALID_QUERIES[i],
+ false);
+ }
+ }
+
+ /** */
+ private void executeQuery(int index) {
+ Object[] expectedResultValues =
+ expectedResult[index] instanceof String[] ?
+ getCompanyModelInstances((String[])expectedResult[index]) :
+ expectedResult[index];
+ executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index],
+ expectedResultValues);
+ executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index],
+ expectedResultValues);
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ loadCompanyModel(getPM(), COMPANY_TESTDATA);
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ }
+}
Index: test/java/org/apache/jdo/tck/query/result/VariableInResult.java
===================================================================
--- test/java/org/apache/jdo/tck/query/result/VariableInResult.java (Revision 0)
+++ test/java/org/apache/jdo/tck/query/result/VariableInResult.java (Revision 0)
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.result;
+
+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;
+
+/**
+ *Title: Variable in Result.
+ *
+ *Keywords: query
+ *
+ *Assertion ID: A14.6.9-3.
+ *
+ *Assertion Description:
+ * If a variable or a field of a variable is included in the result,
+ * either directly or via navigation through the variable,
+ * then the semantics of the contains clause that include the variable change.
+ * In this case, all values of the variable
+ * that satisfy the filter are included in the result.
+ */
+public class VariableInResult extends QueryTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.9-3 (VariableInResult) 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*/ "project",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "projects.contains(project) & project.name == 'orange'",
+ /*VARIABLES*/ "Project project",
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "project.projid, project.name",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "projects.contains(project) & project.name == 'orange'",
+ /*VARIABLES*/ "Project project",
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null)
+ };
+
+ /** The expected results of valid queries. */
+ private static Object[][] expectedResult = {
+ new String[]{"proj1"},
+ {new Object[]{new Long(1), "orange"}}
+ };
+
+ /**
+ * The main is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(VariableInResult.class);
+ }
+
+ /** */
+ public void testPositive() {
+ for (int i = 0; i < VALID_QUERIES.length; i++) {
+ Object[] expectedResultValues =
+ expectedResult[i] instanceof String[] ?
+ getCompanyModelInstances((String[])expectedResult[i]) :
+ expectedResult[i];
+ executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i],
+ expectedResultValues);
+ executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i],
+ expectedResultValues);
+ }
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ loadCompanyModel(getPM(), COMPANY_TESTDATA);
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ }
+}
Index: test/java/org/apache/jdo/tck/query/result/DefaultUnique.java
===================================================================
--- test/java/org/apache/jdo/tck/query/result/DefaultUnique.java (Revision 0)
+++ test/java/org/apache/jdo/tck/query/result/DefaultUnique.java (Revision 0)
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.result;
+
+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;
+
+/**
+ *Title: Default Unique.
+ *
+ *Keywords: query
+ *
+ *Assertion ID: A14.6.11-2.
+ *
+ *Assertion Description:
+ * The default Unique setting is true for aggregate results
+ * without a grouping expression, and false otherwise.
+ */
+public class DefaultUnique extends QueryTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.11-2 (DefaultUnique) 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*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "COUNT(department)",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "COUNT(department)",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ "department",
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null)
+ };
+
+ /** The expected results of valid queries. */
+ private static Object[][] expectedResult = {
+ new String[]{"emp1", "emp2", "emp3", "emp4", "emp5"},
+ new Object[]{new Long(5)},
+ new Object[]{new Long(3), new Long(2)}
+ };
+
+ /**
+ * The main is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(DefaultUnique.class);
+ }
+
+ /** */
+ public void testPositive() {
+ for (int i = 0; i < VALID_QUERIES.length; i++) {
+ Object[] expectedResultValues =
+ expectedResult[i] instanceof String[] ?
+ getCompanyModelInstances((String[])expectedResult[i]) :
+ expectedResult[i];
+ executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i],
+ expectedResultValues);
+ executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i],
+ expectedResultValues);
+ }
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ loadCompanyModel(getPM(), COMPANY_TESTDATA);
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ }
+}
Index: test/java/org/apache/jdo/tck/query/result/Having.java
===================================================================
--- test/java/org/apache/jdo/tck/query/result/Having.java (Revision 0)
+++ test/java/org/apache/jdo/tck/query/result/Having.java (Revision 0)
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.result;
+
+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;
+
+/**
+ *Title: Having.
+ *
+ *Keywords: query
+ *
+ *Assertion ID: A14.6.10-2.
+ *
+ *Assertion Description:
+ * When having is specified, the having expression consists of
+ * arithmetic and boolean expressions containing aggregate expressions.
+ */
+public class Having extends QueryTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.10-2 (Having) 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*/ "department, SUM(salary)",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ "department HAVING COUNT(department.employees) > 0",
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null)
+ };
+
+ /**
+ * The array of invalid queries which may be executed as
+ * single string queries and as API queries.
+ */
+ private static final QueryElementHolder[] INVALID_QUERIES = {
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "department, SUM(salary)",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ "department HAVING firstname == 'emp1First'",
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null)
+ };
+
+ /**
+ * The main is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(Having.class);
+ }
+
+ /** */
+ public void testPositive() {
+ // prepare expected result
+ Object[] departments =
+ getCompanyModelInstances(new String[] {"dept1", "dept2"});
+ Object[] expectedResult = new Object[]
+ {new Object[]{departments[0], new Double(45000.0)},
+ new Object[]{departments[1], new Double(58000.0)}};
+
+ // execute queries
+ for (int i = 0; i < VALID_QUERIES.length; i++) {
+ executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i],
+ expectedResult);
+ executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i],
+ expectedResult);
+ }
+ }
+
+ /** */
+ public void testNegative() {
+ for (int i = 0; i < INVALID_QUERIES.length; i++) {
+ compileAPIQuery(ASSERTION_FAILED, INVALID_QUERIES[i], false);
+ compileSingleStringQuery(ASSERTION_FAILED, INVALID_QUERIES[i],
+ false);
+ }
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ loadCompanyModel(getPM(), COMPANY_TESTDATA);
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ }
+}
Index: test/java/org/apache/jdo/tck/query/result/classes/NoArgsConstructor.java
===================================================================
--- test/java/org/apache/jdo/tck/query/result/classes/NoArgsConstructor.java (Revision 0)
+++ test/java/org/apache/jdo/tck/query/result/classes/NoArgsConstructor.java (Revision 0)
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.result.classes;
+
+
+/**
+ * JDOQL result class not having an no-args constructor.
+ */
+public class NoArgsConstructor {
+
+ private long l;
+
+ public NoArgsConstructor(int l) {
+ this.l = l;
+ }
+
+ /**
+ * @see Object#hashCode()
+ */
+ public int hashCode() {
+ int result = 0;
+ result += (int) (this.l % Integer.MAX_VALUE);
+ return result;
+ }
+
+ /**
+ * @see Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object o) {
+ if (!(o instanceof NoArgsConstructor))
+ return false;
+ NoArgsConstructor other = (NoArgsConstructor) o;
+ return this.l == other.l;
+ }
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString() {
+ return getClass().getName() + '(';
+ }
+
+ /**
+ * @return Returns the l.
+ */
+ public long getL() {
+ return l;
+ }
+
+ /**
+ * @param l The l to set.
+ */
+ public void setL(int l) {
+ this.l = l;
+ }
+}
Index: test/java/org/apache/jdo/tck/query/result/classes/PublicLongField.java
===================================================================
--- test/java/org/apache/jdo/tck/query/result/classes/PublicLongField.java (Revision 0)
+++ test/java/org/apache/jdo/tck/query/result/classes/PublicLongField.java (Revision 0)
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.result.classes;
+
+/**
+ * JDOQL result class having a public lonf field.
+ */
+public class PublicLongField {
+
+ public long l;
+
+ public PublicLongField() {}
+
+ public PublicLongField(long l) {
+ this.l = l;
+ }
+ /**
+ * @see Object#hashCode()
+ */
+ public int hashCode() {
+ return (int) (this.l % Integer.MAX_VALUE);
+ }
+
+ /**
+ * @see Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object o) {
+ if (!(o instanceof PublicLongField))
+ return false;
+ PublicLongField other = (PublicLongField) o;
+ return this.l == other.l;
+ }
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString() {
+ return getClass().getName() + '(' + this.l + ')';
+ }
+
+}
Index: test/java/org/apache/jdo/tck/query/result/classes/FullName.java
===================================================================
--- test/java/org/apache/jdo/tck/query/result/classes/FullName.java (Revision 332256)
+++ test/java/org/apache/jdo/tck/query/result/classes/FullName.java (Arbeitskopie)
@@ -16,6 +16,8 @@
package org.apache.jdo.tck.query.result.classes;
+import org.apache.jdo.tck.util.EqualityHelper;
+
/**
* JDOQL result class having bean properties firstname,
* firstName, lastname, and lastName.
@@ -51,15 +53,11 @@
* @see Object#equals(java.lang.Object)
*/
public boolean equals(Object o) {
+ if (!(o instanceof FullName))
+ return false;
FullName other = (FullName) o;
- if (this.firstName == null) {
- return other.firstName == null;
- }
- if (this.lastName == null) {
- return other.lastName == null;
- }
- return this.firstName.equals(other.firstName) &&
- this.lastName.equals(other.lastName);
+ return EqualityHelper.equals(this.firstName, other.firstName) &&
+ EqualityHelper.equals(this.lastName, other.lastName);
}
/**
Index: test/java/org/apache/jdo/tck/query/result/classes/NoFieldsNoMethods.java
===================================================================
--- test/java/org/apache/jdo/tck/query/result/classes/NoFieldsNoMethods.java (Revision 0)
+++ test/java/org/apache/jdo/tck/query/result/classes/NoFieldsNoMethods.java (Revision 0)
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.result.classes;
+
+
+/**
+ * JDOQL result class not having an no-args constructor.
+ */
+public class NoFieldsNoMethods {
+}
Index: test/java/org/apache/jdo/tck/query/result/classes/LongString.java
===================================================================
--- test/java/org/apache/jdo/tck/query/result/classes/LongString.java (Revision 0)
+++ test/java/org/apache/jdo/tck/query/result/classes/LongString.java (Revision 0)
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.result.classes;
+
+import org.apache.jdo.tck.util.EqualityHelper;
+
+/**
+ * JDOQL result class having bean properties s and l.
+ * These properties are used by JDO query tests in result clauses.
+ */
+public class LongString {
+
+ private long l;
+ private String s;
+
+ public LongString() {}
+
+ public LongString(int l, String s) {
+ this.l = l;
+ this.s = s;
+ }
+
+ /**
+ * @see Object#hashCode()
+ */
+ public int hashCode() {
+ int result = 0;
+ result += this.s != null ? this.s.hashCode() : 0;
+ result += (int) (this.l % Integer.MAX_VALUE);
+ return result;
+ }
+
+ /**
+ * @see Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object o) {
+ if (!(o instanceof LongString))
+ return false;
+ LongString other = (LongString) o;
+ return this.l == other.l &&
+ EqualityHelper.equals(this.s, other.s);
+ }
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString() {
+ return getClass().getName() + '(' +
+ this.l + ", " + this.s + ')';
+ }
+
+ /**
+ * @return Returns the l.
+ */
+ public long getL() {
+ return l;
+ }
+
+ /**
+ * @param l The l to set.
+ */
+ public void setL(int l) {
+ this.l = l;
+ }
+
+ /**
+ * @return Returns the s.
+ */
+ public String getS() {
+ return s;
+ }
+
+ /**
+ * @param s The s to set.
+ */
+ public void setS(String s) {
+ this.s = s;
+ }
+
+}
Index: test/java/org/apache/jdo/tck/query/result/classes/PublicPutMethod.java
===================================================================
--- test/java/org/apache/jdo/tck/query/result/classes/PublicPutMethod.java (Revision 0)
+++ test/java/org/apache/jdo/tck/query/result/classes/PublicPutMethod.java (Revision 0)
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.result.classes;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * JDOQL result class having a public lonf field.
+ */
+public class PublicPutMethod {
+
+ private Map map = new HashMap();
+
+ public PublicPutMethod() {}
+
+ public PublicPutMethod(Map map) {
+ this.map = map;
+ }
+
+ public void put(Object key, Object value) {
+ this.map.put(key, value);
+ }
+
+ /**
+ * @see Object#hashCode()
+ */
+ public int hashCode() {
+ return this.map.hashCode();
+ }
+
+ /**
+ * @see Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object o) {
+ if (!(o instanceof PublicPutMethod))
+ return false;
+ PublicPutMethod other = (PublicPutMethod) o;
+ return this.map.equals(other.map);
+ }
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString() {
+ return getClass().getName() + '(' + this.map + ')';
+ }
+
+}
Index: test/java/org/apache/jdo/tck/query/result/ResultExpressions.java
===================================================================
--- test/java/org/apache/jdo/tck/query/result/ResultExpressions.java (Revision 0)
+++ test/java/org/apache/jdo/tck/query/result/ResultExpressions.java (Revision 0)
@@ -0,0 +1,504 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.result;
+
+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.Person;
+import org.apache.jdo.tck.query.QueryElementHolder;
+import org.apache.jdo.tck.query.QueryTest;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *Title: Result Expressions.
+ *
+ *Keywords: query
+ *
+ *Assertion ID: A14.6.9-5.
+ *
+ *Assertion Description:
+ * The result expressions include: ...
+ * The result expression can be explicitly cast using the (cast) operator.
+ */
+public class ResultExpressions extends QueryTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.9-5 (ResultExpressions) failed: ";
+
+ /**
+ * The array of valid queries which may be executed as
+ * single string queries and as API queries.
+ */
+ private static final QueryElementHolder[] VALID_QUERIES = {
+ // this
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "this",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // field
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "personid",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // variable.field
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "project.projid",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "projects.contains(project) && personid == 1",
+ /*VARIABLES*/ "Project project",
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // variable
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "project",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "projects.contains(project) && personid == 1",
+ /*VARIABLES*/ "Project project",
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // COUNT(this)
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "COUNT(this)",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // COUNT(variable)
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "COUNT(project)",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "projects.contains(project) && personid == 1",
+ /*VARIABLES*/ "Project project",
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // SUM
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "SUM(personid)",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // MIN
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "MIN(personid)",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // MAX
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "MAX(personid)",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // AVG
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "AVG(personid)",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // field expression
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "personid + 1",
+ /*INTO*/ null,
+ /*FROM*/ Person.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // navigational expression this
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "this.personid",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // navigational expression variable
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "project.projid",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "projects.contains(project) && personid == 1",
+ /*VARIABLES*/ "Project project",
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // navigational expression parameter
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "project.projid",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "personid == 1",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ "Project project",
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // navigational expression field
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "department.deptid",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "personid == 1",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // parameter
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "project",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "personid == 1",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ "Project project",
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // cast
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "(FullTimeEmployee)manager",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "personid == 1",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null)
+ };
+
+ /** The expected results of valid queries. */
+ private static Object[][] expectedResult = {
+ // this
+ new String[]{"emp1", "emp2", "emp3", "emp4", "emp5"},
+ // field
+ {new Long(1), new Long(2), new Long(3), new Long(4), new Long(5)},
+ // variable.field
+ {new Long(1)},
+ // variable
+ new String[]{"proj1"},
+ // COUNT(this)
+ {new Long(5)},
+ // COUNT(variable)
+ {new Long(1)},
+ // SUM
+ {new Long(1+2+3+4+5)},
+ // MIN
+ {new Long(1)},
+ // MAX
+ {new Long(5)},
+ // AVG
+ {new Long(3)},
+ // field expression
+ {new Long(2), new Long(3), new Long(4), new Long(5), new Long(6)},
+ // navigational expression this
+ {new Long(1), new Long(2), new Long(3), new Long(4), new Long(5)},
+ // navigational expression variable
+ {new Long(1)},
+ // navigational expression parameter
+ {new Long(1)},
+ // navigational expression field
+ {new Long(1)},
+ // parameter
+ new String[]{"proj1"},
+ // cast
+ new String[]{"emp2"}
+ };
+
+ /**
+ * The main is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(ResultExpressions.class);
+ }
+
+ /** */
+ public void testThis() {
+ int index = 0;
+ executeQuery(index);
+ }
+
+ /** */
+ public void testField() {
+ int index = 1;
+ executeQuery(index);
+ }
+
+ /** */
+ public void testVariableField() {
+ int index = 2;
+ executeQuery(index);
+ }
+
+ /** */
+ public void testVariable() {
+ int index = 3;
+ executeQuery(index);
+ }
+
+ /** */
+ public void testCountThis() {
+ int index = 4;
+ executeQuery(index);
+ }
+
+ /** */
+ public void testCountVariable() {
+ int index = 5;
+ executeQuery(index);
+ }
+
+ /** */
+ public void testSum() {
+ int index = 6;
+ executeQuery(index);
+ }
+
+ /** */
+ public void testMin() {
+ int index = 7;
+ executeQuery(index);
+ }
+
+ /** */
+ public void testMax() {
+ int index = 8;
+ executeQuery(index);
+ }
+
+ /** */
+ public void testAvg() {
+ int index = 9;
+ executeQuery(index);
+ }
+
+ /** */
+ public void testFieldExpression() {
+ int index = 10;
+ executeQuery(index);
+ }
+
+ /** */
+ public void testNavigationalExpressionThis() {
+ int index = 11;
+ executeQuery(index);
+ }
+
+ /** */
+ public void testNavigationalExpressionVariable() {
+ int index = 12;
+ executeQuery(index);
+ }
+
+ /** */
+ public void testNavigationalExpressionParameter() {
+ int index = 13;
+ Object[] parameters = getCompanyModelInstances(new String[]{"proj1"});
+ executeQuery(index, parameters);
+ }
+
+ /** */
+ public void testNavigationalExpressionField() {
+ int index = 14;
+ executeQuery(index);
+ }
+
+ /** */
+ public void testParameter() {
+ int index = 15;
+ Object[] parameters = getCompanyModelInstances(new String[]{"proj1"});
+ executeQuery(index, parameters);
+ }
+
+ /** */
+ public void testCast() {
+ int index = 16;
+ executeQuery(index);
+ }
+
+ /** */
+ private void executeQuery(int index) {
+ Object[] expectedResultValues =
+ expectedResult[index] instanceof String[] ?
+ getCompanyModelInstances((String[])expectedResult[index]) :
+ expectedResult[index];
+ executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index],
+ expectedResultValues);
+ executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index],
+ expectedResultValues);
+ }
+
+ /** */
+ private void executeQuery(int index, Object[] parameters) {
+ Object[] expectedResultValues =
+ expectedResult[index] instanceof String[] ?
+ getCompanyModelInstances((String[])expectedResult[index]) :
+ expectedResult[index];
+ executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index],
+ parameters, expectedResultValues);
+ executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index],
+ parameters, expectedResultValues);
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ loadCompanyModel(getPM(), COMPANY_TESTDATA);
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ }
+}
Index: test/java/org/apache/jdo/tck/query/result/DefaultResult.java
===================================================================
--- test/java/org/apache/jdo/tck/query/result/DefaultResult.java (Revision 0)
+++ test/java/org/apache/jdo/tck/query/result/DefaultResult.java (Revision 0)
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.result;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.company.CompanyModelReader;
+import org.apache.jdo.tck.pc.company.Person;
+import org.apache.jdo.tck.query.QueryElementHolder;
+import org.apache.jdo.tck.query.QueryTest;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *Title: Default Result.
+ *
+ *Keywords: query
+ *
+ *Assertion ID: A14.6.9-8.
+ *
+ *Assertion Description:
+ * If not specified, the result defaults to distinct this as C.
+ */
+public class DefaultResult extends QueryTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.9-8 (DefaultResult) 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*/ Person.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*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", "emp2", "emp3", "emp4", "emp5"}
+ };
+
+ /**
+ * The main is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(DefaultResult.class);
+ }
+
+ /** */
+ public void testPositive() {
+ for (int i = 0; i < VALID_QUERIES.length; i++) {
+ Object[] expectedResultValues =
+ expectedResult[i] instanceof String[] ?
+ getCompanyModelInstances((String[])expectedResult[i]) :
+ expectedResult[i];
+ executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i],
+ expectedResultValues);
+ executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i],
+ expectedResultValues);
+ }
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ loadCompanyModel(getPM(), COMPANY_TESTDATA);
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ }
+}
Index: test/java/org/apache/jdo/tck/query/result/DistintCandidateInstances.java
===================================================================
--- test/java/org/apache/jdo/tck/query/result/DistintCandidateInstances.java (Revision 0)
+++ test/java/org/apache/jdo/tck/query/result/DistintCandidateInstances.java (Revision 0)
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.result;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.jdo.Query;
+
+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;
+
+/**
+ *Title: Disctinct Query.
+ *
+ *Keywords: query
+ *
+ *Assertion ID: A14.6.9-2.
+ *
+ *Assertion Description:
+ * Queries against an extent always consider only distinct candidate instances,
+ * regardless of whether distinct is specified.
+ * Queries against a collection might contain duplicate candidate instances;
+ * the distinct keyword removes duplicates from the candidate collection
+ * in this case.
+ */
+public class DistintCandidateInstances extends QueryTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.9-2 (DistintCandidateInstances) 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*/ null,
+ /*VARIABLES*/ "Project project",
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "DISTINCT",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ "Project project",
+ /*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", "emp2", "emp3", "emp4", "emp5"},
+ {"emp1", "emp2", "emp3", "emp4", "emp5"}
+ };
+
+ /**
+ * The main is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(DistintCandidateInstances.class);
+ }
+
+ /** */
+ public void testPositive() {
+ if (isUnconstrainedVariablesSupported()) {
+ for (int i = 0; i < VALID_QUERIES.length; i++) {
+ Object[] expectedResultValues =
+ expectedResult[i] instanceof String[] ?
+ getCompanyModelInstances((String[])expectedResult[i]) :
+ expectedResult[i];
+ executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i],
+ expectedResultValues);
+ executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i],
+ expectedResultValues);
+ }
+ }
+
+ Collection candidates = new ArrayList();
+ candidates.add(new Integer(1));
+ candidates.add(new Integer(1));
+ candidates.add(new Integer(2));
+ candidates.add(new Integer(2));
+ Query query = getPM().newQuery();
+ query.setCandidates(candidates);
+ execute(ASSERTION_FAILED, query, "Candidate collection without filter", false, false, null, candidates.toArray());
+
+ query.setResult("DISTINCT");
+ Collection distinctCandidates = new ArrayList(candidates);
+ distinctCandidates.remove(new Integer(1));
+ distinctCandidates.remove(new Integer(2));
+ execute(ASSERTION_FAILED, query, "Candidate collection without filter", false, false, null, distinctCandidates.toArray());
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ loadCompanyModel(getPM(), COMPANY_TESTDATA);
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ }
+}
Index: test/java/org/apache/jdo/tck/query/result/ShapeOfResult.java
===================================================================
--- test/java/org/apache/jdo/tck/query/result/ShapeOfResult.java (Revision 0)
+++ test/java/org/apache/jdo/tck/query/result/ShapeOfResult.java (Revision 0)
@@ -0,0 +1,272 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.result;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.company.CompanyModelReader;
+import org.apache.jdo.tck.pc.company.Person;
+import org.apache.jdo.tck.query.QueryElementHolder;
+import org.apache.jdo.tck.query.QueryTest;
+import org.apache.jdo.tck.query.result.classes.FullName;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *Title: Shape of Result.
+ *
+ *Keywords: query
+ *
+ *Assertion ID: A14.6.12-2.
+ *
+ *Assertion Description:
+ * Table 6: Shape of Result (C is the candidate class)
+ */
+public class ShapeOfResult extends QueryTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.12-2 (ShapeOfResult) failed: ";
+
+ /**
+ * The array of valid queries which may be executed as
+ * single string queries and as API queries.
+ */
+ private static final QueryElementHolder[] VALID_QUERIES = {
+ // result: null
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ null,
+ /*INTO*/ null,
+ /*FROM*/ Person.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // result: this AS C
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "this AS Person",
+ /*INTO*/ null,
+ /*FROM*/ Person.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // result: null, unique: true
+ new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ null,
+ /*INTO*/ null,
+ /*FROM*/ Person.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "personid == 1",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // result: this AS C, unique: true
+ new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "this AS Person",
+ /*INTO*/ null,
+ /*FROM*/ Person.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "personid == 1",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // result: expression of type T
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "firstname",
+ /*INTO*/ null,
+ /*FROM*/ Person.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // result: expression of type T, unique: true
+ new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "firstname",
+ /*INTO*/ null,
+ /*FROM*/ Person.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "personid == 1",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // result: multiple expressions of type T
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "firstname, lastname",
+ /*INTO*/ null,
+ /*FROM*/ Person.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // result: multiple expressions of type T, unique: true
+ new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "firstname, lastname",
+ /*INTO*/ null,
+ /*FROM*/ Person.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "personid == 1",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // result: multiple expressions of type T, result class
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "firstname, lastname",
+ /*INTO*/ FullName.class,
+ /*FROM*/ Person.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // result: multiple expressions of type T, result class, unique: true
+ new QueryElementHolder(
+ /*UNIQUE*/ Boolean.TRUE,
+ /*RESULT*/ "firstname, lastname",
+ /*INTO*/ FullName.class,
+ /*FROM*/ Person.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "personid == 1",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ };
+
+ /** The expected results of valid queries. */
+ private static Object[][] expectedResult = {
+ // result: null
+ new String[]{"emp1", "emp2", "emp3", "emp4", "emp5"},
+ // result: this AS C
+ new String[]{"emp1", "emp2", "emp3", "emp4", "emp5"},
+ // result: null, unique: true
+ new String[]{"emp1"},
+ // result: this AS C, unique: true
+ new String[]{"emp1"},
+ // result: expression of type T
+ {"emp1First", "emp2First", "emp3First", "emp4First", "emp5First"},
+ // result: expression of type T, unique: true
+ {"emp1First"},
+ // result: multiple expressions of type T
+ {new Object[]{"emp1First", "emp1Last"},
+ new Object[]{"emp2First", "emp2Last"},
+ new Object[]{"emp3First", "emp3Last"},
+ new Object[]{"emp4First", "emp4Last"},
+ new Object[]{"emp5First", "emp5Last"}},
+ // result: multiple expressions of type T, unique: true
+ {new Object[]{"emp1First", "emp1Last"}},
+ // result: multiple expressions of type T, result class
+ {new FullName("emp1First", "emp1Last"),
+ new FullName("emp2First", "emp2Last"),
+ new FullName("emp3First", "emp3Last"),
+ new FullName("emp4First", "emp4Last"),
+ new FullName("emp5First", "emp5Last")},
+ // result: multiple expressions of type T, result class, unique: true
+ {new FullName("emp1First", "emp1Last")}
+ };
+
+ /**
+ * The main is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(ShapeOfResult.class);
+ }
+
+ /** */
+ public void testPositive() {
+ for (int i = 0; i < VALID_QUERIES.length; i++) {
+ Object[] expectedResultValues =
+ expectedResult[i] instanceof String[] ?
+ getCompanyModelInstances((String[])expectedResult[i]) :
+ expectedResult[i];
+ executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i],
+ expectedResultValues);
+ executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i],
+ expectedResultValues);
+ }
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ loadCompanyModel(getPM(), COMPANY_TESTDATA);
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ }
+}
Index: test/java/org/apache/jdo/tck/query/result/AggregateResult.java
===================================================================
--- test/java/org/apache/jdo/tck/query/result/AggregateResult.java (Revision 0)
+++ test/java/org/apache/jdo/tck/query/result/AggregateResult.java (Revision 0)
@@ -0,0 +1,498 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.result;
+
+import java.math.BigDecimal;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.company.CompanyModelReader;
+import org.apache.jdo.tck.pc.company.DentalInsurance;
+import org.apache.jdo.tck.pc.company.FullTimeEmployee;
+import org.apache.jdo.tck.pc.company.Person;
+import org.apache.jdo.tck.pc.company.Project;
+import org.apache.jdo.tck.query.QueryElementHolder;
+import org.apache.jdo.tck.query.QueryTest;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *Title: Aggregate Result.
+ *
+ *Keywords: query
+ *
+ *Assertion ID: A14.6.9-6.
+ *
+ *Assertion Description:
+ * Count returns Long. Sum returns Long for integral types and
+ * the field's type for other Number types
+ * (BigDecimal, BigInteger, Float, and Double).
+ * Sum is invalid if applied to non-Number types.
+ * Avg, min, and max return the type of the expression.
+ */
+public class AggregateResult extends QueryTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.9-6 (AggregateResult) failed: ";
+
+ /**
+ * The array of valid queries which may be executed as
+ * single string queries and as API queries.
+ */
+ private static final QueryElementHolder[] VALID_QUERIES = {
+ // COUNT
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "COUNT(this)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // COUNT
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "COUNT(this)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "personid == 0",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // COUNT
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "COUNT(manager)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // SUM(long)
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "SUM(personid)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // SUM(double)
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "SUM(salary)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // SUM(BigDecimal)
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "SUM(budget)",
+ /*INTO*/ null,
+ /*FROM*/ Project.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // SUM
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "SUM(budget)",
+ /*INTO*/ null,
+ /*FROM*/ Project.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "projid == 0",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // MIN(long)
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "MIN(personid)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // MIN(double)
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "MIN(salary)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // MIN(BigDecimal)
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "MIN(budget)",
+ /*INTO*/ null,
+ /*FROM*/ Project.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // MIN
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "MIN(budget)",
+ /*INTO*/ null,
+ /*FROM*/ Project.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "projid == 0",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // MAX(long)
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "MAX(personid)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // MAX(double)
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "MAX(salary)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // MAX(BigDecimal)
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "MAX(budget)",
+ /*INTO*/ null,
+ /*FROM*/ Project.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // MAX
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "MAX(budget)",
+ /*INTO*/ null,
+ /*FROM*/ Project.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "projid == 0",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // AVG(long)
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "AVG(personid)",
+ /*INTO*/ null,
+ /*FROM*/ Person.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // AVG(double)
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "AVG(salary)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // AVG(BigDecimal)
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "AVG(lifetimeOrthoBenefit)",
+ /*INTO*/ null,
+ /*FROM*/ DentalInsurance.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+
+ // AVG
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "AVG(lifetimeOrthoBenefit)",
+ /*INTO*/ null,
+ /*FROM*/ DentalInsurance.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "insid == 0",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null)
+
+ };
+
+ /**
+ * The array of invalid queries which may be executed as
+ * single string queries and as API queries.
+ */
+ private static final QueryElementHolder[] INVALID_QUERIES = {
+ // SUM
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "SUM(firstname)",
+ /*INTO*/ null,
+ /*FROM*/ FullTimeEmployee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null)
+ };
+
+ /** The expected results of valid queries. */
+ private static Object[][] expectedResult = {
+ // COUNT
+ {new Long(3)},
+ // COUNT
+ {new Long(0)},
+ // COUNT
+ {new Long(2)},
+ // SUM(long)
+ {new Long(1+2+5)},
+ // SUM(double)
+ {new Double(20000.0+10000.0+45000.0)},
+ // SUM(BigDecimal)
+ {new BigDecimal("2500000.99").add
+ (new BigDecimal("50000.00")).add(new BigDecimal("2000.99"))},
+ // SUM
+ {null},
+ // MIN(long)
+ {new Long(1)},
+ // MIN(double)
+ {new Double(10000.0)},
+ // MIN(BigDecimal)
+ {new BigDecimal("2000.99")},
+ // MIN
+ {null},
+ // MAX(long)
+ {new Long(5)},
+ // MAX(double)
+ {new Double(45000.0)},
+ // MAX(BigDecimal)
+ {new BigDecimal("2500000.99")},
+ // MAX
+ {null},
+ // AVG(long)
+ {new Long(3)},
+ // AVG(double)
+ {new Double(25000.0)},
+ // AVG(BigDecimal)
+ {new BigDecimal("99.999")},
+ // AVG
+ {null}
+ };
+
+ /**
+ * The main is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(AggregateResult.class);
+ }
+
+ /** */
+ public void testCount() {
+ for(int i = 0; i < 3; i++) {
+ executeQuery(i);
+ }
+ }
+
+ /** */
+ public void testSUM() {
+ for(int i = 3; i < 7; i++) {
+ executeQuery(i);
+ }
+ }
+
+ /** */
+ public void testMIN() {
+ for(int i = 7; i < 11; i++) {
+ executeQuery(i);
+ }
+ }
+
+ /** */
+ public void testMAX() {
+ for(int i = 11; i < 15; i++) {
+ executeQuery(i);
+ }
+ }
+
+ /** */
+ public void testAVG() {
+ for(int i = 15; i < 19; i++) {
+ executeQuery(i);
+ }
+ }
+
+ public void testNegative() {
+ for (int i = 0; i < INVALID_QUERIES.length; i++) {
+ compileAPIQuery(ASSERTION_FAILED, INVALID_QUERIES[i], false);
+ compileSingleStringQuery(ASSERTION_FAILED, INVALID_QUERIES[i],
+ false);
+ }
+ }
+
+ /** */
+ private void executeQuery(int index) {
+ Object[] expectedResultValues =
+ expectedResult[index] instanceof String[] ?
+ getCompanyModelInstances((String[])expectedResult[index]) :
+ expectedResult[index];
+ executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index],
+ expectedResultValues);
+ executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index],
+ expectedResultValues);
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ loadCompanyModel(getPM(), COMPANY_TESTDATA);
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ }
+}
Index: test/java/org/apache/jdo/tck/query/result/Grouping.java
===================================================================
--- test/java/org/apache/jdo/tck/query/result/Grouping.java (Revision 0)
+++ test/java/org/apache/jdo/tck/query/result/Grouping.java (Revision 0)
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.result;
+
+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;
+
+/**
+ *Title: Grouping.
+ *
+ *Keywords: query
+ *
+ *Assertion ID: A14.6.10-1.
+ *
+ *Assertion Description:
+ * When grouping is specified, each result expression must be one of:
+ * an expression contained in the grouping expression;
+ * or, an aggregate expression evaluated once per group.
+ * The query groups all elements where all expressions
+ * specified in setGrouping have the same values.
+ * The query result consists of one element per group.
+ */
+public class Grouping extends QueryTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.10-1 (Grouping) 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*/ "department, SUM(salary)",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ "department",
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null)
+ };
+
+ /**
+ * The array of invalid queries which may be executed as
+ * single string queries and as API queries.
+ */
+ private static final QueryElementHolder[] INVALID_QUERIES = {
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "department, salary",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ "department",
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null)
+ };
+
+ /**
+ * The main is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(Grouping.class);
+ }
+
+ /** */
+ public void testPositive() {
+ // prepare expected result
+ Object[] departments =
+ getCompanyModelInstances(new String[] {"dept1", "dept2"});
+ Object[] expectedResult = new Object[]
+ {new Object[]{departments[0], new Double(45000.0)},
+ new Object[]{departments[1], new Double(58000.0)}};
+
+ // execute queries
+ for (int i = 0; i < VALID_QUERIES.length; i++) {
+ executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i],
+ expectedResult);
+ executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i],
+ expectedResult);
+ }
+ }
+
+ /** */
+ public void testNegative() {
+ for (int i = 0; i < INVALID_QUERIES.length; i++) {
+ compileAPIQuery(ASSERTION_FAILED, INVALID_QUERIES[i], false);
+ compileSingleStringQuery(ASSERTION_FAILED, INVALID_QUERIES[i],
+ false);
+ }
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ loadCompanyModel(getPM(), COMPANY_TESTDATA);
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ }
+}
Index: test/java/org/apache/jdo/tck/query/result/NullResults.java
===================================================================
--- test/java/org/apache/jdo/tck/query/result/NullResults.java (Revision 0)
+++ test/java/org/apache/jdo/tck/query/result/NullResults.java (Revision 0)
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.query.result;
+
+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;
+
+/**
+ *Title: Null Results.
+ *
+ *Keywords: query
+ *
+ *Assertion ID: A14.6.9-7.
+ *
+ *Assertion Description:
+ * If the returned value from a query specifying a result is null,
+ * this indicates that the expression specified as the result was null.
+ */
+public class NullResults extends QueryTest {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A14.6.9-7 (NullResults) 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*/ Boolean.TRUE,
+ /*RESULT*/ "manager",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "lastname == 'emp2Last'",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "manager",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ "lastname == 'emp2Last'",
+ /*VARIABLES*/ null,
+ /*PARAMETERS*/ null,
+ /*IMPORTS*/ null,
+ /*GROUP BY*/ null,
+ /*ORDER BY*/ null,
+ /*FROM*/ null,
+ /*TO*/ null),
+ new QueryElementHolder(
+ /*UNIQUE*/ null,
+ /*RESULT*/ "DISTINCT manager",
+ /*INTO*/ null,
+ /*FROM*/ Employee.class,
+ /*EXCLUDE*/ null,
+ /*WHERE*/ null,
+ /*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 = {
+ {null},
+ {null},
+ {"emp2", null}
+ };
+
+ /**
+ * The main is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(NullResults.class);
+ }
+
+ /** */
+ public void testPositive() {
+ for (int i = 0; i < VALID_QUERIES.length; i++) {
+ Object[] expectedResultValues =
+ expectedResult[i] instanceof String[] ?
+ getCompanyModelInstances((String[])expectedResult[i]) :
+ expectedResult[i];
+ executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i],
+ expectedResultValues);
+ executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i],
+ expectedResultValues);
+ }
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ loadCompanyModel(getPM(), COMPANY_TESTDATA);
+ addTearDownClass(CompanyModelReader.getTearDownClasses());
+ }
+}
Index: test/java/org/apache/jdo/tck/util/ConversionHelper.java
===================================================================
--- test/java/org/apache/jdo/tck/util/ConversionHelper.java (Revision 0)
+++ test/java/org/apache/jdo/tck/util/ConversionHelper.java (Revision 0)
@@ -0,0 +1,160 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.util;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+import java.util.TimeZone;
+
+import javax.jdo.JDOFatalException;
+
+/**
+ * Provides consersion functionality.
+ */
+public class ConversionHelper {
+
+ /**
+ * Converts the given value to a {@link java.util.Date}.
+ * @param pattern the pattern
+ * @param timezone the timezone
+ * @param locale the locale
+ * @param value the value
+ * @return the date
+ * @throws JDOFatalException if the conversion fails
+ */
+ public static Date toUtilDate(String pattern,
+ String timezone, Locale locale, String value) {
+ SimpleDateFormat formatter = new SimpleDateFormat(pattern, Locale.US);
+ formatter.setTimeZone(TimeZone.getTimeZone(timezone));
+ try {
+ return formatter.parse(value);
+ } catch (ParseException e) {
+ throw new JDOFatalException("", e);
+ }
+ }
+
+ /**
+ * Converts the given array into a {@link Map}.
+ * The first dimension represents the map entries,
+ * the second dimension holds the keys and values, e.g.
+ * { {"key1", "value1"}, {"key2", {"value2"} }.
+ * @param array the array
+ * @return the map
+ */
+ public static Map arrayToMap(Object[][] array) {
+ Map map = new HashMap();
+ for (int i = 0; i < array.length; i++) {
+ map.put(array[i][0], array[i][1]);
+ }
+ return map;
+ }
+
+ /**
+ * Returns a collection containing all elements
+ * in the given collection.
+ * Recursively converts all elements of type Object[]
+ * in the given collection to collections
+ * in the returned collection.
+ * @param collection the collection
+ * @return the converted collection
+ */
+ public static Collection convertsElementsOfTypeObjectArray(Collection collection) {
+ Collection result = new ArrayList();
+ for (Iterator i = collection.iterator(); i.hasNext(); ) {
+ Object current = convertsElementsOfTypeObjectArray(i.next());
+ result.add(current);
+ }
+ return result;
+ }
+
+ /**
+ * Returns a map containing all entries
+ * in the given map.
+ * Recursively converts all entries having keys and/or values
+ * of type Object[] in the given map to collections
+ * in the returned map.
+ * @param map the map
+ * @return the converted map
+ */
+ public static Map convertsElementsOfTypeObjectArray(Map map) {
+ Map result = new HashMap();
+ for (Iterator i = map.entrySet().iterator(); i.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) i.next();
+ Object key = convertsElementsOfTypeObjectArray(entry.getKey());
+ Object value = convertsElementsOfTypeObjectArray(entry.getValue());
+ result.put(key, value);
+ }
+ return result;
+ }
+
+ /**
+ * Recursively converts all elements of type Object[]
+ * in the given array to collections.
+ * Finally, converts the given array to a collection
+ * and return it.
+ * @param array the array
+ * @return the collection
+ */
+ public static Object convertsElementsOfTypeObjectArray(Object object) {
+ Object result;
+ if (object instanceof Object[]) {
+ result = toCollection((Object[])object);
+ } else if (object instanceof Collection) {
+ result = convertsElementsOfTypeObjectArray((Collection)object);
+ } else if (object instanceof Map) {
+ result = convertsElementsOfTypeObjectArray((Map)object);
+ } else {
+ result = object;
+ }
+ return result;
+ }
+
+ /**
+ * Recursively converts all elements of type Object[]
+ * in the given array to collections.
+ * Finally, converts the given array to a collection
+ * and returns it.
+ * @param array the array
+ * @return the collection
+ */
+ public static Collection toCollection(Object[] array) {
+ for (int i = 0; i < array.length; i++ ) {
+ array[i] = convertsElementsOfTypeObjectArray(array[i]);
+ }
+ return Arrays.asList(array);
+ }
+
+ /**
+ * Converts the given array to a string array.
+ * @param array the object array
+ * @return the string array
+ */
+ public static String[] toStringArray(Object[] array) {
+ String[] result = new String[array.length];
+ System.arraycopy(array, 0, result, 0, result.length);
+ return result;
+ }
+
+}
Index: test/java/org/apache/jdo/tck/util/EqualityHelper.java
===================================================================
--- test/java/org/apache/jdo/tck/util/EqualityHelper.java (Revision 332256)
+++ test/java/org/apache/jdo/tck/util/EqualityHelper.java (Arbeitskopie)
@@ -746,6 +746,23 @@
return true;
}
+ /** Returns true if the specified objects are equal.
+ * This is a helper method checking for identical and null
+ * objects before delegating to the regular equals method.
+ * @param o1 one object to be tested for equality
+ * @param o2 the other object to be tested for equality
+ * @return true if the specified objects are equal.
+ */
+ public static boolean equals(Object o1, Object o2) {
+ if (o1 == o2) {
+ return true;
+ }
+ if (o1 == null || o2 == null) {
+ return false;
+ }
+ return o1.equals(o2);
+ }
+
// Methods to support "close enough" comparison
/** Returns true if the specified objects are close
Index: test/conf/alltests.conf
===================================================================
--- test/conf/alltests.conf (Revision 332256)
+++ test/conf/alltests.conf (Arbeitskopie)
@@ -376,7 +376,21 @@
org.apache.jdo.tck.query.jdoql.variables.VariablesAndFields \
org.apache.jdo.tck.query.jdoql.variables.VariablesWithoutExtent \
org.apache.jdo.tck.query.jdoql.variables.VariableDeclaredWithSameNameAsFieldOfCandidateClass \
+org.apache.jdo.tck.query.result.AggregateResult \
+org.apache.jdo.tck.query.result.DefaultResult \
+org.apache.jdo.tck.query.result.DefaultUnique \
+org.apache.jdo.tck.query.result.DistintCandidateInstances \
+org.apache.jdo.tck.query.result.DistinctQuery \
+org.apache.jdo.tck.query.result.Grouping \
+org.apache.jdo.tck.query.result.Having \
org.apache.jdo.tck.query.result.ImmutableQueryResult \
+org.apache.jdo.tck.query.result.NPEInResultExpr \
+org.apache.jdo.tck.query.result.NullResults \
+org.apache.jdo.tck.query.result.ResultClassRequirements \
+org.apache.jdo.tck.query.result.ResultExpressions \
+org.apache.jdo.tck.query.result.ShapeOfResult \
+org.apache.jdo.tck.query.result.Unique \
+org.apache.jdo.tck.query.result.VariableInResult \
org.apache.jdo.tck.transactions.AfterCompletionMethodCalledWhenCommitted \
org.apache.jdo.tck.transactions.AfterCompletionMethodCalledWhenRolledback \
org.apache.jdo.tck.transactions.AfterSetRollbackOnlyCommitFails \