cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1234425 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne: ./ access/ util/
Date Sat, 21 Jan 2012 22:01:26 GMT
Author: aadamchik
Date: Sat Jan 21 22:01:25 2012
New Revision: 1234425

URL: http://svn.apache.org/viewvc?rev=1234425&view=rev
Log:
CAY-1616 Remove internal dependencies on deprecated ObjectContext.localObject

migrating unit tests

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/ShallowMergeOperation_ClientTest.java
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/NestedCayenneContextTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDataChannelEventsTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDelegateSharedCacheTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextReadTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextWriteTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NumericTypesTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/ShallowMergeOperationTest.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=1234425&r1=1234424&r2=1234425&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 Sat Jan 21 22:01:25 2012
@@ -389,7 +389,7 @@ public class CayenneContextTest extends 
         context.setEntityResolver(serverContext
                 .getEntityResolver()
                 .getClientEntityResolver());
-        ClientMtTable1 hollow = (ClientMtTable1) context.localObject(gid, null);
+        ClientMtTable1 hollow = context.localObject(inflated);
         assertEquals(PersistenceState.HOLLOW, hollow.getPersistenceState());
 
         // testing this...

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/NestedCayenneContextTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/NestedCayenneContextTest.java?rev=1234425&r1=1234424&r2=1234425&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/NestedCayenneContextTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/NestedCayenneContextTest.java Sat Jan 21 22:01:25 2012
@@ -24,7 +24,6 @@ import java.util.List;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.graph.GraphChangeHandler;
 import org.apache.cayenne.graph.GraphDiff;
-import org.apache.cayenne.query.ObjectIdQuery;
 import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.query.SortOrder;
 import org.apache.cayenne.remote.RemoteCayenneCase;
@@ -71,127 +70,6 @@ public class NestedCayenneContextTest ex
         assertSame(child, grandchild.getChannel());
     }
 
