cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r957030 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test: java/org/apache/cayenne/ java/org/apache/cayenne/util/ resources/dml/
Date Tue, 22 Jun 2010 21:00:59 GMT
Author: aadamchik
Date: Tue Jun 22 21:00:59 2010
New Revision: 957030

URL: http://svn.apache.org/viewvc?rev=957030&view=rev
Log:
DI-enabled unit tests

* more tests converted

Removed:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/PersistentObjectInContextTest.xml
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/access.DataContextNamedQueryCachingTest.xml
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/dml/util.ObjectDetachOperationTest.xml
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/PersistentObjectInContextTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/ObjectDetachOperationTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextTest.java?rev=957030&r1=957029&r2=957030&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextTest.java
Tue Jun 22 21:00:59 2010
@@ -49,7 +49,7 @@ import org.apache.cayenne.util.GenericRe
 public class CayenneContextTest extends ClientCase {
 
     @Inject
-    protected ObjectContext serverContext;
+    private ObjectContext serverContext;
 
     public void testConstructor() {
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/PersistentObjectInContextTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/PersistentObjectInContextTest.java?rev=957030&r1=957029&r2=957030&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/PersistentObjectInContextTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/PersistentObjectInContextTest.java
Tue Jun 22 21:00:59 2010
@@ -19,46 +19,54 @@
 
 package org.apache.cayenne;
 
-import java.util.Iterator;
 import java.util.List;
 
-import org.apache.cayenne.access.ClientServerChannel;
-import org.apache.cayenne.event.MockEventManager;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.query.ObjectIdQuery;
-import org.apache.cayenne.remote.ClientChannel;
-import org.apache.cayenne.remote.ClientConnection;
-import org.apache.cayenne.remote.service.LocalConnection;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.mt.ClientMtTable1;
 import org.apache.cayenne.testdo.mt.ClientMtTable2;
 import org.apache.cayenne.testdo.mt.MtTable1;
 import org.apache.cayenne.testdo.mt.MtTable2;
-import org.apache.cayenne.unit.AccessStack;
-import org.apache.cayenne.unit.CayenneCase;
-import org.apache.cayenne.unit.CayenneResources;
+import org.apache.cayenne.unit.di.client.ClientCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
 import org.apache.cayenne.util.PersistentObjectHolder;
 
-public class PersistentObjectInContextTest extends CayenneCase {
+@UseServerRuntime(ClientCase.MULTI_TIER_PROJECT)
+public class PersistentObjectInContextTest extends ClientCase {
+
+    @Inject
+    private CayenneContext context;
+
+    @Inject
+    private DBHelper dbHelper;
+
+    private TableHelper tMtTable1;
+    private TableHelper tMtTable2;
 
     @Override
-    protected AccessStack buildAccessStack() {
-        return CayenneResources.getResources().getAccessStack(MULTI_TIER_ACCESS_STACK);
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("MT_TABLE2");
+        dbHelper.deleteAll("MT_TABLE1");
+
+        tMtTable1 = new TableHelper(dbHelper, "MT_TABLE1");
+        tMtTable1.setColumns("TABLE1_ID", "GLOBAL_ATTRIBUTE1", "SERVER_ATTRIBUTE1");
+
+        tMtTable2 = new TableHelper(dbHelper, "MT_TABLE2");
+        tMtTable2.setColumns("TABLE2_ID", "TABLE1_ID", "GLOBAL_ATTRIBUTE");
     }
 
-    protected ObjectContext createObjectContext() {
-        // wrap ClientServerChannel in LocalConnection to enable logging...
-        ClientConnection connector = new LocalConnection(new ClientServerChannel(
-                getDomain()), LocalConnection.HESSIAN_SERIALIZATION);
-        return new CayenneContext(new ClientChannel(
-                connector,
-                false,
-                new MockEventManager(),
-                false));
+    private void createTwoMtTable1sAnd2sDataSet() throws Exception {
+        tMtTable1.insert(1, "g1", "s1");
+        tMtTable1.insert(2, "g2", "s2");
+
+        tMtTable2.insert(1, 1, "g1");
+        tMtTable2.insert(2, 1, "g2");
     }
 
     public void testResolveToManyReverseResolved() throws Exception {
-        createTestData("prepare");
-
-        ObjectContext context = createObjectContext();
+        createTwoMtTable1sAnd2sDataSet();
 
         ObjectId gid = new ObjectId(
                 "MtTable1",
@@ -70,11 +78,10 @@ public class PersistentObjectInContextTe
 
         assertNotNull(t1);
 
-        List t2s = t1.getTable2Array();
+        List<ClientMtTable2> t2s = t1.getTable2Array();
         assertEquals(2, t2s.size());
-        Iterator it = t2s.iterator();
-        while (it.hasNext()) {
-            ClientMtTable2 t2 = (ClientMtTable2) it.next();
+
+        for (ClientMtTable2 t2 : t2s) {
 
             PersistentObjectHolder holder = (PersistentObjectHolder) t2.getTable1Direct();
             assertFalse(holder.isFault());
@@ -83,9 +90,7 @@ public class PersistentObjectInContextTe
     }
 
     public void testToOneRelationship() throws Exception {
-        createTestData("prepare");
-
-        ObjectContext context = createObjectContext();
+        createTwoMtTable1sAnd2sDataSet();
 
         ObjectId gid = new ObjectId(
                 "MtTable2",
@@ -103,9 +108,7 @@ public class PersistentObjectInContextTe
     }
 
     public void testResolveToOneReverseResolved() throws Exception {
-        createTestData("prepare");
-
-        ObjectContext context = createObjectContext();
+        createTwoMtTable1sAnd2sDataSet();
 
         ObjectId gid = new ObjectId(
                 "MtTable2",
@@ -120,7 +123,7 @@ public class PersistentObjectInContextTe
         ClientMtTable1 mtTable1 = mtTable21.getTable1();
         assertNotNull("To one relationship incorrectly resolved to null", mtTable1);
 
-        List list = mtTable1.getTable2Array();
+        List<ClientMtTable2> list = mtTable1.getTable2Array();
         assertNotNull(list);
         assertTrue(list instanceof ValueHolder);
 
@@ -128,10 +131,7 @@ public class PersistentObjectInContextTe
 
         // resolve it here...
         assertEquals(2, list.size());
-        Iterator it = list.iterator();
-        while (it.hasNext()) {
-            ClientMtTable2 t2 = (ClientMtTable2) it.next();
-
+        for (ClientMtTable2 t2 : list) {
             PersistentObjectHolder holder = (PersistentObjectHolder) t2.getTable1Direct();
             assertFalse(holder.isFault());
             assertSame(mtTable1, holder.getValue());

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/ObjectDetachOperationTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/ObjectDetachOperationTest.java?rev=957030&r1=957029&r2=957030&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/ObjectDetachOperationTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/ObjectDetachOperationTest.java
Tue Jun 22 21:00:59 2010
@@ -22,26 +22,38 @@ package org.apache.cayenne.util;
 import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.PersistenceState;
 import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.mt.ClientMtTable1;
 import org.apache.cayenne.testdo.mt.MtTable1;
-import org.apache.cayenne.unit.AccessStack;
-import org.apache.cayenne.unit.CayenneCase;
-import org.apache.cayenne.unit.CayenneResources;
+import org.apache.cayenne.unit.di.client.ClientCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
-public class ObjectDetachOperationTest extends CayenneCase {
+@UseServerRuntime(ClientCase.MULTI_TIER_PROJECT)
+public class ObjectDetachOperationTest extends ClientCase {
+
+    @Inject
+    private DataContext serverContext;
+
+    @Inject
+    private DBHelper dbHelper;
+
+    private TableHelper tMtTable1;
 
     @Override
-    protected AccessStack buildAccessStack() {
-        return CayenneResources
-                .getResources()
-                .getAccessStack(MULTI_TIER_ACCESS_STACK);
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("MT_TABLE2");
+        dbHelper.deleteAll("MT_TABLE1");
+
+        tMtTable1 = new TableHelper(dbHelper, "MT_TABLE1");
+        tMtTable1.setColumns("TABLE1_ID", "GLOBAL_ATTRIBUTE1", "SERVER_ATTRIBUTE1");
     }
 
     public void testDetachCommitted() {
 
-        DataContext context = createDataContext();
-        EntityResolver serverResover = context.getEntityResolver();
+        EntityResolver serverResover = serverContext.getEntityResolver();
         EntityResolver clientResolver = serverResover.getClientEntityResolver();
         ObjectDetachOperation op = new ObjectDetachOperation(clientResolver);
 
@@ -50,8 +62,8 @@ public class ObjectDetachOperationTest e
         so.setObjectId(oid);
         so.setGlobalAttribute1("gx");
         so.setPersistenceState(PersistenceState.COMMITTED);
-        so.setObjectContext(context);
-        context.getGraphManager().registerNode(oid, so);
+        so.setObjectContext(serverContext);
+        serverContext.getGraphManager().registerNode(oid, so);
 
         Object detached = op.detach(
                 so,
@@ -70,19 +82,18 @@ public class ObjectDetachOperationTest e
 
     public void testDetachHollow() throws Exception {
 
-        createTestData("testDetachHollow");
+        tMtTable1.insert(4, "g1", "s1");
 
-        DataContext context = createDataContext();
-        EntityResolver serverResover = context.getEntityResolver();
+        EntityResolver serverResover = serverContext.getEntityResolver();
         EntityResolver clientResolver = serverResover.getClientEntityResolver();
         ObjectDetachOperation op = new ObjectDetachOperation(clientResolver);
 
-        ObjectId oid = new ObjectId("MtTable1", MtTable1.TABLE1_ID_PK_COLUMN, 1);
+        ObjectId oid = new ObjectId("MtTable1", MtTable1.TABLE1_ID_PK_COLUMN, 4);
         MtTable1 so = new MtTable1();
         so.setObjectId(oid);
         so.setPersistenceState(PersistenceState.HOLLOW);
-        so.setObjectContext(context);
-        context.getGraphManager().registerNode(oid, so);
+        so.setObjectContext(serverContext);
+        serverContext.getGraphManager().registerNode(oid, so);
 
         Object detached = op.detach(
                 so,



Mime
View raw message