You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-commits@db.apache.org by cl...@apache.org on 2005/12/26 23:04:38 UTC
svn commit: r359106 - in /db/jdo/trunk/tck20/test:
java/org/apache/jdo/tck/query/api/GetFetchPlan.java
jdo/applicationidentity/org/apache/jdo/tck/pc/mylib/PCClass.jdo
jdo/datastoreidentity/org/apache/jdo/tck/pc/mylib/PCClass.jdo
Author: clr
Date: Mon Dec 26 14:04:34 2005
New Revision: 359106
URL: http://svn.apache.org/viewcvs?rev=359106&view=rev
Log:
JDO-220 updated test and metadata
Modified:
db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/api/GetFetchPlan.java
db/jdo/trunk/tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/mylib/PCClass.jdo
db/jdo/trunk/tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/mylib/PCClass.jdo
Modified: db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/api/GetFetchPlan.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/api/GetFetchPlan.java?rev=359106&r1=359105&r2=359106&view=diff
==============================================================================
--- db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/api/GetFetchPlan.java (original)
+++ db/jdo/trunk/tck20/test/java/org/apache/jdo/tck/query/api/GetFetchPlan.java Mon Dec 26 14:04:34 2005
@@ -45,7 +45,10 @@
/** */
private static final String ASSERTION_FAILED =
"Assertion A14.6-21 (FetchPan) failed: ";
-
+
+ private String FETCH_GROUP_1 = "fetchGroup1";
+ private String FETCH_GROUP_2 = "fetchGroup2";
+
/**
* The <code>main</code> is called when the class
* is directly executed from the command line.
@@ -54,16 +57,32 @@
public static void main(String[] args) {
BatchTestRunner.run(GetFetchPlan.class);
}
-
+
/** */
- public void testPositive() {
+ private Query createQuery() {
+ // initialize the PM with datastore transactions and no retain values
+ getPM().currentTransaction().setOptimistic(false);
+ getPM().currentTransaction().setRetainValues(false);
Query query = getPM().newQuery(PCClass.class, "number1 == param");
query.declareParameters("int param");
-
+ query.getFetchPlan().setGroup(FETCH_GROUP_1);
+ return query;
+ }
+
+ /** */
+ public void testFetchGroup1() {
+ // localSetUp closes the PM
+ Query query = createQuery();
checkSameFetchPlanInstances(query);
- checkDefaultFetchGroup(query);
+ checkFetchGroup1(query);
+ cleanupPM();
+ }
+
+ public void testFetchGroup2() {
+ // localSetUp closes the PM
+ Query query = createQuery();
checkFetchGroup2(query);
- checkDefaultFetchGroup(query);
+ checkFetchGroup1(query);
}
private void checkSameFetchPlanInstances(Query query) {
@@ -77,10 +96,15 @@
/**
* Checks if the given query loads fields
- * assigned to the default fetch group.
+ * assigned to fetchGroup1
* @param query the query
*/
- private void checkDefaultFetchGroup(Query query) {
+ private void checkFetchGroup1(Query query) {
+ FetchPlan fetchplan = query.getFetchPlan();
+ Collection fetchgroups = fetchplan.getGroups();
+ assertTrue("FetchPlan should include fetchGroup1 and not fetchGroup2",
+ fetchgroups.contains(FETCH_GROUP_1) &&
+ !fetchgroups.contains(FETCH_GROUP_2));
Transaction transaction = query.getPersistenceManager().
currentTransaction();
transaction.begin();
@@ -90,38 +114,39 @@
" instances, expected size is " + 1);
}
PCClass pcClass = (PCClass) result.iterator().next();
- if (pcClass.getTransientNumber1() != 10) {
- fail(ASSERTION_FAILED +
- "Field PCClass.number1 is in the " +
- "default fetch group and should have been loaded. " +
- "The jdoPostLoad() callback has copied the field value " +
- "to a transient field which has an unexpected value: " +
- pcClass.getTransientNumber1());
- }
- if (pcClass.getTransientNumber2() != 0) {
- fail(ASSERTION_FAILED +
- "Field PCClass.number2 is not in the " +
- "default fetch group and should not have been loaded. " +
- "The jdoPostLoad() callback has copied the field value " +
- "to a transient field which has an unexpected value: " +
- pcClass.getTransientNumber2());
- }
+ int transient1 = pcClass.getTransientNumber1();
+ int transient2 = pcClass.getTransientNumber2();
+ boolean field1loaded = transient1 == 10;
+ boolean field2loaded = transient2 == 10;
transaction.commit();
+
+ if (!field1loaded || field2loaded) {
+ fail(ASSERTION_FAILED +
+ "\nUnexpected: TransientNumber1 = " + transient1 +
+ ", and TransientNumber2 = " + transient2 + ".\n" +
+ "Field number1 loaded = " + field1loaded +
+ ", Field number2 loaded = " + field2loaded + ".\n" +
+ "With fetchGroup1 active, expect field number1 " +
+ " loaded and field number2 not loaded.");
+ }
}
/**
* Checks if the given query loads fields assigned
- * to the default fetch group plus fetch group "fetchGroup2".
+ * to "fetchGroup1" plus fetch group "fetchGroup2".
* For this purpose, the method temporarily adds fetch group "fetchGroup2"
* to the fetch plan of the given query instance.
- * That fetch group is assigned a different field
- * than the default fetch group.
+ * That fetch group loads field number2.
* Finally, that fetch group is removed from the fetch plan again.
* @param query the query
*/
private void checkFetchGroup2(Query query) {
- String fetchGoupName = "fetchGroup2";
- query.getFetchPlan().addGroup(fetchGoupName);
+ FetchPlan fetchplan = query.getFetchPlan();
+ fetchplan.addGroup(FETCH_GROUP_2);
+ Collection fetchgroups = fetchplan.getGroups();
+ assertTrue("FetchPlan should include fetchGroup1 and fetchGroup2",
+ fetchgroups.contains(FETCH_GROUP_1) &&
+ fetchgroups.contains(FETCH_GROUP_2));
try {
Transaction transaction = query.getPersistenceManager().
currentTransaction();
@@ -132,25 +157,23 @@
" instances, expected size is " + 1);
}
PCClass pcClass = (PCClass) result.iterator().next();
- if (pcClass.getTransientNumber1() != 20) {
- fail(ASSERTION_FAILED +
- "Field PCClass.number1 is in the " +
- "default fetch group and should have been loaded. " +
- "The jdoPostLoad() callback has copied the field value " +
- "to a transient field which has an unexpected value: " +
- pcClass.getTransientNumber1());
- }
- if (pcClass.getTransientNumber2() != 20) {
- fail(ASSERTION_FAILED +
- "Field PCClass.number1 is in " +
- "fetch group 2 and should have been loaded. " +
- "The jdoPostLoad() callback has copied the field value " +
- "to a transient field which has an unexpected value: " +
- pcClass.getTransientNumber2());
- }
+ int transient1 = pcClass.getTransientNumber1();
+ int transient2 = pcClass.getTransientNumber2();
+ boolean field1loaded = transient1 == 20;
+ boolean field2loaded = transient2 == 20;
transaction.commit();
+
+ if (!field1loaded || !field2loaded) {
+ fail(ASSERTION_FAILED +
+ "\nUnexpected: TransientNumber1 = " + transient1 +
+ ", and TransientNumber2 = " + transient2 + ".\n" +
+ "Field number1 loaded = " + field1loaded +
+ ", Field number2 loaded = " + field2loaded + ".\n" +
+ "With fetchGroup1 active, expect field number1" +
+ " loaded and field number2 loaded.");
+ }
} finally {
- query.getFetchPlan().removeGroup(fetchGoupName);
+ query.getFetchPlan().removeGroup(FETCH_GROUP_2);
}
}
@@ -160,5 +183,6 @@
protected void localSetUp() {
addTearDownClass(MylibReader.getTearDownClasses());
loadAndPersistMylib(getPM());
+ cleanupPM();
}
}
Modified: db/jdo/trunk/tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/mylib/PCClass.jdo
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/mylib/PCClass.jdo?rev=359106&r1=359105&r2=359106&view=diff
==============================================================================
--- db/jdo/trunk/tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/mylib/PCClass.jdo (original)
+++ db/jdo/trunk/tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/mylib/PCClass.jdo Mon Dec 26 14:04:34 2005
@@ -2,10 +2,6 @@
<!DOCTYPE jdo PUBLIC "-//Sun Microsystems, Inc.//DTD Java Data Objects Metadata 2.0//EN" "http://java.sun.com/dtd/jdo_2_0.dtd">
<jdo>
<package name="org.apache.jdo.tck.pc.mylib">
-
- <!-- This will not be required once the JDOModel is fixed so that
- the defaults defined in section 18.4 of the spec are working
- -->
<class name="PCClass"
identity-type="application" objectid-class="org.apache.jdo.tck.pc.mylib.PCClass$Oid">
<field name="id" primary-key="true"/>
@@ -14,14 +10,13 @@
<query name="classJDO">
SELECT FROM org.apache.jdo.tck.pc.mylib.PCClass
</query>
- <fetch-group name="default">
+ <fetch-group name="fetchGroup1" post-load="true">
<field name="number1"/>
</fetch-group>
- <fetch-group name="fetchGoup2" post-load="true">
+ <fetch-group name="fetchGroup2" post-load="true">
<field name="number2"/>
</fetch-group>
</class>
-
</package>
</jdo>
Modified: db/jdo/trunk/tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/mylib/PCClass.jdo
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/mylib/PCClass.jdo?rev=359106&r1=359105&r2=359106&view=diff
==============================================================================
--- db/jdo/trunk/tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/mylib/PCClass.jdo (original)
+++ db/jdo/trunk/tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/mylib/PCClass.jdo Mon Dec 26 14:04:34 2005
@@ -2,24 +2,19 @@
<!DOCTYPE jdo PUBLIC "-//Sun Microsystems, Inc.//DTD Java Data Objects Metadata 2.0//EN" "http://java.sun.com/dtd/jdo_2_0.dtd">
<jdo>
<package name="org.apache.jdo.tck.pc.mylib">
-
- <!-- This will not be required once the JDOModel is fixed so that
- the defaults defined in section 18.4 of the spec are working
- -->
<class name="PCClass" identity-type="datastore">
<field name="transientNumber1" persistence-modifier="none"/>
<field name="transientNumber2" persistence-modifier="none"/>
<query name="classJDO">
SELECT FROM org.apache.jdo.tck.pc.mylib.PCClass
</query>
- <fetch-group name="default">
+ <fetch-group name="fetchGroup1" post-load="true">
<field name="number1"/>
- </fetch-group>
- <fetch-group name="fetchGoup2" post-load="true">
+ </fetch-group>
+ <fetch-group name="fetchGroup2" post-load="true">
<field name="number2"/>
</fetch-group>
</class>
-
</package>
</jdo>