-    public void testLocalObjectSynchronize() throws Exception {
-        final ObjectContext child = clientContext.createChildContext();
-
-        final ClientMtTable1 committed = clientContext.newObject(ClientMtTable1.class);
-        final ClientMtTable1 deleted = clientContext.newObject(ClientMtTable1.class);
-        final ClientMtTable1 modified = clientContext.newObject(ClientMtTable1.class);
-
-        clientContext.commitChanges();
-
-        clientContext.deleteObjects(deleted);
-        modified.setGlobalAttribute1("a");
-
-        final ClientMtTable1 _new = clientContext.newObject(ClientMtTable1.class);
-
-        final ClientMtTable1 hollow = (ClientMtTable1) clientContext.localObject(new ObjectId(
-                "MtTable1"), null);
-
-        assertEquals(PersistenceState.HOLLOW, hollow.getPersistenceState());
-        assertEquals(PersistenceState.COMMITTED, committed.getPersistenceState());
-        assertEquals(PersistenceState.MODIFIED, modified.getPersistenceState());
-        assertEquals(PersistenceState.DELETED, deleted.getPersistenceState());
-        assertEquals(PersistenceState.NEW, _new.getPersistenceState());
-
-        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
-
-            public void execute() {
-                Persistent newPeer = child.localObject(_new.getObjectId(), _new);
-
-                assertEquals(_new.getObjectId(), newPeer.getObjectId());
-                assertEquals(PersistenceState.COMMITTED, newPeer.getPersistenceState());
-
-                assertSame(child, newPeer.getObjectContext());
-                assertSame(clientContext, _new.getObjectContext());
-
-                Persistent hollowPeer = child.localObject(hollow.getObjectId(), hollow);
-                assertEquals(PersistenceState.HOLLOW, hollowPeer.getPersistenceState());
-                assertEquals(hollow.getObjectId(), hollowPeer.getObjectId());
-                assertSame(child, hollowPeer.getObjectContext());
-                assertSame(clientContext, hollow.getObjectContext());
-
-                Persistent committedPeer = child.localObject(
-                        committed.getObjectId(),
-                        committed);
-                assertEquals(PersistenceState.COMMITTED, committedPeer
-                        .getPersistenceState());
-                assertEquals(committed.getObjectId(), committedPeer.getObjectId());
-                assertSame(child, committedPeer.getObjectContext());
-                assertSame(clientContext, committed.getObjectContext());
-
-                ClientMtTable1 modifiedPeer = (ClientMtTable1) child.localObject(modified
-                        .getObjectId(), modified);
-                assertEquals(PersistenceState.COMMITTED, modifiedPeer
-                        .getPersistenceState());
-                assertEquals(modified.getObjectId(), modifiedPeer.getObjectId());
-                assertEquals("a", modifiedPeer.getGlobalAttribute1());
-                assertSame(child, modifiedPeer.getObjectContext());
-                assertSame(clientContext, modified.getObjectContext());
-
-                Persistent deletedPeer = child
-                        .localObject(deleted.getObjectId(), deleted);
-                assertEquals(PersistenceState.COMMITTED, deletedPeer
-                        .getPersistenceState());
-                assertEquals(deleted.getObjectId(), deletedPeer.getObjectId());
-                assertSame(child, deletedPeer.getObjectContext());
-                assertSame(clientContext, deleted.getObjectContext());
-            }
-        });
-    }
-
-    public void testLocalObjectsNoOverride() throws Exception {
-        final ObjectContext child = clientContext.createChildContext();
-
-        final ClientMtTable1 modified = clientContext.newObject(ClientMtTable1.class);
-        clientContext.commitChanges();
-
-        final ClientMtTable1 peerModified = (ClientMtTable1) Cayenne.objectForQuery(
-                child,
-                new ObjectIdQuery(modified.getObjectId()));
-
-        modified.setGlobalAttribute1("M1");
-        peerModified.setGlobalAttribute1("M2");
-
-        assertEquals(PersistenceState.MODIFIED, modified.getPersistenceState());
-        assertEquals(PersistenceState.MODIFIED, peerModified.getPersistenceState());
-
-        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
-
-            public void execute() {
-                Persistent peerModified2 = child.localObject(
-                        modified.getObjectId(),
-                        modified);
-                assertSame(peerModified, peerModified2);
-                assertEquals(PersistenceState.MODIFIED, peerModified2
-                        .getPersistenceState());
-                assertEquals("M2", peerModified.getGlobalAttribute1());
-                assertEquals("M1", modified.getGlobalAttribute1());
-            }
-        });
-    }
-
-    public void testLocalObjectRelationship() throws Exception {
-        final ObjectContext child = clientContext.createChildContext();
-
-        ClientMtTable1 _new = clientContext.newObject(ClientMtTable1.class);
-        final ClientMtTable2 _new2 = clientContext.newObject(ClientMtTable2.class);
-        _new.addToTable2Array(_new2);
-
-        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
-
-            public void execute() {
-                ClientMtTable2 child2 = (ClientMtTable2) child.localObject(_new2
-                        .getObjectId(), _new2);
-                assertEquals(PersistenceState.COMMITTED, child2.getPersistenceState());
-                assertNotNull(child2.getTable1());
-                assertEquals(PersistenceState.COMMITTED, child2
-                        .getTable1()
-                        .getPersistenceState());
-            }
-        });
-    }
-
     public void testSelect() throws Exception {
         ObjectContext child = clientContext.createChildContext();
 
@@ -327,8 +205,9 @@ public class NestedCayenneContextTest ex
         clientContext.commitChanges();
 
         ClientMtTable2 p = child.newObject(ClientMtTable2.class);
-        ClientMtTable1 aChild = (ClientMtTable1) Cayenne.objectForPK(child, a
-                .getObjectId());
+        ClientMtTable1 aChild = (ClientMtTable1) Cayenne.objectForPK(
+                child,
+                a.getObjectId());
         p.setGlobalAttribute("X");
         aChild.addToTable2Array(p);
 
@@ -353,8 +232,9 @@ public class NestedCayenneContextTest ex
         final ObjectContext child = clientContext.createChildContext();
         ObjectContext childPeer = clientContext.createChildContext();
 
-        final ClientMtTable2 childP1 = (ClientMtTable2) Cayenne.objectForPK(child, b
-                .getObjectId());
+        final ClientMtTable2 childP1 = (ClientMtTable2) Cayenne.objectForPK(
+                child,
+                b.getObjectId());
 
         // trigger object creation in the peer nested DC
         Cayenne.objectForPK(childPeer, b.getObjectId());
@@ -453,10 +333,12 @@ public class NestedCayenneContextTest ex
                 // * no actual commit should occur.
 
                 assertEquals(PersistenceState.COMMITTED, childNew.getPersistenceState());
-                assertEquals(PersistenceState.COMMITTED, childModified
-                        .getPersistenceState());
-                assertEquals(PersistenceState.COMMITTED, childCommitted
-                        .getPersistenceState());
+                assertEquals(
+                        PersistenceState.COMMITTED,
+                        childModified.getPersistenceState());
+                assertEquals(
+                        PersistenceState.COMMITTED,
+                        childCommitted.getPersistenceState());
                 assertEquals(PersistenceState.HOLLOW, childHollow.getPersistenceState());
 
                 ClientMtTable1 parentNew = (ClientMtTable1) clientContext
@@ -477,13 +359,15 @@ public class NestedCayenneContextTest ex
                 assertEquals("NNN", parentNew.getGlobalAttribute1());
 
                 assertNotNull(parentModified);
-                assertEquals(PersistenceState.MODIFIED, parentModified
-                        .getPersistenceState());
+                assertEquals(
+                        PersistenceState.MODIFIED,
+                        parentModified.getPersistenceState());
                 assertEquals("MMM", parentModified.getGlobalAttribute1());
 
                 assertNotNull(parentCommitted);
-                assertEquals(PersistenceState.COMMITTED, parentCommitted
-                        .getPersistenceState());
+                assertEquals(
+                        PersistenceState.COMMITTED,
+                        parentCommitted.getPersistenceState());
 
                 assertNotNull(parentHollow);
 
@@ -574,95 +458,92 @@ public class NestedCayenneContextTest ex
         assertEquals(PersistenceState.DELETED, parentDeleted.getPersistenceState());
         assertEquals("DDD", parentDeleted.getGlobalAttribute1());
     }
-    
-    
+
     /*
      * was added for CAY-1636
      */
     public void testCAY1636() throws Exception {
-        
+
         ClientMtTooneMaster A = clientContext.newObject(ClientMtTooneMaster.class);
         clientContext.commitChanges();
-        
+
         ClientMtTooneDep B = clientContext.newObject(ClientMtTooneDep.class);
         A.setToDependent(B);
         clientContext.commitChanges();
-        
+
         ObjectContext child = clientContext.createChildContext();
-    
+
         SelectQuery query = new SelectQuery(ClientMtTooneMaster.class);
         List<?> objects = child.performQuery(query);
-        
+
         assertEquals(1, objects.size());
-        
+
         ClientMtTooneMaster childDeleted = (ClientMtTooneMaster) objects.get(0);
-        
-      
+
         child.deleteObjects(childDeleted);
 
         child.commitChangesToParent();
-        
+
         ClientMtTooneMaster parentDeleted = (ClientMtTooneMaster) clientContext
-          .getGraphManager()
-          .getNode(childDeleted.getObjectId());
-        
+                .getGraphManager()
+                .getNode(childDeleted.getObjectId());
+
         assertNotNull(parentDeleted);
         assertEquals(PersistenceState.DELETED, parentDeleted.getPersistenceState());
-        
+
         clientContext.commitChanges();
-        
+
         SelectQuery query2 = new SelectQuery(ClientMtTooneMaster.class);
         List<?> objects2 = child.performQuery(query2);
-        
+
         assertEquals(0, objects2.size());
- 
+
     }
