cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1096017 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test: java/org/apache/cayenne/access/DataContextPrefetchExtrasTest.java resources/dml/access.DataContextPrefetchExtrasTest.xml
Date Fri, 22 Apr 2011 20:14:31 GMT
Author: aadamchik
Date: Fri Apr 22 20:14:31 2011
New Revision: 1096017

URL: http://svn.apache.org/viewvc?rev=1096017&view=rev
Log:
CAY-1560

patches by Dzmitry Kazimirchyk:
DataContextPrefetchExtrasTest.patch

Removed:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/access.DataContextPrefetchExtrasTest.xml
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchExtrasTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchExtrasTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchExtrasTest.java?rev=1096017&r1=1096016&r2=1096017&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchExtrasTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchExtrasTest.java
Fri Apr 22 20:14:31 2011
@@ -23,45 +23,94 @@ import java.util.List;
 
 import org.apache.cayenne.CayenneDataObject;
 import org.apache.cayenne.DataObject;
+import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.PersistenceState;
 import org.apache.cayenne.ValueHolder;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.query.SortOrder;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.testmap.CharFkTestEntity;
 import org.apache.cayenne.testdo.testmap.CharPkTestEntity;
 import org.apache.cayenne.testdo.testmap.CompoundFkTestEntity;
 import org.apache.cayenne.testdo.testmap.CompoundPkTestEntity;
-import org.apache.cayenne.unit.CayenneCase;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
 /**
  * Test prefetching of various obscure cases.
  */
