TCK20: JDO2 Query Test Cases
JDOQL 2.0
JDO 2.0 adds the following methods to the Query API:
- setResult
- setGrouping
- setUnique
- setResultClass
- setRange
- setUnique
- setUnmodifiable
- isUnmodifiable
- setExtensions
- addExtension
JDO 2.0 extensions of the JDO query language JDOQL:
- Single string JDOQL
- Result specification
- Projections of fields and relationships
- One or more result expressions
- Distinct results
- Unique query result
- Default result class for one or more result expressions
- User defined result class
- Naming of result expressions
- Aggregate functions MIN, MAX, SUM, AVG, and COUNT
- Grouping of query result
- One or more grouing expressions
- Having clause
- New methods in Query filters:
- Map support: get(Object), containsKey(Object), containsValue(Object), isEmpty()
- Additional string methods: toLowerCase(), toUpperCase(), indexOf(String), indexOf(String, int), matches(String), substring(int), substring(int, int)
- Support for other methods: Math.abs(numeric), Math.sqrt(numeric), JDOHelper.getObjectId(Object)
- New operators %(modulo) and instanceof
- Support for implicit parameters
- Support for implicit variables
- Deletion by query
NewQueryTests New TCK Query Tests
Package names of all query test classes start with org.apache.jdo.query.
.
Package names of all pc classes start with org.apache.jdo.tck.pc.
.
Package names of all result classes start with org.apache.jdo.tck.query.result.classes.
.
Language Extensions
Keywords
Assertion |
JDOQL |
Testclass |
Comment |
A14.4-6: Keywords must not be used as package names, class names, parameter names, or variable names in queries. |
|
|
Negative test. |
|
|||
|
|||
|
|||
|
|||
|
|||
A14.4-7: Keywords are permitted as field names only if they are on the right side of the "." in field access expressions |
|
|
Positive and negative test. |
|
|||
A14.6.13-1: The String version of Query represents all query elements using a single string. The string contains the following structure: |
|
|
Positive test. |
A14.6.13-2: Keywords, identified above in bold, are either all upper-case or all lower-case. Keywords cannot be mixed case. |
|
|
Positive and negative test. |
|
|||
|
|||
|
New Operators
Assertion |
JDOQL |
Testclass |
Comment |
A14.6.2-40: modulo operator |
|
|
Positive test. |
A14.6.2-41: instanceof operator |
|
|
Positive test. |
New Supported Methods
Assertion |
JDOQL |
Testclass |
Comment |
A14.6.2-46: Supported Map methods:
|
|
|
Positive Test. |
|
|||
|
|||
A14.6.2-47: New supported String methods:
|
|||
|
|
Positive test. |
|
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
A14.6.2-48: Supported Math methods:
|
|
|
Positive test. |
|
|||
A14.6.2-49: Supported JDOHelper methods:
|
|
|
Positive test. |
Parameters
Assertion |
JDOQL |
Testclass |
Comment |
A14.6.3-2: Parameters must all be declared explicitly via |
|
|
Positive and negative test. |
|
|||
|
|||
A14.6.3-3: Parameters implicitly declared (in the result, filter, grouping, ordering, or range) are identified by prepending a ":" to the parameter everywhere it appears. All parameter types can be determined by one of the following techniques: |
|
|
Positive test. |
|
|||
|
|||
|
|||
|
|||
A14.6.13-3: If implicit parameters are used, their order of appearance in the query determines their order for binding to positional parameters for execution. |
|
|
Positive test. |
Variables
Assertion |
JDOQL |
Testclass |
Comment |
A14.6.5-1: ?? A variable that is not constrained with an explicit contains clause is constrained by the extent of the persistence capable class (including subclasses). |
|
|
Posistive test. |
A14.6.5-2: ?? If the class does not manage an |
|
|
Positive test. |
A14.6.5-3: All variables must be explicitly declared, or all variables must be implicitly declared. |
|
|
Positive and negative test. |
|
|||
|
|||
A14.6.5-4: Names are treated as variable names if they are explicitly declared via |
|
|
Positive test. |
|
|||
|
Other Language Changes
Assertion |
JDOQL |
Testclass |
Comment |
A14.6.2-42: There is no distinction made between character literals and |
|
|
Positive and negative test. |
|
|||
A14.6.2-43: Identifiers that are persistent field names or |
|
|
Positive test. |
|
|||
A14.6.8-1: |
|
|
Positive test. |
A14.6.8-2: If |
|
|
Positive test. |
A14.6.8-3: |
|
|
Positive test. |
Query API Extensions
Assertion |
JDOQL |
Testclass |
Comment |
A14.5-11: Construct a new query instance using the specified |
|
|
Positive test. |
A14.5-12: Construct a new query instance with the given candidate class from a named query. |
|
|
Positive test and negative test. |
|
|||
|
|||
|
|||
A14.5-13: If the named query is not found in already-loaded metadata, the query is searched for using an algorithm. Files containing metadata are examined in turn until the query is found. The order is based on the metadata search order for class metadata, but includes files named based on the query name. |
|
|
Positive test. |
A14.5-14: If the metadata is not found in the above, a |
|
|
Negative test. |
A14.5-15: The |
|
|
Positive test. |
A14.5-16: Named queries must be compilable. Attempts to get a named query that cannot be compiled result in |
|
|
Negative test. |
A14.6-21: This method retrieves the fetch plan associated with the |
|
|
Positive test. |
A14.6-16: |
|
|
Positive test and negative test. |
|
|||
A14.6-17: |
|
|
Positive test. |
A14.6-18: |
|
|
Positive test. |
A14.6-19: |
|
|
Positive test. |
A14.6-20: |
|
|
Positive test. |
A14.6-22: The |
|
|
Negative test. |
A14.6-23: The single string query is first parsed to yield the result, result class, filter, variable list, parameter list, import list, grouping, ordering, and range. Then, the values specified in APIs |
|
|
Positive test. |
A14.9-1: Some JDO vendors provide extensions to the query, and these extensions must be set in the query instance prior to execution. |
|
|
Positive test. |
Result Handling
Assertion |
JDOQL |
Testclass |
Comment |
|
A14.6.9-1: If |
|
|
Positive test. |
|
A14.6.9-2: Queries against an extent always consider only distinct candidate instances, regardless of whether |
|
|
Positive test. |
|
A14.6.9-3: 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. |
|
|
Positive test. |
|
|
||||
A14.6.9-4: If any result is a navigational expression, and a non-terminal field or variable has a |
|
|
Positive test. |
|
|
||||
A14.6.9-5: The result expressions include: ... The result expression can be explicitly cast using the (cast) operator. |
|
|
Positive test. |
|
A14.6.9-6: |
|
|
Positive and negative test. |
|
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
A14.6.9-7: If the returned value from a query specifying a result is |
|
|
Positive test. |
|
A14.6.9-8: If not specified, the result defaults to |
|
|
Positive test. |
|
A14.6.10-1: 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 |
|
|
Positive and negative test. |
|
|
||||
A14.6.10-2: When |
|
|
Positive and negative test. |
|
|
||||
A14.6.11-1: When the value of the |
|
|
Positive and negative test. |
|
|
||||
|
||||
A14.6.11-2: The default Unique setting is |
|
|
Positive test. |
|
|
||||
|
||||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="ed9d5f5c-d20e-40c2-a25e-47235ca02ea6"><ac:plain-text-body><![CDATA[ |
*A14.6.12-1:*The result class may be one of the
|
|
|
Positive and negative test. |
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
A14.6.12-2: Table 6: Shape of Result (C is the candidate class) |
|
|
Positive test. |
|
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
SQL Queries
Assertion |
JDOQL |
Testclass |
Comment |
A14.7-1: In this case, the factory method that takes the language string and Object is used: |
|
|
Positive test. |
A14.7-2: The only methods that can be used are |
|
|
Positive and negative test. |
|
|||
|
|||
|
|||
|
|||
A14.7-3: SQL queries can be defined without a candidate class. These queries can be found by name using the factory method |
|
|
Positive test. |
|
|||
A14.7-4: Table 7: Shape of Result of SQL Query |
|
|
Positive test and negative test. |
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
Deletion by Query
Assertion |
JDOQL |
Testclass |
Comment |
A14.8-1: These methods delete the instances of affected classes that pass the filter, and all dependent instances. Affected classes are the candidate class and its persistence-capable subclasses. |
|
|
Positive test. |
A14.8-2: The number of instances of affected classes that were deleted is returned. Embedded instances and dependent instances are not counted in the return value. |
|
|
Positive test. |
A14.8-3: Query elements |
|
|
Positive and negative test. |
|
|||
|
|||
|
|||
|
|||
|
|||
A14.8-4: Dirty instances of affected classes are first flushed to the datastore. Instances already in the cache when deleted via these methods or brought into the cache as a result of these methods undergo the life cycle transitions as if |
|
|
Positive test. |
Testcase Pattern
Positive test
A positive test expects that the query compiles and executes w/o exception and returns the expected result:
Query query = pm.newQuery(); ... // define query Object results = query.execute(...); // check query result List expected = new ArrayList(); expected.add(...); checkQueryResultWithoutOrder(assertion, results, expected);
Negative test
A negative test case uses an invalid JDOQL query and expects an exception to be thrown by compile or execute:
try { Query query = pm.newQuery(); ... // define query Object results = query.execute(); fail(ASSERTION_FAILED, text); } catch (JDOException e) { if (debug) logger.debug("Caught expected " + e); }