-    
+
     public void testCAY1636_2() throws Exception {
-        
+
         ClientMtTooneMaster A = clientContext.newObject(ClientMtTooneMaster.class);
         clientContext.commitChanges();
-        
+
         ClientMtTooneDep B = clientContext.newObject(ClientMtTooneDep.class);
         A.setToDependent(B);
         clientContext.commitChanges();
-        
+
         ObjectContext child = clientContext.createChildContext();
-        
+
         SelectQuery queryB = new SelectQuery(ClientMtTooneDep.class);
         List<?> objectsB = child.performQuery(queryB);
-        
+
         assertEquals(1, objectsB.size());
-        
+
         ClientMtTooneDep childBDeleted = (ClientMtTooneDep) objectsB.get(0);
         child.deleteObjects(childBDeleted);
-    
+
         SelectQuery query = new SelectQuery(ClientMtTooneMaster.class);
         List<?> objects = child.performQuery(query);
-        
+
         assertEquals(1, objects.size());
-        
+
         ClientMtTooneMaster childDeleted = (ClientMtTooneMaster) objects.get(0);
-        
-      
+
         child.deleteObjects(childDeleted);
 
         child.commitChangesToParent();
-        
+
         ClientMtTooneMaster parentDeleted = (ClientMtTooneMaster) clientContext
-          .getGraphManager()
-          .getNode(childDeleted.getObjectId());
-        
+                .getGraphManager()
+                .getNode(childDeleted.getObjectId());
+
         assertNotNull(parentDeleted);
         assertEquals(PersistenceState.DELETED, parentDeleted.getPersistenceState());
-        
+
         clientContext.commitChanges();
-        
+
         SelectQuery query2 = new SelectQuery(ClientMtTooneMaster.class);
         List<?> objects2 = child.performQuery(query2);
-        
+
         assertEquals(0, objects2.size());
- 
+
     }
 
     public void testCommitChanges() throws Exception {
@@ -704,8 +585,9 @@ public class NestedCayenneContextTest ex
         assertEquals(PersistenceState.TRANSIENT, childDeleted.getPersistenceState());
         assertEquals(PersistenceState.HOLLOW, childHollow.getPersistenceState());
 
-        ClientMtTable1 parentNew = (ClientMtTable1) clientContext.getGraphManager().getNode(
-                childNew.getObjectId());
+        ClientMtTable1 parentNew = (ClientMtTable1) clientContext
+                .getGraphManager()
+                .getNode(childNew.getObjectId());
         ClientMtTable1 parentModified = (ClientMtTable1) clientContext
                 .getGraphManager()
                 .getNode(childModified.getObjectId());
@@ -715,8 +597,9 @@ public class NestedCayenneContextTest ex
         ClientMtTable1 parentDeleted = (ClientMtTable1) clientContext
                 .getGraphManager()
                 .getNode(childDeleted.getObjectId());
-        ClientMtTable1 parentHollow = (ClientMtTable1) clientContext.getGraphManager().getNode(
-                childHollow.getObjectId());
+        ClientMtTable1 parentHollow = (ClientMtTable1) clientContext
+                .getGraphManager()
+                .getNode(childHollow.getObjectId());
 
         assertNotNull(parentNew);
         assertEquals(PersistenceState.COMMITTED, parentNew.getPersistenceState());
@@ -771,8 +654,9 @@ public class NestedCayenneContextTest ex
         assertEquals(PersistenceState.MODIFIED, a.getPersistenceState());
 
         child.commitChangesToParent();
-        ClientMtTable1 parentA = (ClientMtTable1) clientContext.getGraphManager().getNode(
-                a.getObjectId());
+        ClientMtTable1 parentA = (ClientMtTable1) clientContext
+                .getGraphManager()
+                .getNode(a.getObjectId());
         assertEquals(PersistenceState.COMMITTED, a.getPersistenceState());
         assertEquals(PersistenceState.MODIFIED, parentA.getPersistenceState());
         assertEquals(1, parentA.getTable2Array().size());
@@ -794,8 +678,9 @@ public class NestedCayenneContextTest ex
         clientContext.commitChanges();
 
         ObjectContext child = clientContext.createChildContext();
-        ClientMtTable1 childMt = (ClientMtTable1) Cayenne.objectForPK(child, parentMt
-                .getObjectId());
+        ClientMtTable1 childMt = (ClientMtTable1) Cayenne.objectForPK(
+                child,
+                parentMt.getObjectId());
         childMt.setGlobalAttribute1("1183");
         ClientMtTable2 childMt2 = child.newObject(ClientMtTable2.class);
         childMt2.setGlobalAttribute("1183");
@@ -814,8 +699,7 @@ public class NestedCayenneContextTest ex
         ClientMtTable2 childMt2 = child.newObject(ClientMtTable2.class);
         childMt2.setGlobalAttribute("222");
 
-        ClientMtTable1 localParentMt = (ClientMtTable1) child.localObject(parentMt
-                .getObjectId(), null);
+        ClientMtTable1 localParentMt = child.localObject(parentMt);
         assertEquals(0, parentMt.getTable2Array().size());
         assertEquals(0, localParentMt.getTable2Array().size());
 
@@ -840,10 +724,12 @@ public class NestedCayenneContextTest ex
 
         child.commitChangesToParent();
 
-        ClientMtTable1 masterParent = (ClientMtTable1) clientContext.getGraphManager().getNode(
-                master.getObjectId());
-        ClientMtTable2 depParent = (ClientMtTable2) clientContext.getGraphManager().getNode(
-                dep.getObjectId());
+        ClientMtTable1 masterParent = (ClientMtTable1) clientContext
+                .getGraphManager()
+                .getNode(master.getObjectId());
+        ClientMtTable2 depParent = (ClientMtTable2) clientContext
+                .getGraphManager()
+                .getNode(dep.getObjectId());
 
         assertNotNull(masterParent);
         assertNotNull(depParent);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDataChannelEventsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDataChannelEventsTest.java?rev=1234425&r1=1234424&r2=1234425&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDataChannelEventsTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDataChannelEventsTest.java Sat Jan 21 22:01:25 2012
@@ -22,6 +22,7 @@ package org.apache.cayenne.access;
 import org.apache.cayenne.DataChannel;
 import org.apache.cayenne.DataChannelListener;
 import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.configuration.server.ServerRuntime;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.graph.GraphEvent;
 import org.apache.cayenne.testdo.testmap.Artist;
@@ -42,6 +43,9 @@ public class DataContextDataChannelEvent
     @Inject
     private DataContext peer;
 
+    @Inject
+    private ServerRuntime runtime;
+
     public void testCommitEvent() {
         Artist a = context.newObject(Artist.class);
         a.setArtistName("X");
@@ -82,11 +86,12 @@ public class DataContextDataChannelEvent
         MockChannelListener listener = new MockChannelListener();
         EventUtil.listenForChannelEvents(context, listener);
 
-        ObjectContext child = context.createChildContext();
-        Artist a1 = (Artist) child.localObject(a.getObjectId(), a);
+        ObjectContext childContext = runtime.getContext(context);
+
+        Artist a1 = childContext.localObject(a);
 
         a1.setArtistName("Y");
-        child.commitChangesToParent();
+        childContext.commitChangesToParent();
 
         assertFalse(listener.graphCommitted);
         assertTrue(listener.graphChanged);
@@ -101,7 +106,7 @@ public class DataContextDataChannelEvent
         final MockChannelListener listener = new MockChannelListener();
         EventUtil.listenForChannelEvents(context, listener);
 
-        Artist a1 = (Artist) peer.localObject(a.getObjectId(), a);
+        Artist a1 = peer.localObject(a);
 
         a1.setArtistName("Y");
         peer.commitChangesToParent();
@@ -118,7 +123,7 @@ public class DataContextDataChannelEvent
     }
 
     public void testChangeEventOnPeerChangeSecondNestingLevel() throws Exception {
-        ObjectContext childPeer1 = context.createChildContext();
+        ObjectContext childPeer1 = runtime.getContext(context);
 
         Artist a = childPeer1.newObject(Artist.class);
         a.setArtistName("X");
@@ -127,9 +132,9 @@ public class DataContextDataChannelEvent
         final MockChannelListener listener = new MockChannelListener();
         EventUtil.listenForChannelEvents((DataChannel) childPeer1, listener);
 
-        ObjectContext childPeer2 = context.createChildContext();
+        ObjectContext childPeer2 = runtime.getContext(context);
 
-        Artist a1 = (Artist) childPeer2.localObject(a.getObjectId(), a);
+        Artist a1 = childPeer2.localObject(a);
 
         a1.setArtistName("Y");
         childPeer2.commitChangesToParent();

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDelegateSharedCacheTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDelegateSharedCacheTest.java?rev=1234425&r1=1234424&r2=1234425&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDelegateSharedCacheTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDelegateSharedCacheTest.java Sat Jan 21 22:01:25 2012
@@ -54,8 +54,6 @@ public class DataContextDelegateSharedCa
     /**
      * Test case to prove that delegate method is invoked on external change of object in
      * the store.
-     * 
-     * @throws Exception
      */
     public void testShouldMergeChanges() throws Exception {
 
@@ -71,7 +69,7 @@ public class DataContextDelegateSharedCa
 
         // make sure we have a fully resolved copy of an artist object
         // in the second context
-        Artist altArtist = (Artist) context1.localObject(artist.getObjectId(), null);
+        Artist altArtist = context1.localObject(artist);
         assertNotNull(altArtist);
         assertNotSame(altArtist, artist);
         assertEquals(artist.getArtistName(), altArtist.getArtistName());
@@ -114,7 +112,7 @@ public class DataContextDelegateSharedCa
 
         // make sure we have a fully resolved copy of an artist object
         // in the second context
-        Artist altArtist = (Artist) context1.localObject(artist.getObjectId(), null);
+        Artist altArtist = context1.localObject(artist);
         assertNotNull(altArtist);
         assertFalse(altArtist == artist);
         assertEquals(oldName, altArtist.getArtistName());
@@ -149,7 +147,7 @@ public class DataContextDelegateSharedCa
 
         // make sure we have a fully resolved copy of an artist object
         // in the second context
-        Artist altArtist = (Artist) context1.localObject(artist.getObjectId(), null);
+        Artist altArtist = context1.localObject(artist);
         assertNotNull(altArtist);
         assertFalse(altArtist == artist);
         assertEquals(artist.getArtistName(), altArtist.getArtistName());
@@ -192,7 +190,7 @@ public class DataContextDelegateSharedCa
 
         // make sure we have a fully resolved copy of an artist object
         // in the second context
-        Artist altArtist = (Artist) context1.localObject(artist.getObjectId(), null);
+        Artist altArtist = context1.localObject(artist);
         assertNotNull(altArtist);
         assertFalse(altArtist == artist);
         assertEquals(artist.getArtistName(), altArtist.getArtistName());

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextTest.java?rev=1234425&r1=1234424&r2=1234425&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextTest.java Sat Jan 21 22:01:25 2012
@@ -37,6 +37,7 @@ import java.util.Map;
 
 import javax.sql.DataSource;
 
+import org.apache.cayenne.Cayenne;
 import org.apache.cayenne.DataObject;
 import org.apache.cayenne.DataRow;
 import org.apache.cayenne.Fault;
@@ -391,8 +392,9 @@ public class DataContextTest extends Ser
 
         createSingleArtistDataSet();
 
-        SelectQuery select = new SelectQuery(Painting.class, Expression
-                .fromString("db:PAINTING_ID = 1"));
+        SelectQuery select = new SelectQuery(
+                Painting.class,
+                Expression.fromString("db:PAINTING_ID = 1"));
 
         assertEquals(0, context.performQuery(select).size());
 
@@ -638,8 +640,10 @@ public class DataContextTest extends Ser
                 Artist artist = context.objectFromDataRow(Artist.class, row);
                 List<?> paintings = artist.getPaintingArray();
                 assertNotNull(paintings);
-                assertEquals("Expected one painting for artist: " + artist, 1, paintings
-                        .size());
+                assertEquals(
+                        "Expected one painting for artist: " + artist,
+                        1,
+                        paintings.size());
             }
         }
         finally {
@@ -703,7 +707,7 @@ public class DataContextTest extends Ser
         assertNull(context.getObjectStore().getCachedSnapshot(oid));
         assertSame(object, context.getObjectStore().getNode(oid));
     }
-    
+
     public void testInvalidateObjects() throws Exception {
 
         DataRow row = new DataRow(10);
@@ -729,19 +733,17 @@ public class DataContextTest extends Ser
     public void testBeforeHollowDeleteShouldChangeStateToCommited() throws Exception {
         createSingleArtistDataSet();
 
-        ObjectId gid = new ObjectId("Artist", "ARTIST_ID", 33001);
-        final Artist inflated = new Artist();
-        inflated.setPersistenceState(PersistenceState.COMMITTED);
-        inflated.setObjectId(gid);
-        inflated.setArtistName("artist1");
-
-        Artist hollow = (Artist) context.localObject(gid, null);
+        Artist hollow = Cayenne.objectForPK(context, Artist.class, 33001);
+        context.invalidateObjects(hollow);
         assertEquals(PersistenceState.HOLLOW, hollow.getPersistenceState());
 
         // testing this...
         context.deleteObjects(hollow);
-        assertSame(hollow, context.getGraphManager().getNode(gid));
-        assertEquals(inflated.getArtistName(), hollow.getArtistName());
+        assertSame(
+                hollow,
+                context.getGraphManager().getNode(
+                        new ObjectId("Artist", "ARTIST_ID", 33001)));
+        assertEquals("artist1", hollow.getArtistName());
 
         assertEquals(PersistenceState.DELETED, hollow.getPersistenceState());
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextReadTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextReadTest.java?rev=1234425&r1=1234424&r2=1234425&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextReadTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextReadTest.java Sat Jan 21 22:01:25 2012
@@ -133,143 +133,6 @@ public class NestedDataContextReadTest e
         assertFalse(((DataContext) child2).isValidatingObjectsOnCommit());
     }
 
-    public void testLocalObjectSynchronize() throws Exception {
-        createArtistsDataSet();
-
-        final ObjectContext childContext = context.createChildContext();
-
-        final Persistent _new = context.newObject(Artist.class);
-
-        final Persistent hollow = context.localObject(new ObjectId(
-                "Artist",
-                Artist.ARTIST_ID_PK_COLUMN,
-                33001), null);
-        final DataObject committed = (DataObject) Cayenne.objectForQuery(
-                context,
-                new ObjectIdQuery(new ObjectId(
-                        "Artist",
-                        Artist.ARTIST_ID_PK_COLUMN,
-                        33002)));
-
-        int modifiedId = 33003;
-        final Artist modified = (Artist) Cayenne.objectForQuery(
-                context,
-                new ObjectIdQuery(new ObjectId(
-                        "Artist",
-                        Artist.ARTIST_ID_PK_COLUMN,
-                        modifiedId)));
-        modified.setArtistName("M1");
-        final DataObject deleted = (DataObject) Cayenne.objectForQuery(
-                context,
-                new ObjectIdQuery(new ObjectId(
-                        "Artist",
-                        Artist.ARTIST_ID_PK_COLUMN,
-                        33004)));
-        context.deleteObjects(deleted);
-
-        assertEquals(PersistenceState.HOLLOW, hollow.getPersistenceState());
-        assertEquals(PersistenceState.COMMITTED, committed.getPersistenceState());
-        assertEquals(PersistenceState.MODIFIED, modified.getPersistenceState());
-        assertEquals(PersistenceState.DELETED, deleted.getPersistenceState());
-        assertEquals(PersistenceState.NEW, _new.getPersistenceState());
-
-        // now check how objects in different state behave
-
-        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
-
-            public void execute() {
-                Persistent newPeer = childContext.localObject(_new.getObjectId(), _new);
-
-                assertEquals(_new.getObjectId(), newPeer.getObjectId());
-                assertEquals(PersistenceState.COMMITTED, newPeer.getPersistenceState());
-
-                assertSame(childContext, newPeer.getObjectContext());
-                assertSame(context, _new.getObjectContext());
-
-                Persistent hollowPeer = childContext.localObject(
-                        hollow.getObjectId(),
-                        hollow);
-                assertEquals(PersistenceState.HOLLOW, hollowPeer.getPersistenceState());
-                assertEquals(hollow.getObjectId(), hollowPeer.getObjectId());
-                assertSame(childContext, hollowPeer.getObjectContext());
-                assertSame(context, hollow.getObjectContext());
-
-                Persistent committedPeer = childContext.localObject(
-                        committed.getObjectId(),
-                        committed);
-                assertEquals(
-                        PersistenceState.COMMITTED,
-                        committedPeer.getPersistenceState());
-                assertEquals(committed.getObjectId(), committedPeer.getObjectId());
-                assertSame(childContext, committedPeer.getObjectContext());
-                assertSame(context, committed.getObjectContext());
-
-                Artist modifiedPeer = (Artist) childContext.localObject(
-                        modified.getObjectId(),
-                        modified);
-                assertEquals(
-                        PersistenceState.COMMITTED,
-                        modifiedPeer.getPersistenceState());
-                assertEquals(modified.getObjectId(), modifiedPeer.getObjectId());
-                assertEquals("M1", modifiedPeer.getArtistName());
-                assertSame(childContext, modifiedPeer.getObjectContext());
-                assertSame(context, modified.getObjectContext());
-
-                Persistent deletedPeer = childContext.localObject(
-                        deleted.getObjectId(),
-                        deleted);
-                assertEquals(
-                        PersistenceState.COMMITTED,
-                        deletedPeer.getPersistenceState());
-                assertEquals(deleted.getObjectId(), deletedPeer.getObjectId());
-                assertSame(childContext, deletedPeer.getObjectContext());
-                assertSame(context, deleted.getObjectContext());
-
-            }
-        });
-    }
-
-    public void testLocalObjectsNoOverride() throws Exception {
-        createArtistsDataSet();
-
-        final ObjectContext childContext = context.createChildContext();
-
-        int modifiedId = 33003;
-        final Artist modified = (Artist) Cayenne.objectForQuery(
-                context,
-                new ObjectIdQuery(new ObjectId(
-                        "Artist",
-                        Artist.ARTIST_ID_PK_COLUMN,
-                        modifiedId)));
-        final Artist peerModified = (Artist) Cayenne.objectForQuery(
-                childContext,
-                new ObjectIdQuery(new ObjectId(
-                        "Artist",
-                        Artist.ARTIST_ID_PK_COLUMN,
-                        modifiedId)));
-
-        modified.setArtistName("M1");
-        peerModified.setArtistName("M2");
-
-        assertEquals(PersistenceState.MODIFIED, modified.getPersistenceState());
-        assertEquals(PersistenceState.MODIFIED, peerModified.getPersistenceState());
-
-        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
-
-            public void execute() {
-                Persistent peerModified2 = childContext.localObject(
-                        modified.getObjectId(),
-                        modified);
-                assertSame(peerModified, peerModified2);
-                assertEquals(
-                        PersistenceState.MODIFIED,
-                        peerModified2.getPersistenceState());
-                assertEquals("M2", peerModified.getArtistName());
-                assertEquals("M1", modified.getArtistName());
-            }
-        });
-    }
-
     public void testSelect() throws Exception {
         createArtistsDataSet();
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextWriteTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextWriteTest.java?rev=1234425&r1=1234424&r2=1234425&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextWriteTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextWriteTest.java Sat Jan 21 22:01:25 2012
@@ -654,7 +654,7 @@ public class NestedDataContextWriteTest 
         Painting painting = child.newObject(Painting.class);
         painting.setPaintingTitle("222");
 
-        Artist localParentMt = (Artist) child.localObject(artist.getObjectId(), null);
+        Artist localParentMt = child.localObject(artist);
         assertEquals(0, artist.getPaintingArray().size());
         assertEquals(0, localParentMt.getPaintingArray().size());
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NumericTypesTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NumericTypesTest.java?rev=1234425&r1=1234424&r2=1234425&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NumericTypesTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NumericTypesTest.java Sat Jan 21 22:01:25 2012
@@ -21,9 +21,7 @@ package org.apache.cayenne.access;
 
 import java.math.BigDecimal;
 import java.math.BigInteger;
-import java.util.Collections;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.configuration.server.ServerRuntime;
@@ -271,11 +269,11 @@ public class NumericTypesTest extends Se
         object.setDecimalPK(new BigDecimal("1.25"));
         context.commitChanges();
 
-        Map<String, BigDecimal> map = Collections.singletonMap(
+        ObjectId syntheticId = new ObjectId(
+                "DecimalPKTestEntity",
                 "DECIMAL_PK",
                 new BigDecimal("1.25"));
-        ObjectId syntheticId = new ObjectId("DecimalPKTestEntity", map);
-        assertSame(object, context.localObject(syntheticId, null));
+        assertSame(object, context.getGraphManager().getNode(syntheticId));
 
         context.deleteObjects(object);
         context.commitChanges();
@@ -290,9 +288,8 @@ public class NumericTypesTest extends Se
         object.setDecimalPK(new Double(1.25));
         context.commitChanges();
 
-        Map<String, Double> map = Collections
-                .singletonMap("DECIMAL_PK", new Double(1.25));
-        ObjectId syntheticId = new ObjectId("DecimalPKTest1", map);
-        assertSame(object, context.localObject(syntheticId, null));
+        ObjectId syntheticId = new ObjectId("DecimalPKTest1", "DECIMAL_PK", new Double(
+                1.25));
+        assertSame(object, context.getGraphManager().getNode(syntheticId));
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/ShallowMergeOperationTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/ShallowMergeOperationTest.java?rev=1234425&r1=1234424&r2=1234425&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/ShallowMergeOperationTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/ShallowMergeOperationTest.java Sat Jan 21 22:01:25 2012
@@ -18,11 +18,17 @@
  ****************************************************************/
 package org.apache.cayenne.util;
 
+import org.apache.cayenne.Cayenne;
 import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.PersistenceState;
+import org.apache.cayenne.Persistent;
 import org.apache.cayenne.access.DataContext;
 import org.apache.cayenne.configuration.server.ServerRuntime;
 import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.query.ObjectIdQuery;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.testmap.Artist;
 import org.apache.cayenne.testdo.testmap.Painting;
 import org.apache.cayenne.unit.di.DataChannelInterceptor;
@@ -35,14 +41,39 @@ public class ShallowMergeOperationTest e
 
     @Inject
     private ServerRuntime runtime;
-    
+
     @Inject
     private DataContext context;
 
     @Inject
     private DataChannelInterceptor queryInterceptor;
 
-    public void testLocalObjectRelationship() throws Exception {
+    @Inject
+    private DBHelper dbHelper;
+
+    private TableHelper tArtist;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("PAINTING_INFO");
+        dbHelper.deleteAll("PAINTING");
+        dbHelper.deleteAll("ARTIST_EXHIBIT");
+        dbHelper.deleteAll("ARTIST_GROUP");
+        dbHelper.deleteAll("ARTIST");
+
+        tArtist = new TableHelper(dbHelper, "ARTIST");
+        tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
+
+    }
+
+    private void createArtistsDataSet() throws Exception {
+        tArtist.insert(33001, "artist1");
+        tArtist.insert(33002, "artist2");
+        tArtist.insert(33003, "artist3");
+        tArtist.insert(33004, "artist4");
+    }
+
+    public void testMerge_Relationship() throws Exception {
 
         ObjectContext childContext = runtime.getContext(context);
         final ShallowMergeOperation op = new ShallowMergeOperation(childContext);
@@ -64,4 +95,116 @@ public class ShallowMergeOperationTest e
             }
         });
     }