-public class DataContextPrefetchExtrasTest extends CayenneCase {
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextPrefetchExtrasTest extends ServerCase {
 
-    protected DataContext context;
+    @Inject
+    protected ObjectContext context;
+
+    @Inject
+    protected DBHelper dbHelper;
+
+    protected TableHelper tCharPkTest;
+    protected TableHelper tCharFkTest;
+    protected TableHelper tCompoundPkTest;
+    protected TableHelper tCompoundFkTest;
 
     @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        deleteTestData();
-        context = createDataContext();
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("CHAR_PK_TEST");
+        dbHelper.deleteAll("CHAR_FK_TEST");
+        dbHelper.deleteAll("COMPOUND_PK_TEST");
+        dbHelper.deleteAll("COMPOUND_FK_TEST");
+
+        tCharPkTest = new TableHelper(dbHelper, "CHAR_PK_TEST");
+        tCharPkTest.setColumns("PK_COL", "OTHER_COL");
+
+        tCharFkTest = new TableHelper(dbHelper, "CHAR_FK_TEST");
+        tCharFkTest.setColumns("PK", "FK_COL", "NAME");
+
+        tCompoundPkTest = new TableHelper(dbHelper, "COMPOUND_PK_TEST");
+        tCompoundPkTest.setColumns("KEY1", "KEY2", "NAME");
+
+        tCompoundFkTest = new TableHelper(dbHelper, "COMPOUND_FK_TEST");
+        tCompoundFkTest.setColumns("PKEY", "F_KEY1", "F_KEY2", "NAME");
+    }
+
+    protected void createPrefetchToManyOnCharKeyDataSet() throws Exception {
+        tCharPkTest.insert("k1", "n1");
+        tCharPkTest.insert("k2", "n2");
+
+        tCharFkTest.insert(1, "k1", "fn1");
+        tCharFkTest.insert(2, "k1", "fn2");
+        tCharFkTest.insert(3, "k2", "fn3");
+        tCharFkTest.insert(4, "k2", "fn4");
+        tCharFkTest.insert(5, "k1", "fn5");
+    }
+
+    protected void createCompoundDataSet() throws Exception {
+        tCompoundPkTest.insert("101", "201", "CPK1");
+        tCompoundPkTest.insert("102", "202", "CPK2");
+        tCompoundPkTest.insert("103", "203", "CPK3");
+
+        tCompoundFkTest.insert(301, "102", "202", "CFK1");
+        tCompoundFkTest.insert(302, "102", "202", "CFK2");
+        tCompoundFkTest.insert(303, "101", "201", "CFK3");
     }
 
     public void testPrefetchToManyOnCharKey() throws Exception {
-        createTestData("testPrefetchToManyOnCharKey");
+        createPrefetchToManyOnCharKeyDataSet();
 
         SelectQuery q = new SelectQuery(CharPkTestEntity.class);
         q.addPrefetch("charFKs");
         q.addOrdering(CharPkTestEntity.OTHER_COL_PROPERTY, SortOrder.ASCENDING);
 
-        List pks = context.performQuery(q);
+        List<?> pks = context.performQuery(q);
         assertEquals(2, pks.size());
 
         CharPkTestEntity pk1 = (CharPkTestEntity) pks.get(0);
         assertEquals("n1", pk1.getOtherCol());
-        List toMany = (List) pk1.readPropertyDirectly("charFKs");
+        List<?> toMany = (List<?>) pk1.readPropertyDirectly("charFKs");
         assertNotNull(toMany);
         assertFalse(((ValueHolder) toMany).isFault());
         assertEquals(3, toMany.size());
@@ -75,49 +124,42 @@ public class DataContextPrefetchExtrasTe
      * Tests to-one prefetching over relationships with compound keys.
      */
     public void testPrefetch10() throws Exception {
-        createTestData("testCompound");
+        createCompoundDataSet();
 
         Expression e = ExpressionFactory.matchExp("name", "CFK2");
         SelectQuery q = new SelectQuery(CompoundFkTestEntity.class, e);
         q.addPrefetch("toCompoundPk");
 
-        List objects = context.performQuery(q);
+        List<?> objects = context.performQuery(q);
         assertEquals(1, objects.size());
         CayenneDataObject fk1 = (CayenneDataObject) objects.get(0);
 
-        blockQueries();
-        try {
-
-            Object toOnePrefetch = fk1.readNestedProperty("toCompoundPk");
-            assertNotNull(toOnePrefetch);
-            assertTrue(
-                    "Expected DataObject, got: " + toOnePrefetch.getClass().getName(),
-                    toOnePrefetch instanceof DataObject);
-
-            DataObject pk1 = (DataObject) toOnePrefetch;
-            assertEquals(PersistenceState.COMMITTED, pk1.getPersistenceState());
-            assertEquals("CPK2", pk1.readPropertyDirectly("name"));
-        }
-        finally {
-            unblockQueries();
-        }
+        Object toOnePrefetch = fk1.readNestedProperty("toCompoundPk");
+        assertNotNull(toOnePrefetch);
+        assertTrue(
+                "Expected DataObject, got: " + toOnePrefetch.getClass().getName(),
+                toOnePrefetch instanceof DataObject);
+
+        DataObject pk1 = (DataObject) toOnePrefetch;
+        assertEquals(PersistenceState.COMMITTED, pk1.getPersistenceState());
+        assertEquals("CPK2", pk1.readPropertyDirectly("name"));
     }
 
     /**
      * Tests to-many prefetching over relationships with compound keys.
      */
     public void testPrefetch11() throws Exception {
-        createTestData("testCompound");
+        createCompoundDataSet();
 
         Expression e = ExpressionFactory.matchExp("name", "CPK2");
         SelectQuery q = new SelectQuery(CompoundPkTestEntity.class, e);
         q.addPrefetch("compoundFkArray");
 
-        List pks = context.performQuery(q);
+        List<?> pks = context.performQuery(q);
         assertEquals(1, pks.size());
         CayenneDataObject pk1 = (CayenneDataObject) pks.get(0);
 
-        List toMany = (List) pk1.readPropertyDirectly("compoundFkArray");
+        List<?> toMany = (List<?>) pk1.readPropertyDirectly("compoundFkArray");
         assertNotNull(toMany);
         assertFalse(((ValueHolder) toMany).isFault());
         assertEquals(2, toMany.size());



Mime
View raw message