cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject [5/8] Rename Integration Tests in cayenne-client (*IT.java instead of *Test.java)
Date Sun, 02 Nov 2014 07:39:01 GMT
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fcb1d536/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextTest.java
----------------------------------------------------------------------
diff --git a/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextTest.java b/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextTest.java
deleted file mode 100644
index 405036e..0000000
--- a/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextTest.java
+++ /dev/null
@@ -1,351 +0,0 @@
-/*****************************************************************
- *   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;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.event.DefaultEventManager;
-import org.apache.cayenne.event.EventManager;
-import org.apache.cayenne.event.MockEventManager;
-import org.apache.cayenne.graph.CompoundDiff;
-import org.apache.cayenne.graph.GraphDiff;
-import org.apache.cayenne.graph.MockGraphDiff;
-import org.apache.cayenne.graph.NodeIdChangeOperation;
-import org.apache.cayenne.map.DataMap;
-import org.apache.cayenne.map.EntityResolver;
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.query.Query;
-import org.apache.cayenne.remote.BootstrapMessage;
-import org.apache.cayenne.remote.ClientChannel;
-import org.apache.cayenne.remote.ClientConnection;
-import org.apache.cayenne.remote.ClientMessage;
-import org.apache.cayenne.testdo.mt.ClientMtTable1;
-import org.apache.cayenne.unit.di.client.ClientCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-import org.apache.cayenne.util.GenericResponse;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-@UseServerRuntime(ClientCase.MULTI_TIER_PROJECT)
-public class CayenneContextTest extends ClientCase {
-
-    @Inject
-    private ObjectContext serverContext;
-
-    public void testConstructor() {
-
-        CayenneContext context = new CayenneContext();
-
-        // test default property parameters
-        assertNotNull(context.getGraphManager());
-        assertNull(context.channel);
-
-        MockDataChannel channel = new MockDataChannel();
-        context.setChannel(channel);
-        assertSame(channel, context.getChannel());
-    }
-
-    public void testChannel() {
-        MockDataChannel channel = new MockDataChannel();
-        CayenneContext context = new CayenneContext(channel);
-
-        assertSame(channel, context.getChannel());
-    }
-
-    public void testCommitUnchanged() {
-
-        MockDataChannel channel = new MockDataChannel();
-        CayenneContext context = new CayenneContext(channel);
-
-        // no context changes so no connector access is expected
-        context.commitChanges();
-        assertTrue(channel.getRequestObjects().isEmpty());
-    }
-
-    public void testCommitCommandExecuted() {
-
-        MockDataChannel channel = new MockDataChannel(new MockGraphDiff());
-        channel.setEntityResolver(serverContext
-                .getEntityResolver()
-                .getClientEntityResolver());
-        CayenneContext context = new CayenneContext(channel);
-
-        // test that a command is being sent via connector on commit...
-
-        context.internalGraphManager().nodePropertyChanged(
-                new ObjectId("MtTable1"),
-                "x",
-                "y",
-                "z");
-
-        context.commitChanges();
-        assertEquals(1, channel.getRequestObjects().size());
-
-        // expect a sync/commit chain
-        Object mainMessage = channel.getRequestObjects().iterator().next();
-        assertTrue(mainMessage instanceof GraphDiff);
-    }
-
-    public void testCommitChangesNew() {
-        final CompoundDiff diff = new CompoundDiff();
-        final Object newObjectId = new ObjectId("test", "key", "generated");
-        final EventManager eventManager = new DefaultEventManager(0);
-
-        // test that ids that are passed back are actually propagated to the right
-        // objects...
-
-        MockDataChannel channel = new MockDataChannel() {
-
-            @Override
-            public GraphDiff onSync(
-                    ObjectContext originatingContext,
-                    GraphDiff changes,
-                    int syncType) {
-
-                return diff;
-            }
-
-            // must provide a channel with working event manager
-            @Override
-            public EventManager getEventManager() {
-                return eventManager;
-            }
-        };
-
-        CayenneContext context = new CayenneContext(channel);
-        ObjEntity entity = new ObjEntity("test_entity");
-        entity.setClassName(MockPersistentObject.class.getName());
-
-        DataMap dataMap = new DataMap("test");
-        dataMap.addObjEntity(entity);
-        Collection<DataMap> entities = Collections.singleton(dataMap);
-        context.setEntityResolver(new EntityResolver(entities));
-        Persistent object = context.newObject(MockPersistentObject.class);
-
-        // record change here to make it available to the anonymous connector method..
-        diff.add(new NodeIdChangeOperation(object.getObjectId(), newObjectId));
-
-        // check that a generated object ID is assigned back to the object...
-        assertNotSame(newObjectId, object.getObjectId());
-        context.commitChanges();
-        assertSame(newObjectId, object.getObjectId());
-        assertSame(object, context.graphManager.getNode(newObjectId));
-    }
-
-    public void testNewObject() {
-
-        CayenneContext context = new CayenneContext(new MockDataChannel());
-
-        ObjEntity entity = new ObjEntity("test_entity");
-        entity.setClassName(MockPersistentObject.class.getName());
-
-        DataMap dataMap = new DataMap("test");
-        dataMap.addObjEntity(entity);
-        Collection<DataMap> entities = Collections.singleton(dataMap);
-        context.setEntityResolver(new EntityResolver(entities));
-
-        Persistent object = context.newObject(MockPersistentObject.class);
-        assertNotNull(object);
-        assertTrue(object instanceof MockPersistentObject);
-        assertEquals(PersistenceState.NEW, object.getPersistenceState());
-        assertSame(context, object.getObjectContext());
-        assertTrue(context
-                .internalGraphManager()
-                .dirtyNodes(PersistenceState.NEW)
-                .contains(object));
-        assertNotNull(object.getObjectId());
-        assertTrue(object.getObjectId().isTemporary());
-    }
-
-    public void testDeleteObject() {
-
-        CayenneContext context = new CayenneContext(new MockDataChannel());
-        ObjEntity entity = new ObjEntity("test_entity");
-        entity.setClassName(MockPersistentObject.class.getName());
-
-        DataMap dataMap = new DataMap("test");
-        dataMap.addObjEntity(entity);
-        Collection<DataMap> entities = Collections.singleton(dataMap);
-        context.setEntityResolver(new EntityResolver(entities));
-
-        // TRANSIENT ... should quietly ignore it
-        Persistent transientObject = new MockPersistentObject();
-        context.deleteObjects(transientObject);
-        assertEquals(PersistenceState.TRANSIENT, transientObject.getPersistenceState());
-
-        // NEW ... should make it TRANSIENT
-        // create via context to make sure that object store would register it
-        Persistent newObject = context.newObject(MockPersistentObject.class);
-        assertNotNull(newObject.getObjectContext());
-        context.deleteObjects(newObject);
-        assertNull(newObject.getObjectContext());
-        assertEquals(PersistenceState.TRANSIENT, newObject.getPersistenceState());
-        assertFalse(context
-                .internalGraphManager()
-                .dirtyNodes()
-                .contains(newObject.getObjectId()));
-
-        // see CAY-547 for details...
-        assertFalse(context.internalGraphManager().dirtyNodes().contains(null));
-
-        // COMMITTED
-        Persistent committed = new MockPersistentObject();
-        committed.setPersistenceState(PersistenceState.COMMITTED);
-        committed.setObjectId(new ObjectId("test_entity", "key", "value1"));
-        committed.setObjectContext(context);
-        context.deleteObjects(committed);
-        assertEquals(PersistenceState.DELETED, committed.getPersistenceState());
-
-        // MODIFIED
-        Persistent modified = new MockPersistentObject();
-        modified.setPersistenceState(PersistenceState.MODIFIED);
-        modified.setObjectId(new ObjectId("test_entity", "key", "value2"));
-        modified.setObjectContext(context);
-        context.deleteObjects(modified);
-        assertEquals(PersistenceState.DELETED, modified.getPersistenceState());
-
-        // DELETED
-        Persistent deleted = new MockPersistentObject();
-        deleted.setPersistenceState(PersistenceState.DELETED);
-        deleted.setObjectId(new ObjectId("test_entity", "key", "value3"));
-        deleted.setObjectContext(context);
-        context.deleteObjects(deleted);
-        assertEquals(PersistenceState.DELETED, committed.getPersistenceState());
-    }
-
-    public void testBeforePropertyReadShouldInflateHollow() {
-
-        ObjectId gid = new ObjectId("MtTable1", "a", "b");
-        final ClientMtTable1 inflated = new ClientMtTable1();
-        inflated.setPersistenceState(PersistenceState.COMMITTED);
-        inflated.setObjectId(gid);
-        inflated.setGlobalAttribute1("abc");
-
-        ClientConnection connection = mock(ClientConnection.class);
-        when(connection.sendMessage((ClientMessage) any())).thenAnswer(
-                new Answer<Object>() {
-
-                    public Object answer(InvocationOnMock invocation) {
-                        ClientMessage arg = (ClientMessage) invocation.getArguments()[0];
-
-                        if (arg instanceof BootstrapMessage) {
-                            return new EntityResolver();
-                        }
-                        else {
-                            return new GenericResponse(Arrays.asList(inflated));
-                        }
-                    }
-                });
-
-        ClientChannel channel = new ClientChannel(
-                connection,
-                false,
-                new MockEventManager(),
-                false);
-
-        // check that a HOLLOW object is infalted on "beforePropertyRead"
-        ClientMtTable1 hollow = new ClientMtTable1();
-        hollow.setPersistenceState(PersistenceState.HOLLOW);
-        hollow.setObjectId(gid);
-
-        final boolean[] selectExecuted = new boolean[1];
-        CayenneContext context = new CayenneContext(channel) {
-
-            @Override
-            public List<?> performQuery(Query query) {
-                selectExecuted[0] = true;
-                return super.performQuery(query);
-            }
-        };
-
-        context.setEntityResolver(serverContext
-                .getEntityResolver()
-                .getClientEntityResolver());
-
-        context.graphManager.registerNode(hollow.getObjectId(), hollow);
-
-        // testing this...
-        context
-                .prepareForAccess(
-                        hollow,
-                        ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY,
-                        false);
-        assertTrue(selectExecuted[0]);
-        assertSame(hollow, context.getGraphManager().getNode(gid));
-        assertEquals(
-                inflated.getGlobalAttribute1Direct(),
-                hollow.getGlobalAttribute1Direct());
-        assertEquals(PersistenceState.COMMITTED, hollow.getPersistenceState());
-    }
-
-    public void testBeforeHollowDeleteShouldChangeStateToCommited() {
-
-        ObjectId gid = new ObjectId("MtTable1", "a", "b");
-        final ClientMtTable1 inflated = new ClientMtTable1();
-        inflated.setPersistenceState(PersistenceState.COMMITTED);
-        inflated.setObjectId(gid);
-        inflated.setGlobalAttribute1("abc");
-
-        ClientConnection connection = mock(ClientConnection.class);
-        when(connection.sendMessage((ClientMessage) any())).thenAnswer(
-                new Answer<Object>() {
-
-                    public Object answer(InvocationOnMock invocation) {
-                        ClientMessage arg = (ClientMessage) invocation.getArguments()[0];
-
-                        if (arg instanceof BootstrapMessage) {
-                            return new EntityResolver();
-                        }
-                        else {
-                            return new GenericResponse(Arrays.asList(inflated));
-                        }
-                    }
-                });
-        ClientChannel channel = new ClientChannel(
-                connection,
-                false,
-                new MockEventManager(),
-                false);
-
-        CayenneContext context = new CayenneContext(channel);
-        context.setEntityResolver(serverContext
-                .getEntityResolver()
-                .getClientEntityResolver());
-        ClientMtTable1 hollow = context.localObject(inflated);
-        assertEquals(PersistenceState.HOLLOW, hollow.getPersistenceState());
-
-        // testing this...
-        context.deleteObjects(hollow);
-        assertSame(hollow, context.getGraphManager().getNode(gid));
-        assertEquals(
-                inflated.getGlobalAttribute1Direct(),
-                hollow.getGlobalAttribute1Direct());
-        assertEquals(PersistenceState.DELETED, hollow.getPersistenceState());
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fcb1d536/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextValidationIT.java
----------------------------------------------------------------------
diff --git a/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextValidationIT.java b/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextValidationIT.java
new file mode 100644
index 0000000..f8e3c78
--- /dev/null
+++ b/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextValidationIT.java
@@ -0,0 +1,89 @@
+/*****************************************************************
+ *   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;
+
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.testdo.mt.ClientMtTable1;
+import org.apache.cayenne.testdo.mt.ClientMtTable2;
+import org.apache.cayenne.unit.di.client.ClientCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+import org.apache.cayenne.validation.ValidationException;
+
+@UseServerRuntime(ClientCase.MULTI_TIER_PROJECT)
+public class CayenneContextValidationIT extends ClientCase {
+
+    @Inject
+    private DBHelper dbHelper;
+
+    @Inject
+    private CayenneContext context;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("MT_TABLE2");
+        dbHelper.deleteAll("MT_TABLE1");
+    }
+
+    public void testValidate() throws Exception {
+
+        ClientMtTable1 o1 = context.newObject(ClientMtTable1.class);
+        o1.setGlobalAttribute1("G1");
+        o1.resetValidation(false);
+
+        // this one is not validating
+        ClientMtTable2 o2 = context.newObject(ClientMtTable2.class);
+        o2.setTable1(o1);
+
+        context.commitChanges();
+        assertTrue(o1.isValidatedForInsert());
+        assertFalse(o1.isValidatedForDelete());
+        assertFalse(o1.isValidatedForUpdate());
+
+        o1.resetValidation(false);
+        o1.setGlobalAttribute1("G2");
+
+        context.commitChanges();
+        assertFalse(o1.isValidatedForInsert());
+        assertFalse(o1.isValidatedForDelete());
+        assertTrue(o1.isValidatedForUpdate());
+
+        o1.resetValidation(false);
+        context.deleteObjects(o1);
+        context.deleteObjects(o2);
+
+        context.commitChanges();
+        assertFalse(o1.isValidatedForInsert());
+        assertTrue(o1.isValidatedForDelete());
+        assertFalse(o1.isValidatedForUpdate());
+
+        ClientMtTable1 o11 = context.newObject(ClientMtTable1.class);
+        o11.setGlobalAttribute1("G1");
+        o11.resetValidation(true);
+
+        try {
+            context.commitChanges();
+            fail("Validation failure must have prevented commit");
+        }
+        catch (ValidationException e) {
+            // expected
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fcb1d536/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextValidationTest.java
----------------------------------------------------------------------
diff --git a/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextValidationTest.java b/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextValidationTest.java
deleted file mode 100644
index fcac894..0000000
--- a/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextValidationTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*****************************************************************
- *   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;
-
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.test.jdbc.DBHelper;
-import org.apache.cayenne.testdo.mt.ClientMtTable1;
-import org.apache.cayenne.testdo.mt.ClientMtTable2;
-import org.apache.cayenne.unit.di.client.ClientCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-import org.apache.cayenne.validation.ValidationException;
-
-@UseServerRuntime(ClientCase.MULTI_TIER_PROJECT)
-public class CayenneContextValidationTest extends ClientCase {
-
-    @Inject
-    private DBHelper dbHelper;
-
-    @Inject
-    private CayenneContext context;
-
-    @Override
-    protected void setUpAfterInjection() throws Exception {
-        dbHelper.deleteAll("MT_TABLE2");
-        dbHelper.deleteAll("MT_TABLE1");
-    }
-
-    public void testValidate() throws Exception {
-
-        ClientMtTable1 o1 = context.newObject(ClientMtTable1.class);
-        o1.setGlobalAttribute1("G1");
-        o1.resetValidation(false);
-
-        // this one is not validating
-        ClientMtTable2 o2 = context.newObject(ClientMtTable2.class);
-        o2.setTable1(o1);
-
-        context.commitChanges();
-        assertTrue(o1.isValidatedForInsert());
-        assertFalse(o1.isValidatedForDelete());
-        assertFalse(o1.isValidatedForUpdate());
-
-        o1.resetValidation(false);
-        o1.setGlobalAttribute1("G2");
-
-        context.commitChanges();
-        assertFalse(o1.isValidatedForInsert());
-        assertFalse(o1.isValidatedForDelete());
-        assertTrue(o1.isValidatedForUpdate());
-
-        o1.resetValidation(false);
-        context.deleteObjects(o1);
-        context.deleteObjects(o2);
-
-        context.commitChanges();
-        assertFalse(o1.isValidatedForInsert());
-        assertTrue(o1.isValidatedForDelete());
-        assertFalse(o1.isValidatedForUpdate());
-
-        ClientMtTable1 o11 = context.newObject(ClientMtTable1.class);
-        o11.setGlobalAttribute1("G1");
-        o11.resetValidation(true);
-
-        try {
-            context.commitChanges();
-            fail("Validation failure must have prevented commit");
-        }
-        catch (ValidationException e) {
-            // expected
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fcb1d536/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextWithDataContextIT.java
----------------------------------------------------------------------
diff --git a/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextWithDataContextIT.java b/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextWithDataContextIT.java
new file mode 100644
index 0000000..a5cf087
--- /dev/null
+++ b/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextWithDataContextIT.java
@@ -0,0 +1,570 @@
+/*****************************************************************
+ *   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;
+
+import java.sql.Types;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.cayenne.access.ClientServerChannel;
+import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.map.LifecycleEvent;
+import org.apache.cayenne.query.ObjectIdQuery;
+import org.apache.cayenne.query.QueryCacheStrategy;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.query.SortOrder;
+import org.apache.cayenne.reflect.LifecycleCallbackRegistry;
+import org.apache.cayenne.remote.RemoteIncrementalFaultList;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
+import org.apache.cayenne.test.parallel.ParallelTestContainer;
+import org.apache.cayenne.testdo.mt.ClientMtMeaningfulPk;
+import org.apache.cayenne.testdo.mt.ClientMtReflexive;
+import org.apache.cayenne.testdo.mt.ClientMtTable1;
+import org.apache.cayenne.testdo.mt.ClientMtTable2;
+import org.apache.cayenne.testdo.mt.MtReflexive;
+import org.apache.cayenne.testdo.mt.MtTable1;
+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 CayenneContextWithDataContextIT extends ClientCase {
+
+    @Inject
+    private CayenneContext clientContext;
+
+    @Inject
+    private DBHelper dbHelper;
+
+    @Inject(ClientCase.ROP_CLIENT_KEY)
+    private DataChannelInterceptor clientServerInterceptor;
+
+    @Inject
+    private ClientServerChannel clientServerChannel;
+
+    private TableHelper tMtTable1;
+    private TableHelper tMtTable2;
+
+    private TableHelper tMtMeaningfulPK;
+
+    @Override
+    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").setColumnTypes(
+                Types.INTEGER, Types.INTEGER, Types.VARCHAR);
+
+        tMtMeaningfulPK = new TableHelper(dbHelper, "MT_MEANINGFUL_PK");
+        tMtMeaningfulPK.setColumns("PK");
+    }
+
+    private void deleteAndCreateTwoMeaningfulPKsDataSet() throws Exception {
+        tMtMeaningfulPK.deleteAll();
+        tMtMeaningfulPK.insert("A");
+        tMtMeaningfulPK.insert("B");
+    }
+
+    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");
+    }
+
+    private void createEightMtTable1s() throws Exception {
+        for (int i = 1; i <= 8; i++) {
+            tMtTable1.insert(i, "g" + i, "s" + i);
+        }
+    }
+
+    public void testLocalCacheStaysLocal() {
+
+        DataContext serverContext = (DataContext) clientServerChannel.getParentChannel();
+
+        SelectQuery query = new SelectQuery(ClientMtTable1.class);
+        query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
+
+        assertEquals(0, clientContext.getQueryCache().size());
+        assertEquals(0, serverContext.getQueryCache().size());
+
+        List<?> results = clientContext.performQuery(query);
+
+        assertEquals(1, clientContext.getQueryCache().size());
+        assertSame(results, clientContext.getQueryCache().get(
+                query.getMetaData(clientContext.getEntityResolver())));
+
+        assertEquals(0, serverContext.getQueryCache().size());
+    }
+
+    public void testAddToList() throws Exception {
+
+        ClientMtTable1 t1 = clientContext.newObject(ClientMtTable1.class);
+        ClientMtTable2 t2 = clientContext.newObject(ClientMtTable2.class);
+
+        t1.addToTable2Array(t2);
+        assertEquals(1, t1.getTable2Array().size());
+        assertSame(t1, t2.getTable1());
+
+        // do it again to make sure action can handle series of changes
+        ClientMtTable1 t3 = clientContext.newObject(ClientMtTable1.class);
+        ClientMtTable2 t4 = clientContext.newObject(ClientMtTable2.class);
+
+        t3.addToTable2Array(t4);
+        assertEquals(1, t3.getTable2Array().size());
+        assertSame(t3, t4.getTable1());
+    }
+
+    public void testSetValueHolder() throws Exception {
+
+        ClientMtTable1 t1 = clientContext.newObject(ClientMtTable1.class);
+        ClientMtTable2 t2 = clientContext.newObject(ClientMtTable2.class);
+
+        t2.setTable1(t1);
+        assertEquals(1, t1.getTable2Array().size());
+        assertSame(t1, t2.getTable1());
+    }
+
+    public void testPostAddCallback() throws Exception {
+
+        LifecycleCallbackRegistry callbackRegistry = clientServerChannel
+                .getEntityResolver()
+                .getCallbackRegistry();
+
+        final boolean[] flag = new boolean[1];
+
+        try {
+            callbackRegistry.addListener(MtTable1.class, new LifecycleListener() {
+
+                public void postLoad(Object entity) {
+                }
+
+                public void postPersist(Object entity) {
+                }
+
+                public void postRemove(Object entity) {
+                }
+
+                public void postUpdate(Object entity) {
+                }
+
+                public void postAdd(Object entity) {
+                    flag[0] = true;
+                }
+
+                public void preRemove(Object entity) {
+                }
+
+                public void preUpdate(Object entity) {
+                }
+
+                public void prePersist(Object entity) {
+                }
+            });
+
+            clientContext.newObject(ClientMtTable1.class);
+
+            assertFalse(flag[0]);
+            clientContext.commitChanges();
+            assertTrue(flag[0]);
+        }
+        finally {
+            callbackRegistry.clear();
+        }
+    }
+
+    public void testPostAddOnObjectCallback() throws Exception {
+
+        final DataContext serverContext = (DataContext) clientServerChannel.getParentChannel();
+
+        LifecycleCallbackRegistry callbackRegistry = serverContext
+                .getEntityResolver()
+                .getCallbackRegistry();
+
+        try {
+            callbackRegistry.addCallback(
+                    LifecycleEvent.POST_ADD,
+                    MtTable1.class,
+                    "prePersistMethod");
+
+            final Persistent clientObject = clientContext.newObject(ClientMtTable1.class);
+            clientContext.commitChanges();
+
+        new ParallelTestContainer() {
+
+            @Override
+            protected void assertResult() throws Exception {
+            	// find peer
+            	MtTable1 peer = (MtTable1) serverContext.getGraphManager().getNode(
+                    clientObject.getObjectId());
+
+            	assertNotNull(peer);
+            	assertTrue(peer.isPrePersisted());
+            }
+        }.runTest(1000);
+
+
+        }
+        finally {
+            callbackRegistry.clear();
+        }
+    }
+
+    public void testPreRemoveCallback() throws Exception {
+
+        // an exception was triggered within POST_LOAD callback
+        LifecycleCallbackRegistry callbackRegistry = clientServerChannel
+                .getEntityResolver()
+                .getCallbackRegistry();
+
+        final boolean[] flag = new boolean[1];
+
+        try {
+            callbackRegistry.addListener(MtTable1.class, new LifecycleListener() {
+
+                public void postLoad(Object entity) {
+                }
+
+                public void postPersist(Object entity) {
+                }
+
+                public void postRemove(Object entity) {
+                }
+
+                public void postUpdate(Object entity) {
+                }
+
+                public void postAdd(Object entity) {
+                }
+
+                public void preRemove(Object entity) {
+                    flag[0] = true;
+                }
+
+                public void preUpdate(Object entity) {
+                }
+
+                public void prePersist(Object entity) {
+                }
+            });
+
+            ClientMtTable1 object = clientContext.newObject(ClientMtTable1.class);
+
+            assertFalse(flag[0]);
+            clientContext.commitChanges();
+            assertFalse(flag[0]);
+
+            clientContext.deleteObjects(object);
+            clientContext.commitChanges();
+            assertTrue(flag[0]);
+        }
+        finally {
+            callbackRegistry.clear();
+        }
+    }
+
+    public void testCAY830() throws Exception {
+
+        // an exception was triggered within POST_LOAD callback
+        LifecycleCallbackRegistry callbackRegistry = clientServerChannel
+                .getEntityResolver()
+                .getCallbackRegistry();
+
+        try {
+            callbackRegistry.addListener(MtReflexive.class, new LifecycleListener() {
+
+                public void postLoad(Object entity) {
+                }
+
+                public void postPersist(Object entity) {
+                }
+
+                public void postRemove(Object entity) {
+                }
+
+                public void postUpdate(Object entity) {
+                }
+
+                public void postAdd(Object entity) {
+                }
+
+                public void preRemove(Object entity) {
+                }
+
+                public void preUpdate(Object entity) {
+                }
+
+                public void prePersist(Object entity) {
+                }
+            });
+
+            ClientMtReflexive o1 = clientContext.newObject(ClientMtReflexive.class);
+            o1.setName("parent");
+
+            ClientMtReflexive o2 = clientContext.newObject(ClientMtReflexive.class);
+            o2.setName("child");
+            o2.setToParent(o1);
+            clientContext.commitChanges();
+
+            clientContext.deleteObjects(o1);
+            clientContext.deleteObjects(o2);
+            clientContext.commitChanges();
+            // per CAY-830 an exception is thrown here
+        }
+        finally {
+            callbackRegistry.clear();
+        }
+    }
+
+    public void testRollbackChanges() throws Exception {
+
+        ClientMtTable1 o = clientContext.newObject(ClientMtTable1.class);
+        o.setGlobalAttribute1("1");
+        clientContext.commitChanges();
+
+        assertEquals("1", o.getGlobalAttribute1());
+        o.setGlobalAttribute1("2");
+        assertEquals("2", o.getGlobalAttribute1());
+        clientContext.rollbackChanges();
+
+        assertEquals("1", o.getGlobalAttribute1());
+        assertTrue(clientContext.modifiedObjects().isEmpty());
+    }
+
+    public void testCreateFault() throws Exception {
+        tMtTable1.insert(1, "g1", "s1");
+
+        ObjectId id = new ObjectId("MtTable1", MtTable1.TABLE1_ID_PK_COLUMN, 1);
+
+        Object fault = clientContext.createFault(id);
+        assertTrue(fault instanceof ClientMtTable1);
+
+        ClientMtTable1 o = (ClientMtTable1) fault;
+        assertEquals(PersistenceState.HOLLOW, o.getPersistenceState());
+        assertSame(clientContext, o.getObjectContext());
+        assertNull(o.getGlobalAttribute1Direct());
+
+        // make sure we haven't tripped the fault yet
+        assertEquals(PersistenceState.HOLLOW, o.getPersistenceState());
+
+        // try tripping fault
+        assertEquals("g1", o.getGlobalAttribute1());
+        assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
+    }
+
+    public void testCreateBadFault() throws Exception {
+        tMtTable1.insert(1, "g1", "s1");
+
+        ObjectId id = new ObjectId("MtTable1", MtTable1.TABLE1_ID_PK_COLUMN, 2);
+
+        Object fault = clientContext.createFault(id);
+        assertTrue(fault instanceof ClientMtTable1);
+
+        ClientMtTable1 o = (ClientMtTable1) fault;
+
+        // try tripping fault
+        try {
+            o.getGlobalAttribute1();
+            fail("resolving bad fault should've thrown");
+        }
+        catch (FaultFailureException e) {
+            // expected
+        }
+    }
+
+    public void testMeaningfulPK() throws Exception {
+        deleteAndCreateTwoMeaningfulPKsDataSet();
+
+        SelectQuery query = new SelectQuery(ClientMtMeaningfulPk.class);
+        query.addOrdering(ClientMtMeaningfulPk.PK_PROPERTY, SortOrder.DESCENDING);
+
+        List<?> results = clientContext.performQuery(query);
+        assertEquals(2, results.size());
+    }
+
+    public void testPrefetchingToOne() throws Exception {
+        createTwoMtTable1sAnd2sDataSet();
+
+        final ObjectId prefetchedId = new ObjectId(
+                "MtTable1",
+                MtTable1.TABLE1_ID_PK_COLUMN,
+                1);
+
+        SelectQuery q = new SelectQuery(ClientMtTable2.class);
+        q.addOrdering(ClientMtTable2.GLOBAL_ATTRIBUTE_PROPERTY, SortOrder.ASCENDING);
+        q.addPrefetch(ClientMtTable2.TABLE1_PROPERTY);
+
+        final List<ClientMtTable2> results = clientContext.performQuery(q);
+
+        clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+            public void execute() {
+                assertEquals(2, results.size());
+
+                for (ClientMtTable2 o : results) {
+                    assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
+                    assertSame(clientContext, o.getObjectContext());
+
+                    ClientMtTable1 o1 = o.getTable1();
+                    assertNotNull(o1);
+                    assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
+                    assertSame(clientContext, o1.getObjectContext());
+                    assertEquals(prefetchedId, o1.getObjectId());
+                }
+            }
+        });
+    }
+
+    public void testPrefetchingToOneNull() throws Exception {
+        tMtTable2.insert(15, null, "g3");
+
+        SelectQuery q = new SelectQuery(ClientMtTable2.class);
+        q.addPrefetch(ClientMtTable2.TABLE1_PROPERTY);
+
+        final List<ClientMtTable2> results = clientContext.performQuery(q);
+
+        clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+            public void execute() {
+
+                assertEquals(1, results.size());
+
+                ClientMtTable2 o = results.get(0);
+                assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
+                assertSame(clientContext, o.getObjectContext());
+
+                assertNull(o.getTable1());
+            }
+        });
+    }
+
+    public void testPrefetchingToMany() throws Exception {
+        createTwoMtTable1sAnd2sDataSet();
+
+        SelectQuery q = new SelectQuery(ClientMtTable1.class);
+        q.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.ASCENDING);
+        q.addPrefetch(ClientMtTable1.TABLE2ARRAY_PROPERTY);
+
+        final List<ClientMtTable1> results = clientContext.performQuery(q);
+
+        clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+            public void execute() {
+
+                ClientMtTable1 o1 = results.get(0);
+                assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
+                assertSame(clientContext, o1.getObjectContext());
+
+                List<?> children1 = o1.getTable2Array();
+
+                assertEquals(2, children1.size());
+                Iterator<?> it = children1.iterator();
+                while (it.hasNext()) {
+                    ClientMtTable2 o = (ClientMtTable2) it.next();
+                    assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
+                    assertSame(clientContext, o.getObjectContext());
+
+                    // TODO: fixme... reverse relationship is not connected and will
+                    // cause a fetch
+                    // assertEquals(o1, o.getTable1());
+                }
+            }
+        });
+    }
+
+    public void testPerformPaginatedQuery() throws Exception {
+        createEightMtTable1s();
+
+        SelectQuery query = new SelectQuery(ClientMtTable1.class);
+        query.setPageSize(5);
+        List<ClientMtTable1> objects = clientContext.performQuery(query);
+        assertNotNull(objects);
+        assertTrue(objects instanceof RemoteIncrementalFaultList);
+    }
+
+    public void testPrefetchingToManyEmpty() throws Exception {
+        createTwoMtTable1sAnd2sDataSet();
+
+        SelectQuery q = new SelectQuery(ClientMtTable1.class);
+        q.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.ASCENDING);
+        q.addPrefetch(ClientMtTable1.TABLE2ARRAY_PROPERTY);
+
+        final List<ClientMtTable1> results = clientContext.performQuery(q);
+
+        clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+            public void execute() {
+                ClientMtTable1 o2 = results.get(1);
+                assertEquals(PersistenceState.COMMITTED, o2.getPersistenceState());
+                assertSame(clientContext, o2.getObjectContext());
+
+                List<ClientMtTable2> children2 = o2.getTable2Array();
+                assertFalse(((ValueHolder) children2).isFault());
+                assertEquals(0, children2.size());
+            }
+        });
+    }
+
+    public void testOIDQueryInterception() throws Exception {
+
+        final ClientMtTable1 o = clientContext.newObject(ClientMtTable1.class);
+        o.setGlobalAttribute1("aaa");
+
+        // fetch new
+        final ObjectIdQuery q1 = new ObjectIdQuery(
+                o.getObjectId(),
+                false,
+                ObjectIdQuery.CACHE);
+
+        clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+            public void execute() {
+                List<?> objects = clientContext.performQuery(q1);
+                assertEquals(1, objects.size());
+                assertSame(o, objects.get(0));
+            }
+        });
+
+        clientContext.commitChanges();
+
+        // fetch committed
+        final ObjectIdQuery q2 = new ObjectIdQuery(
+                o.getObjectId(),
+                false,
+                ObjectIdQuery.CACHE);
+
+        clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+            public void execute() {
+                List<?> objects = clientContext.performQuery(q2);
+                assertEquals(1, objects.size());
+                assertSame(o, objects.get(0));
+            }
+        });
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fcb1d536/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextWithDataContextTest.java
----------------------------------------------------------------------
diff --git a/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextWithDataContextTest.java b/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextWithDataContextTest.java
deleted file mode 100644
index c9b45a2..0000000
--- a/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextWithDataContextTest.java
+++ /dev/null
@@ -1,570 +0,0 @@
-/*****************************************************************
- *   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;
-
-import java.sql.Types;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.cayenne.access.ClientServerChannel;
-import org.apache.cayenne.access.DataContext;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.map.LifecycleEvent;
-import org.apache.cayenne.query.ObjectIdQuery;
-import org.apache.cayenne.query.QueryCacheStrategy;
-import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.query.SortOrder;
-import org.apache.cayenne.reflect.LifecycleCallbackRegistry;
-import org.apache.cayenne.remote.RemoteIncrementalFaultList;
-import org.apache.cayenne.test.jdbc.DBHelper;
-import org.apache.cayenne.test.jdbc.TableHelper;
-import org.apache.cayenne.test.parallel.ParallelTestContainer;
-import org.apache.cayenne.testdo.mt.ClientMtMeaningfulPk;
-import org.apache.cayenne.testdo.mt.ClientMtReflexive;
-import org.apache.cayenne.testdo.mt.ClientMtTable1;
-import org.apache.cayenne.testdo.mt.ClientMtTable2;
-import org.apache.cayenne.testdo.mt.MtReflexive;
-import org.apache.cayenne.testdo.mt.MtTable1;
-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 CayenneContextWithDataContextTest extends ClientCase {
-
-    @Inject
-    private CayenneContext clientContext;
-
-    @Inject
-    private DBHelper dbHelper;
-
-    @Inject(ClientCase.ROP_CLIENT_KEY)
-    private DataChannelInterceptor clientServerInterceptor;
-
-    @Inject
-    private ClientServerChannel clientServerChannel;
-
-    private TableHelper tMtTable1;
-    private TableHelper tMtTable2;
-
-    private TableHelper tMtMeaningfulPK;
-
-    @Override
-    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").setColumnTypes(
-                Types.INTEGER, Types.INTEGER, Types.VARCHAR);
-
-        tMtMeaningfulPK = new TableHelper(dbHelper, "MT_MEANINGFUL_PK");
-        tMtMeaningfulPK.setColumns("PK");
-    }
-
-    private void deleteAndCreateTwoMeaningfulPKsDataSet() throws Exception {
-        tMtMeaningfulPK.deleteAll();
-        tMtMeaningfulPK.insert("A");
-        tMtMeaningfulPK.insert("B");
-    }
-
-    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");
-    }
-
-    private void createEightMtTable1s() throws Exception {
-        for (int i = 1; i <= 8; i++) {
-            tMtTable1.insert(i, "g" + i, "s" + i);
-        }
-    }
-
-    public void testLocalCacheStaysLocal() {
-
-        DataContext serverContext = (DataContext) clientServerChannel.getParentChannel();
-
-        SelectQuery query = new SelectQuery(ClientMtTable1.class);
-        query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
-
-        assertEquals(0, clientContext.getQueryCache().size());
-        assertEquals(0, serverContext.getQueryCache().size());
-
-        List<?> results = clientContext.performQuery(query);
-
-        assertEquals(1, clientContext.getQueryCache().size());
-        assertSame(results, clientContext.getQueryCache().get(
-                query.getMetaData(clientContext.getEntityResolver())));
-
-        assertEquals(0, serverContext.getQueryCache().size());
-    }
-
-    public void testAddToList() throws Exception {
-
-        ClientMtTable1 t1 = clientContext.newObject(ClientMtTable1.class);
-        ClientMtTable2 t2 = clientContext.newObject(ClientMtTable2.class);
-
-        t1.addToTable2Array(t2);
-        assertEquals(1, t1.getTable2Array().size());
-        assertSame(t1, t2.getTable1());
-
-        // do it again to make sure action can handle series of changes
-        ClientMtTable1 t3 = clientContext.newObject(ClientMtTable1.class);
-        ClientMtTable2 t4 = clientContext.newObject(ClientMtTable2.class);
-
-        t3.addToTable2Array(t4);
-        assertEquals(1, t3.getTable2Array().size());
-        assertSame(t3, t4.getTable1());
-    }
-
-    public void testSetValueHolder() throws Exception {
-
-        ClientMtTable1 t1 = clientContext.newObject(ClientMtTable1.class);
-        ClientMtTable2 t2 = clientContext.newObject(ClientMtTable2.class);
-
-        t2.setTable1(t1);
-        assertEquals(1, t1.getTable2Array().size());
-        assertSame(t1, t2.getTable1());
-    }
-
-    public void testPostAddCallback() throws Exception {
-
-        LifecycleCallbackRegistry callbackRegistry = clientServerChannel
-                .getEntityResolver()
-                .getCallbackRegistry();
-
-        final boolean[] flag = new boolean[1];
-
-        try {
-            callbackRegistry.addListener(MtTable1.class, new LifecycleListener() {
-
-                public void postLoad(Object entity) {
-                }
-
-                public void postPersist(Object entity) {
-                }
-
-                public void postRemove(Object entity) {
-                }
-
-                public void postUpdate(Object entity) {
-                }
-
-                public void postAdd(Object entity) {
-                    flag[0] = true;
-                }
-
-                public void preRemove(Object entity) {
-                }
-
-                public void preUpdate(Object entity) {
-                }
-
-                public void prePersist(Object entity) {
-                }
-            });
-
-            clientContext.newObject(ClientMtTable1.class);
-
-            assertFalse(flag[0]);
-            clientContext.commitChanges();
-            assertTrue(flag[0]);
-        }
-        finally {
-            callbackRegistry.clear();
-        }
-    }
-
-    public void testPostAddOnObjectCallback() throws Exception {
-
-        final DataContext serverContext = (DataContext) clientServerChannel.getParentChannel();
-
-        LifecycleCallbackRegistry callbackRegistry = serverContext
-                .getEntityResolver()
-                .getCallbackRegistry();
-
-        try {
-            callbackRegistry.addCallback(
-                    LifecycleEvent.POST_ADD,
-                    MtTable1.class,
-                    "prePersistMethod");
-
-            final Persistent clientObject = clientContext.newObject(ClientMtTable1.class);
-            clientContext.commitChanges();
-
-        new ParallelTestContainer() {
-
-            @Override
-            protected void assertResult() throws Exception {
-            	// find peer
-            	MtTable1 peer = (MtTable1) serverContext.getGraphManager().getNode(
-                    clientObject.getObjectId());
-
-            	assertNotNull(peer);
-            	assertTrue(peer.isPrePersisted());
-            }
-        }.runTest(1000);
-
-
-        }
-        finally {
-            callbackRegistry.clear();
-        }
-    }
-
-    public void testPreRemoveCallback() throws Exception {
-
-        // an exception was triggered within POST_LOAD callback
-        LifecycleCallbackRegistry callbackRegistry = clientServerChannel
-                .getEntityResolver()
-                .getCallbackRegistry();
-
-        final boolean[] flag = new boolean[1];
-
-        try {
-            callbackRegistry.addListener(MtTable1.class, new LifecycleListener() {
-
-                public void postLoad(Object entity) {
-                }
-
-                public void postPersist(Object entity) {
-                }
-
-                public void postRemove(Object entity) {
-                }
-
-                public void postUpdate(Object entity) {
-                }
-
-                public void postAdd(Object entity) {
-                }
-
-                public void preRemove(Object entity) {
-                    flag[0] = true;
-                }
-
-                public void preUpdate(Object entity) {
-                }
-
-                public void prePersist(Object entity) {
-                }
-            });
-
-            ClientMtTable1 object = clientContext.newObject(ClientMtTable1.class);
-
-            assertFalse(flag[0]);
-            clientContext.commitChanges();
-            assertFalse(flag[0]);
-
-            clientContext.deleteObjects(object);
-            clientContext.commitChanges();
-            assertTrue(flag[0]);
-        }
-        finally {
-            callbackRegistry.clear();
-        }
-    }
-
-    public void testCAY830() throws Exception {
-
-        // an exception was triggered within POST_LOAD callback
-        LifecycleCallbackRegistry callbackRegistry = clientServerChannel
-                .getEntityResolver()
-                .getCallbackRegistry();
-
-        try {
-            callbackRegistry.addListener(MtReflexive.class, new LifecycleListener() {
-
-                public void postLoad(Object entity) {
-                }
-
-                public void postPersist(Object entity) {
-                }
-
-                public void postRemove(Object entity) {
-                }
-
-                public void postUpdate(Object entity) {
-                }
-
-                public void postAdd(Object entity) {
-                }
-
-                public void preRemove(Object entity) {
-                }
-
-                public void preUpdate(Object entity) {
-                }
-
-                public void prePersist(Object entity) {
-                }
-            });
-
-            ClientMtReflexive o1 = clientContext.newObject(ClientMtReflexive.class);
-            o1.setName("parent");
-
-            ClientMtReflexive o2 = clientContext.newObject(ClientMtReflexive.class);
-            o2.setName("child");
-            o2.setToParent(o1);
-            clientContext.commitChanges();
-
-            clientContext.deleteObjects(o1);
-            clientContext.deleteObjects(o2);
-            clientContext.commitChanges();
-            // per CAY-830 an exception is thrown here
-        }
-        finally {
-            callbackRegistry.clear();
-        }
-    }
-
-    public void testRollbackChanges() throws Exception {
-
-        ClientMtTable1 o = clientContext.newObject(ClientMtTable1.class);
-        o.setGlobalAttribute1("1");
-        clientContext.commitChanges();
-
-        assertEquals("1", o.getGlobalAttribute1());
-        o.setGlobalAttribute1("2");
-        assertEquals("2", o.getGlobalAttribute1());
-        clientContext.rollbackChanges();
-
-        assertEquals("1", o.getGlobalAttribute1());
-        assertTrue(clientContext.modifiedObjects().isEmpty());
-    }
-
-    public void testCreateFault() throws Exception {
-        tMtTable1.insert(1, "g1", "s1");
-
-        ObjectId id = new ObjectId("MtTable1", MtTable1.TABLE1_ID_PK_COLUMN, 1);
-
-        Object fault = clientContext.createFault(id);
-        assertTrue(fault instanceof ClientMtTable1);
-
-        ClientMtTable1 o = (ClientMtTable1) fault;
-        assertEquals(PersistenceState.HOLLOW, o.getPersistenceState());
-        assertSame(clientContext, o.getObjectContext());
-        assertNull(o.getGlobalAttribute1Direct());
-
-        // make sure we haven't tripped the fault yet
-        assertEquals(PersistenceState.HOLLOW, o.getPersistenceState());
-
-        // try tripping fault
-        assertEquals("g1", o.getGlobalAttribute1());
-        assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
-    }
-
-    public void testCreateBadFault() throws Exception {
-        tMtTable1.insert(1, "g1", "s1");
-
-        ObjectId id = new ObjectId("MtTable1", MtTable1.TABLE1_ID_PK_COLUMN, 2);
-
-        Object fault = clientContext.createFault(id);
-        assertTrue(fault instanceof ClientMtTable1);
-
-        ClientMtTable1 o = (ClientMtTable1) fault;
-
-        // try tripping fault
-        try {
-            o.getGlobalAttribute1();
-            fail("resolving bad fault should've thrown");
-        }
-        catch (FaultFailureException e) {
-            // expected
-        }
-    }
-
-    public void testMeaningfulPK() throws Exception {
-        deleteAndCreateTwoMeaningfulPKsDataSet();
-
-        SelectQuery query = new SelectQuery(ClientMtMeaningfulPk.class);
-        query.addOrdering(ClientMtMeaningfulPk.PK_PROPERTY, SortOrder.DESCENDING);
-
-        List<?> results = clientContext.performQuery(query);
-        assertEquals(2, results.size());
-    }
-
-    public void testPrefetchingToOne() throws Exception {
-        createTwoMtTable1sAnd2sDataSet();
-
-        final ObjectId prefetchedId = new ObjectId(
-                "MtTable1",
-                MtTable1.TABLE1_ID_PK_COLUMN,
-                1);
-
-        SelectQuery q = new SelectQuery(ClientMtTable2.class);
-        q.addOrdering(ClientMtTable2.GLOBAL_ATTRIBUTE_PROPERTY, SortOrder.ASCENDING);
-        q.addPrefetch(ClientMtTable2.TABLE1_PROPERTY);
-
-        final List<ClientMtTable2> results = clientContext.performQuery(q);
-
-        clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
-
-            public void execute() {
-                assertEquals(2, results.size());
-
-                for (ClientMtTable2 o : results) {
-                    assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
-                    assertSame(clientContext, o.getObjectContext());
-
-                    ClientMtTable1 o1 = o.getTable1();
-                    assertNotNull(o1);
-                    assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
-                    assertSame(clientContext, o1.getObjectContext());
-                    assertEquals(prefetchedId, o1.getObjectId());
-                }
-            }
-        });
-    }
-
-    public void testPrefetchingToOneNull() throws Exception {
-        tMtTable2.insert(15, null, "g3");
-
-        SelectQuery q = new SelectQuery(ClientMtTable2.class);
-        q.addPrefetch(ClientMtTable2.TABLE1_PROPERTY);
-
-        final List<ClientMtTable2> results = clientContext.performQuery(q);
-
-        clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
-
-            public void execute() {
-
-                assertEquals(1, results.size());
-
-                ClientMtTable2 o = results.get(0);
-                assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
-                assertSame(clientContext, o.getObjectContext());
-
-                assertNull(o.getTable1());
-            }
-        });
-    }
-
-    public void testPrefetchingToMany() throws Exception {
-        createTwoMtTable1sAnd2sDataSet();
-
-        SelectQuery q = new SelectQuery(ClientMtTable1.class);
-        q.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.ASCENDING);
-        q.addPrefetch(ClientMtTable1.TABLE2ARRAY_PROPERTY);
-
-        final List<ClientMtTable1> results = clientContext.performQuery(q);
-
-        clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
-
-            public void execute() {
-
-                ClientMtTable1 o1 = results.get(0);
-                assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
-                assertSame(clientContext, o1.getObjectContext());
-
-                List<?> children1 = o1.getTable2Array();
-
-                assertEquals(2, children1.size());
-                Iterator<?> it = children1.iterator();
-                while (it.hasNext()) {
-                    ClientMtTable2 o = (ClientMtTable2) it.next();
-                    assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
-                    assertSame(clientContext, o.getObjectContext());
-
-                    // TODO: fixme... reverse relationship is not connected and will
-                    // cause a fetch
-                    // assertEquals(o1, o.getTable1());
-                }
-            }
-        });
-    }
-
-    public void testPerformPaginatedQuery() throws Exception {
-        createEightMtTable1s();
-
-        SelectQuery query = new SelectQuery(ClientMtTable1.class);
-        query.setPageSize(5);
-        List<ClientMtTable1> objects = clientContext.performQuery(query);
-        assertNotNull(objects);
-        assertTrue(objects instanceof RemoteIncrementalFaultList);
-    }
-
-    public void testPrefetchingToManyEmpty() throws Exception {
-        createTwoMtTable1sAnd2sDataSet();
-
-        SelectQuery q = new SelectQuery(ClientMtTable1.class);
-        q.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.ASCENDING);
-        q.addPrefetch(ClientMtTable1.TABLE2ARRAY_PROPERTY);
-
-        final List<ClientMtTable1> results = clientContext.performQuery(q);
-
-        clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
-
-            public void execute() {
-                ClientMtTable1 o2 = results.get(1);
-                assertEquals(PersistenceState.COMMITTED, o2.getPersistenceState());
-                assertSame(clientContext, o2.getObjectContext());
-
-                List<ClientMtTable2> children2 = o2.getTable2Array();
-                assertFalse(((ValueHolder) children2).isFault());
-                assertEquals(0, children2.size());
-            }
-        });
-    }
-
-    public void testOIDQueryInterception() throws Exception {
-
-        final ClientMtTable1 o = clientContext.newObject(ClientMtTable1.class);
-        o.setGlobalAttribute1("aaa");
-
-        // fetch new
-        final ObjectIdQuery q1 = new ObjectIdQuery(
-                o.getObjectId(),
-                false,
-                ObjectIdQuery.CACHE);
-
-        clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
-
-            public void execute() {
-                List<?> objects = clientContext.performQuery(q1);
-                assertEquals(1, objects.size());
-                assertSame(o, objects.get(0));
-            }
-        });
-
-        clientContext.commitChanges();
-
-        // fetch committed
-        final ObjectIdQuery q2 = new ObjectIdQuery(
-                o.getObjectId(),
-                false,
-                ObjectIdQuery.CACHE);
-
-        clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
-
-            public void execute() {
-                List<?> objects = clientContext.performQuery(q2);
-                assertEquals(1, objects.size());
-                assertSame(o, objects.get(0));
-            }
-        });
-    }
-}


Mime
View raw message