+
+    public void testMerge_NoOverride() throws Exception {
+        createArtistsDataSet();
+
+        ObjectContext childContext = runtime.getContext(context);
+        final ShallowMergeOperation op = new ShallowMergeOperation(childContext);
+
+        int modifiedId = 33003;
+        final Artist modified = (Artist) Cayenne.objectForQuery(
+                context,
+                new ObjectIdQuery(new ObjectId(
+                        "Artist",
+                        Artist.ARTIST_ID_PK_COLUMN,
+                        modifiedId)));
+        final Artist peerModified = (Artist) Cayenne.objectForQuery(
+                childContext,
+                new ObjectIdQuery(new ObjectId(
+                        "Artist",
+                        Artist.ARTIST_ID_PK_COLUMN,
+                        modifiedId)));
+
+        modified.setArtistName("M1");
+        peerModified.setArtistName("M2");
+
+        assertEquals(PersistenceState.MODIFIED, modified.getPersistenceState());
+        assertEquals(PersistenceState.MODIFIED, peerModified.getPersistenceState());
+
+        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+            public void execute() {
+                Persistent peerModified2 = op.merge(modified);
+                assertSame(peerModified, peerModified2);
+                assertEquals(
+                        PersistenceState.MODIFIED,
+                        peerModified2.getPersistenceState());
+                assertEquals("M2", peerModified.getArtistName());
+                assertEquals("M1", modified.getArtistName());
+            }
+        });
+    }
+
+    public void testMerge_PersistenceStates() throws Exception {
+        createArtistsDataSet();
+
+        final ObjectContext childContext = runtime.getContext(context);
+        final ShallowMergeOperation op = new ShallowMergeOperation(childContext);
+
+        final Artist _new = context.newObject(Artist.class);
+
+        final Artist hollow = Cayenne.objectForPK(context, Artist.class, 33001);
+        context.invalidateObjects(hollow);
+
+        final Artist committed = Cayenne.objectForPK(context, Artist.class, 33002);
+
+        final Artist modified = Cayenne.objectForPK(context, Artist.class, 33003);
+        modified.setArtistName("M1");
+
+        final Artist deleted = Cayenne.objectForPK(context, Artist.class, 33004);
+        context.deleteObjects(deleted);
+
+        assertEquals(PersistenceState.HOLLOW, hollow.getPersistenceState());
+        assertEquals(PersistenceState.COMMITTED, committed.getPersistenceState());
+        assertEquals(PersistenceState.MODIFIED, modified.getPersistenceState());
+        assertEquals(PersistenceState.DELETED, deleted.getPersistenceState());
+        assertEquals(PersistenceState.NEW, _new.getPersistenceState());
+
+        // now check how objects in different state behave
+        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+            public void execute() {
+                Persistent newPeer = op.merge(_new);
+
+                assertEquals(_new.getObjectId(), newPeer.getObjectId());
+                assertEquals(PersistenceState.COMMITTED, newPeer.getPersistenceState());
+
+                assertSame(childContext, newPeer.getObjectContext());
+                assertSame(context, _new.getObjectContext());
+
+                Persistent hollowPeer = op.merge(hollow);
+                assertEquals(PersistenceState.HOLLOW, hollowPeer.getPersistenceState());
+                assertEquals(hollow.getObjectId(), hollowPeer.getObjectId());
+                assertSame(childContext, hollowPeer.getObjectContext());
+                assertSame(context, hollow.getObjectContext());
+
+                Persistent committedPeer = op.merge(committed);
+                assertEquals(
+                        PersistenceState.COMMITTED,
+                        committedPeer.getPersistenceState());
+                assertEquals(committed.getObjectId(), committedPeer.getObjectId());
+                assertSame(childContext, committedPeer.getObjectContext());
+                assertSame(context, committed.getObjectContext());
+
+                Artist modifiedPeer = op.merge(modified);
+                assertEquals(
+                        PersistenceState.COMMITTED,
+                        modifiedPeer.getPersistenceState());
+                assertEquals(modified.getObjectId(), modifiedPeer.getObjectId());
+                assertEquals("M1", modifiedPeer.getArtistName());
+                assertSame(childContext, modifiedPeer.getObjectContext());
+                assertSame(context, modified.getObjectContext());
+
+                Persistent deletedPeer = op.merge(deleted);
+                assertEquals(
+                        PersistenceState.COMMITTED,
+                        deletedPeer.getPersistenceState());
+                assertEquals(deleted.getObjectId(), deletedPeer.getObjectId());
+                assertSame(childContext, deletedPeer.getObjectContext());
+                assertSame(context, deleted.getObjectContext());
+
+            }
+        });
+    }
 }

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/ShallowMergeOperation_ClientTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/ShallowMergeOperation_ClientTest.java?rev=1234425&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/ShallowMergeOperation_ClientTest.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/util/ShallowMergeOperation_ClientTest.java Sat Jan 21 22:01:25 2012
@@ -0,0 +1,210 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.util;
+
+import org.apache.cayenne.Cayenne;
+import org.apache.cayenne.CayenneContext;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.PersistenceState;
+import org.apache.cayenne.Persistent;
+import org.apache.cayenne.configuration.rop.client.ClientRuntime;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.query.ObjectIdQuery;
+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.unit.di.DataChannelInterceptor;
+import org.apache.cayenne.unit.di.UnitTestClosure;
+import org.apache.cayenne.unit.di.client.ClientCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ClientCase.MULTI_TIER_PROJECT)
+public class ShallowMergeOperation_ClientTest extends ClientCase {
+
+    @Inject
+    private ClientRuntime runtime;
+
+    @Inject
+    private CayenneContext context;
+
+    @Inject
+    private DataChannelInterceptor queryInterceptor;
+
+    @Inject
+    private DBHelper dbHelper;
+
+    private TableHelper tMtTable1;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("MT_TABLE2");
+        dbHelper.deleteAll("MT_TABLE1");
+        dbHelper.deleteAll("MT_JOIN45");
+        dbHelper.deleteAll("MT_TABLE4");
+        dbHelper.deleteAll("MT_TABLE5");
+
+        tMtTable1 = new TableHelper(dbHelper, "MT_TABLE1");
+        tMtTable1.setColumns("TABLE1_ID", "GLOBAL_ATTRIBUTE1", "SERVER_ATTRIBUTE1");
+    }
+
+    private void createMtTable1DataSet() throws Exception {
+        tMtTable1.insert(33001, "g1", "s1");
+        tMtTable1.insert(33002, "g2", "s2");
+        tMtTable1.insert(33003, "g3", "s3");
+        tMtTable1.insert(33004, "g4", "s4");
+    }
+
+    public void testMerge_Relationship() throws Exception {
+
+        ObjectContext childContext = runtime.getContext(context);
+        final ShallowMergeOperation op = new ShallowMergeOperation(childContext);
+
+        ClientMtTable1 _new = context.newObject(ClientMtTable1.class);
+        final ClientMtTable2 _new2 = context.newObject(ClientMtTable2.class);
+        _new.addToTable2Array(_new2);
+
+        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+            public void execute() {
+                ClientMtTable2 child2 = op.merge(_new2);
+                assertEquals(PersistenceState.COMMITTED, child2.getPersistenceState());
+                assertNotNull(child2.getTable1());
+                assertEquals(PersistenceState.COMMITTED, child2
+                        .getTable1()
+                        .getPersistenceState());
+            }
+        });
+    }
+
+    public void testMerge_NoOverride() throws Exception {
+
+        ObjectContext childContext = runtime.getContext(context);
+        final ShallowMergeOperation op = new ShallowMergeOperation(childContext);
+
+        final ClientMtTable1 modified = context.newObject(ClientMtTable1.class);
+        context.commitChanges();
+
+        final ClientMtTable1 peerModified = (ClientMtTable1) Cayenne.objectForQuery(
+                childContext,
+                new ObjectIdQuery(modified.getObjectId()));
+
+        modified.setGlobalAttribute1("M1");
+        peerModified.setGlobalAttribute1("M2");
+
+        assertEquals(PersistenceState.MODIFIED, modified.getPersistenceState());
+        assertEquals(PersistenceState.MODIFIED, peerModified.getPersistenceState());
+
+        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+            public void execute() {
+                Persistent peerModified2 = op.merge(modified);
+                assertSame(peerModified, peerModified2);
+                assertEquals(
+                        PersistenceState.MODIFIED,
+                        peerModified2.getPersistenceState());
+                assertEquals("M2", peerModified.getGlobalAttribute1());
+                assertEquals("M1", modified.getGlobalAttribute1());
+            }
+        });
+    }
+
+    public void testMerge_PersistenceStates() throws Exception {
+
+        createMtTable1DataSet();
+
+        final ObjectContext childContext = runtime.getContext(context);
+        final ShallowMergeOperation op = new ShallowMergeOperation(childContext);
+
+        final ClientMtTable1 _new = context.newObject(ClientMtTable1.class);
+
+        final ClientMtTable1 hollow = Cayenne.objectForPK(
+                context,
+                ClientMtTable1.class,
+                33001);
+        context.invalidateObjects(hollow);
+
+        final ClientMtTable1 committed = Cayenne.objectForPK(
+                context,
+                ClientMtTable1.class,
+                33002);
+
+        final ClientMtTable1 modified = Cayenne.objectForPK(
+                context,
+                ClientMtTable1.class,
+                33003);
+        modified.setGlobalAttribute1("XXX");
+
+        final ClientMtTable1 deleted = Cayenne.objectForPK(
+                context,
+                ClientMtTable1.class,
+                33004);
+        context.deleteObjects(deleted);
+
+        assertEquals(PersistenceState.HOLLOW, hollow.getPersistenceState());
+        assertEquals(PersistenceState.COMMITTED, committed.getPersistenceState());
+        assertEquals(PersistenceState.MODIFIED, modified.getPersistenceState());
+        assertEquals(PersistenceState.DELETED, deleted.getPersistenceState());
+        assertEquals(PersistenceState.NEW, _new.getPersistenceState());
+
+        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+            public void execute() {
+                Persistent newPeer = op.merge(_new);
+
+                assertEquals(_new.getObjectId(), newPeer.getObjectId());
+                assertEquals(PersistenceState.COMMITTED, newPeer.getPersistenceState());
+
+                assertSame(childContext, newPeer.getObjectContext());
+                assertSame(context, _new.getObjectContext());
+
+                Persistent hollowPeer = op.merge(hollow);
+                assertEquals(PersistenceState.HOLLOW, hollowPeer.getPersistenceState());
+                assertEquals(hollow.getObjectId(), hollowPeer.getObjectId());
+                assertSame(childContext, hollowPeer.getObjectContext());
+                assertSame(context, hollow.getObjectContext());
+
+                Persistent committedPeer = op.merge(committed);
+                assertEquals(
+                        PersistenceState.COMMITTED,
+                        committedPeer.getPersistenceState());
+                assertEquals(committed.getObjectId(), committedPeer.getObjectId());
+                assertSame(childContext, committedPeer.getObjectContext());
+                assertSame(context, committed.getObjectContext());
+
+                ClientMtTable1 modifiedPeer = op.merge(modified);
+                assertEquals(
+                        PersistenceState.COMMITTED,
+                        modifiedPeer.getPersistenceState());
+                assertEquals(modified.getObjectId(), modifiedPeer.getObjectId());
+                assertEquals("XXX", modifiedPeer.getGlobalAttribute1());
+                assertSame(childContext, modifiedPeer.getObjectContext());
+                assertSame(context, modified.getObjectContext());
+
+                Persistent deletedPeer = op.merge(deleted);
+                assertEquals(
+                        PersistenceState.COMMITTED,
+                        deletedPeer.getPersistenceState());
+                assertEquals(deleted.getObjectId(), deletedPeer.getObjectId());
+                assertSame(childContext, deletedPeer.getObjectContext());
+                assertSame(context, deleted.getObjectContext());
+            }
+        });
+    }
+}



Mime
View raw message