cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1083937 - /cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/relationship/UuidRelationshipHandlerTest.java
Date Mon, 21 Mar 2011 20:27:22 GMT
Author: aadamchik
Date: Mon Mar 21 20:27:22 2011
New Revision: 1083937

URL: http://svn.apache.org/viewvc?rev=1083937&view=rev
Log:
CAY-1547 cayenne-lifecycle: support for setting UuidRelationships

a test inserting related UUID related objects

Modified:
    cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/relationship/UuidRelationshipHandlerTest.java

Modified: cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/relationship/UuidRelationshipHandlerTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/relationship/UuidRelationshipHandlerTest.java?rev=1083937&r1=1083936&r2=1083937&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/relationship/UuidRelationshipHandlerTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/relationship/UuidRelationshipHandlerTest.java
Mon Mar 21 20:27:22 2011
@@ -34,9 +34,20 @@ public class UuidRelationshipHandlerTest
 
     private ServerRuntime runtime;
 
+    private TableHelper rootTable;
+    private TableHelper e1Table;
+
     @Override
     protected void setUp() throws Exception {
         runtime = new ServerRuntime("cayenne-lifecycle.xml");
+
+        DBHelper dbHelper = new DBHelper(runtime.getDataSource(null));
+
+        rootTable = new TableHelper(dbHelper, "UUID_ROOT1").setColumns("ID", "UUID");
+        rootTable.deleteAll();
+
+        e1Table = new TableHelper(dbHelper, "E1").setColumns("ID");
+        e1Table.deleteAll();
     }
 
     @Override
@@ -46,14 +57,6 @@ public class UuidRelationshipHandlerTest
 
     public void testRelate_Existing() throws Exception {
 
-        DBHelper dbHelper = new DBHelper(runtime.getDataSource(null));
-
-        TableHelper rootTable = new TableHelper(dbHelper, "UUID_ROOT1").setColumns(
-                "ID",
-                "UUID");
-        rootTable.deleteAll();
-        TableHelper e1Table = new TableHelper(dbHelper, "E1").setColumns("ID");
-        e1Table.deleteAll();
         e1Table.insert(1);
 
         ObjectContext context = runtime.getContext();
@@ -68,9 +71,29 @@ public class UuidRelationshipHandlerTest
 
         assertEquals("E1:1", r1.getUuid());
         assertSame(e1, r1.readPropertyDirectly("cay:related:uuid"));
-        
+
         context.commitChanges();
-        
+
+        Object[] r1x = rootTable.select();
+        assertEquals("E1:1", r1x[1]);
+    }
+
+    public void testRelate_New() throws Exception {
+
+        ObjectContext context = runtime.getContext();
+        E1 e1 = context.newObject(E1.class);
+
+        UuidRoot1 r1 = context.newObject(UuidRoot1.class);
+
+        ReferenceableHandler refHandler = new ReferenceableHandler(context
+                .getEntityResolver());
+        UuidRelationshipHandler handler = new UuidRelationshipHandler(refHandler);
+        handler.relate(r1, e1);
+
+        assertSame(e1, r1.readPropertyDirectly("cay:related:uuid"));
+
+        context.commitChanges();
+
         Object[] r1x = rootTable.select();
         assertEquals("E1:1", r1x[1]);
     }



Mime
View raw message