cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject [41/48] Installing Maven Failsafe Plugin
Date Sun, 02 Nov 2014 07:10:29 GMT
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextClobTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextClobTest.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextClobTest.java
deleted file mode 100644
index 1d31ea3..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextClobTest.java
+++ /dev/null
@@ -1,158 +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.access;
-
-import java.util.List;
-
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.test.jdbc.DBHelper;
-import org.apache.cayenne.testdo.testmap.ClobTestEntity;
-import org.apache.cayenne.unit.UnitDbAdapter;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class DataContextClobTest extends ServerCase {
-
-    @Inject
-    private DataContext context;
-
-    @Inject
-    private DataContext context2;
-
-    @Inject
-    private DataContext context3;
-
-    @Inject
-    private UnitDbAdapter accessStackAdapter;
-
-    @Inject
-    private DBHelper dbHelper;
-
-    @Override
-    protected void setUpAfterInjection() throws Exception {
-        if (accessStackAdapter.supportsLobs()) {
-            dbHelper.deleteAll("CLOB_TEST");
-        }
-    }
-
-    private boolean skipTests() {
-        return !accessStackAdapter.supportsLobs();
-    }
-
-    private boolean skipEmptyLOBTests() {
-        return !accessStackAdapter.handlesNullVsEmptyLOBs();
-    }
-
-    public void testEmptyClob() throws Exception {
-        if (skipEmptyLOBTests()) {
-            return;
-        }
-        runWithClobSize(0);
-    }
-
-    public void test5ByteClob() throws Exception {
-        if (skipTests()) {
-            return;
-        }
-        runWithClobSize(5);
-    }
-
-    public void test5KByteClob() throws Exception {
-        if (skipTests()) {
-            return;
-        }
-        runWithClobSize(5 * 1024);
-    }
-
-    public void test1MBClob() throws Exception {
-        if (skipTests()) {
-            return;
-        }
-        runWithClobSize(1024 * 1024);
-    }
-
-    public void testNullClob() throws Exception {
-        if (skipTests()) {
-            return;
-        }
-
-        // insert new clob
-        context.newObject(ClobTestEntity.class);
-        context.commitChanges();
-
-        // read the CLOB in the new context
-        List<?> objects2 = context2.performQuery(new SelectQuery(ClobTestEntity.class));
-        assertEquals(1, objects2.size());
-
-        ClobTestEntity clobObj2 = (ClobTestEntity) objects2.get(0);
-        assertNull("Expected null, got: '" + clobObj2.getClobCol() + "'", clobObj2
-                .getClobCol());
-
-        // update and save Clob
-        clobObj2.setClobCol("updated rather small clob...");
-        context2.commitChanges();
-
-        // read into yet another context and check for changes
-        List<?> objects3 = context3.performQuery(new SelectQuery(ClobTestEntity.class));
-        assertEquals(1, objects3.size());
-
-        ClobTestEntity clobObj3 = (ClobTestEntity) objects3.get(0);
-        assertEquals(clobObj2.getClobCol(), clobObj3.getClobCol());
-    }
-
-    protected void runWithClobSize(int sizeBytes) throws Exception {
-        // insert new clob
-        ClobTestEntity clobObj1 = context.newObject(ClobTestEntity.class);
-
-        // init CLOB of a specified size
-        if (sizeBytes == 0) {
-            clobObj1.setClobCol("");
-        }
-        else {
-            byte[] bytes = new byte[sizeBytes];
-            for (int i = 0; i < sizeBytes; i++) {
-                bytes[i] = (byte) (65 + (50 + i) % 50);
-            }
-            clobObj1.setClobCol(new String(bytes));
-        }
-
-        context.commitChanges();
-
-        // read the CLOB in the new context
-        List<?> objects2 = context2.performQuery(new SelectQuery(ClobTestEntity.class));
-        assertEquals(1, objects2.size());
-
-        ClobTestEntity clobObj2 = (ClobTestEntity) objects2.get(0);
-        assertEquals(clobObj1.getClobCol(), clobObj2.getClobCol());
-
-        // update and save Clob
-        clobObj2.setClobCol("updated rather small clob...");
-        context2.commitChanges();
-
-        // read into yet another context and check for changes
-        List<?> objects3 = context3.performQuery(new SelectQuery(ClobTestEntity.class));
-        assertEquals(1, objects3.size());
-
-        ClobTestEntity clobObj3 = (ClobTestEntity) objects3.get(0);
-        assertEquals(clobObj2.getClobCol(), clobObj3.getClobCol());
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCommitIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCommitIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCommitIT.java
new file mode 100644
index 0000000..30784e1
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCommitIT.java
@@ -0,0 +1,116 @@
+/*****************************************************************
+ *   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.access;
+
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.graph.GraphDiff;
+import org.apache.cayenne.graph.MockGraphChangeHandler;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.testdo.testmap.NullTestEntity;
+import org.apache.cayenne.testdo.testmap.Painting;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextCommitIT extends ServerCase {
+
+    @Inject
+    private DataContext context;
+
+    @Inject
+    private DBHelper dbHelper;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("PAINTING_INFO");
+        dbHelper.deleteAll("PAINTING");
+        dbHelper.deleteAll("ARTIST_EXHIBIT");
+        dbHelper.deleteAll("ARTIST_GROUP");
+        dbHelper.deleteAll("ARTIST");
+        dbHelper.deleteAll("NULL_TEST");
+    }
+
+    public void testFlushToParent_Commit() {
+
+        // commit new object
+        Artist a = context.newObject(Artist.class);
+        a.setArtistName("Test");
+
+        assertTrue(context.hasChanges());
+
+        GraphDiff diff = context.flushToParent(true);
+        assertNotNull(diff);
+        assertFalse(context.hasChanges());
+
+        final Object[] newIds = new Object[1];
+
+        MockGraphChangeHandler diffChecker = new MockGraphChangeHandler() {
+
+            @Override
+            public void nodeIdChanged(Object nodeId, Object newId) {
+                super.nodeIdChanged(nodeId, newId);
+
+                newIds[0] = newId;
+            }
+        };
+
+        diff.apply(diffChecker);
+        assertEquals(1, diffChecker.getCallbackCount());
+        assertSame(a.getObjectId(), newIds[0]);
+
+        // commit a mix of new and modified
+        Painting p = context.newObject(Painting.class);
+        p.setPaintingTitle("PT");
+        p.setToArtist(a);
+        a.setArtistName(a.getArtistName() + "_");
+
+        GraphDiff diff2 = context.flushToParent(true);
+        assertNotNull(diff2);
+        assertFalse(context.hasChanges());
+
+        final Object[] newIds2 = new Object[1];
+
+        MockGraphChangeHandler diffChecker2 = new MockGraphChangeHandler() {
+
+            @Override
+            public void nodeIdChanged(Object nodeId, Object newId) {
+                super.nodeIdChanged(nodeId, newId);
+
+                newIds2[0] = newId;
+            }
+        };
+
+        diff2.apply(diffChecker2);
+        assertEquals(1, diffChecker2.getCallbackCount());
+        assertSame(p.getObjectId(), newIds2[0]);
+
+        // commit new object with uninitialized attributes
+
+        context.newObject(NullTestEntity.class);
+
+        assertTrue(context.hasChanges());
+
+        GraphDiff diff3 = context.flushToParent(true);
+        assertNotNull(diff3);
+        assertFalse(context.hasChanges());
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCommitTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCommitTest.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCommitTest.java
deleted file mode 100644
index 31bcece..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCommitTest.java
+++ /dev/null
@@ -1,116 +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.access;
-
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.graph.GraphDiff;
-import org.apache.cayenne.graph.MockGraphChangeHandler;
-import org.apache.cayenne.test.jdbc.DBHelper;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.testdo.testmap.NullTestEntity;
-import org.apache.cayenne.testdo.testmap.Painting;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class DataContextCommitTest extends ServerCase {
-
-    @Inject
-    private DataContext context;
-
-    @Inject
-    private DBHelper dbHelper;
-
-    @Override
-    protected void setUpAfterInjection() throws Exception {
-        dbHelper.deleteAll("PAINTING_INFO");
-        dbHelper.deleteAll("PAINTING");
-        dbHelper.deleteAll("ARTIST_EXHIBIT");
-        dbHelper.deleteAll("ARTIST_GROUP");
-        dbHelper.deleteAll("ARTIST");
-        dbHelper.deleteAll("NULL_TEST");
-    }
-
-    public void testFlushToParent_Commit() {
-
-        // commit new object
-        Artist a = context.newObject(Artist.class);
-        a.setArtistName("Test");
-
-        assertTrue(context.hasChanges());
-
-        GraphDiff diff = context.flushToParent(true);
-        assertNotNull(diff);
-        assertFalse(context.hasChanges());
-
-        final Object[] newIds = new Object[1];
-
-        MockGraphChangeHandler diffChecker = new MockGraphChangeHandler() {
-
-            @Override
-            public void nodeIdChanged(Object nodeId, Object newId) {
-                super.nodeIdChanged(nodeId, newId);
-
-                newIds[0] = newId;
-            }
-        };
-
-        diff.apply(diffChecker);
-        assertEquals(1, diffChecker.getCallbackCount());
-        assertSame(a.getObjectId(), newIds[0]);
-
-        // commit a mix of new and modified
-        Painting p = context.newObject(Painting.class);
-        p.setPaintingTitle("PT");
-        p.setToArtist(a);
-        a.setArtistName(a.getArtistName() + "_");
-
-        GraphDiff diff2 = context.flushToParent(true);
-        assertNotNull(diff2);
-        assertFalse(context.hasChanges());
-
-        final Object[] newIds2 = new Object[1];
-
-        MockGraphChangeHandler diffChecker2 = new MockGraphChangeHandler() {
-
-            @Override
-            public void nodeIdChanged(Object nodeId, Object newId) {
-                super.nodeIdChanged(nodeId, newId);
-
-                newIds2[0] = newId;
-            }
-        };
-
-        diff2.apply(diffChecker2);
-        assertEquals(1, diffChecker2.getCallbackCount());
-        assertSame(p.getObjectId(), newIds2[0]);
-
-        // commit new object with uninitialized attributes
-
-        context.newObject(NullTestEntity.class);
-
-        assertTrue(context.hasChanges());
-
-        GraphDiff diff3 = context.flushToParent(true);
-        assertNotNull(diff3);
-        assertFalse(context.hasChanges());
-
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCompoundRelIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCompoundRelIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCompoundRelIT.java
new file mode 100644
index 0000000..fcd2563
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCompoundRelIT.java
@@ -0,0 +1,153 @@
+/*****************************************************************
+ *   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.access;
+
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.ExpressionFactory;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.testdo.testmap.CompoundFkTestEntity;
+import org.apache.cayenne.testdo.testmap.CompoundPkTestEntity;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.util.List;
+
+/**
+ * Testing relationships with compound keys.
+ */
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextCompoundRelIT extends ServerCase {
+
+    @Inject
+    private DataContext context;
+
+    @Inject
+    private DataContext context1;
+
+    @Inject
+    private DBHelper dbHelper;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("COMPOUND_FK_TEST");
+        dbHelper.deleteAll("COMPOUND_PK_TEST");
+    }
+
+    public void testInsert() {
+
+        CompoundPkTestEntity master = context.newObject(CompoundPkTestEntity.class);
+        CompoundFkTestEntity detail = context.newObject(CompoundFkTestEntity.class);
+        master.addToCompoundFkArray(detail);
+        master.setName("m1");
+        master.setKey1("key11");
+        master.setKey2("key21");
+        detail.setName("d1");
+
+        context.commitChanges();
+        context.invalidateObjects(master, detail);
+
+        SelectQuery q = new SelectQuery(CompoundPkTestEntity.class);
+        List<?> objs = context1.performQuery(q);
+        assertEquals(1, objs.size());
+
+        master = (CompoundPkTestEntity) objs.get(0);
+        assertEquals("m1", master.getName());
+
+        List<?> details = master.getCompoundFkArray();
+        assertEquals(1, details.size());
+        detail = (CompoundFkTestEntity) details.get(0);
+
+        assertEquals("d1", detail.getName());
+    }
+
+    public void testFetchQualifyingToOne() {
+        CompoundPkTestEntity master = (CompoundPkTestEntity) context
+                .newObject("CompoundPkTestEntity");
+        CompoundPkTestEntity master1 = (CompoundPkTestEntity) context
+                .newObject("CompoundPkTestEntity");
+        CompoundFkTestEntity detail = (CompoundFkTestEntity) context
+                .newObject("CompoundFkTestEntity");
+        CompoundFkTestEntity detail1 = (CompoundFkTestEntity) context
+                .newObject("CompoundFkTestEntity");
+        master.addToCompoundFkArray(detail);
+        master1.addToCompoundFkArray(detail1);
+
+        master.setName("m1");
+        master.setKey1("key11");
+        master.setKey2("key21");
+
+        master1.setName("m2");
+        master1.setKey1("key12");
+        master1.setKey2("key22");
+
+        detail.setName("d1");
+
+        detail1.setName("d2");
+
+        context.commitChanges();
+        context.invalidateObjects(master, master1, detail, detail1);
+
+        Expression qual = ExpressionFactory.matchExp("toCompoundPk", master);
+        SelectQuery q = new SelectQuery(CompoundFkTestEntity.class, qual);
+        List<?> objs = context1.performQuery(q);
+        assertEquals(1, objs.size());
+
+        detail = (CompoundFkTestEntity) objs.get(0);
+        assertEquals("d1", detail.getName());
+    }
+
+    public void testFetchQualifyingToMany() throws Exception {
+        CompoundPkTestEntity master = (CompoundPkTestEntity) context
+                .newObject("CompoundPkTestEntity");
+        CompoundPkTestEntity master1 = (CompoundPkTestEntity) context
+                .newObject("CompoundPkTestEntity");
+        CompoundFkTestEntity detail = (CompoundFkTestEntity) context
+                .newObject("CompoundFkTestEntity");
+        CompoundFkTestEntity detail1 = (CompoundFkTestEntity) context
+                .newObject("CompoundFkTestEntity");
+        master.addToCompoundFkArray(detail);
+        master1.addToCompoundFkArray(detail1);
+
+        master.setName("m1");
+        master.setKey1("key11");
+        master.setKey2("key21");
+
+        master1.setName("m2");
+        master1.setKey1("key12");
+        master1.setKey2("key22");
+
+        detail.setName("d1");
+
+        detail1.setName("d2");
+
+        context.commitChanges();
+        context.invalidateObjects(master, master1, detail, detail1);
+
+        Expression qual = ExpressionFactory.matchExp("compoundFkArray", detail1);
+        SelectQuery q = new SelectQuery(CompoundPkTestEntity.class, qual);
+        List<?> objs = context1.performQuery(q);
+        assertEquals(1, objs.size());
+
+        master = (CompoundPkTestEntity) objs.get(0);
+        assertEquals("m2", master.getName());
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCompoundRelTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCompoundRelTest.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCompoundRelTest.java
deleted file mode 100644
index e167f30..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCompoundRelTest.java
+++ /dev/null
@@ -1,153 +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.access;
-
-import java.util.List;
-
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.exp.Expression;
-import org.apache.cayenne.exp.ExpressionFactory;
-import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.test.jdbc.DBHelper;
-import org.apache.cayenne.testdo.testmap.CompoundFkTestEntity;
-import org.apache.cayenne.testdo.testmap.CompoundPkTestEntity;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-/**
- * Testing relationships with compound keys.
- */
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class DataContextCompoundRelTest extends ServerCase {
-
-    @Inject
-    private DataContext context;
-
-    @Inject
-    private DataContext context1;
-
-    @Inject
-    private DBHelper dbHelper;
-
-    @Override
-    protected void setUpAfterInjection() throws Exception {
-        dbHelper.deleteAll("COMPOUND_FK_TEST");
-        dbHelper.deleteAll("COMPOUND_PK_TEST");
-    }
-
-    public void testInsert() {
-
-        CompoundPkTestEntity master = context.newObject(CompoundPkTestEntity.class);
-        CompoundFkTestEntity detail = context.newObject(CompoundFkTestEntity.class);
-        master.addToCompoundFkArray(detail);
-        master.setName("m1");
-        master.setKey1("key11");
-        master.setKey2("key21");
-        detail.setName("d1");
-
-        context.commitChanges();
-        context.invalidateObjects(master, detail);
-
-        SelectQuery q = new SelectQuery(CompoundPkTestEntity.class);
-        List<?> objs = context1.performQuery(q);
-        assertEquals(1, objs.size());
-
-        master = (CompoundPkTestEntity) objs.get(0);
-        assertEquals("m1", master.getName());
-
-        List<?> details = master.getCompoundFkArray();
-        assertEquals(1, details.size());
-        detail = (CompoundFkTestEntity) details.get(0);
-
-        assertEquals("d1", detail.getName());
-    }
-
-    public void testFetchQualifyingToOne() {
-        CompoundPkTestEntity master = (CompoundPkTestEntity) context
-                .newObject("CompoundPkTestEntity");
-        CompoundPkTestEntity master1 = (CompoundPkTestEntity) context
-                .newObject("CompoundPkTestEntity");
-        CompoundFkTestEntity detail = (CompoundFkTestEntity) context
-                .newObject("CompoundFkTestEntity");
-        CompoundFkTestEntity detail1 = (CompoundFkTestEntity) context
-                .newObject("CompoundFkTestEntity");
-        master.addToCompoundFkArray(detail);
-        master1.addToCompoundFkArray(detail1);
-
-        master.setName("m1");
-        master.setKey1("key11");
-        master.setKey2("key21");
-
-        master1.setName("m2");
-        master1.setKey1("key12");
-        master1.setKey2("key22");
-
-        detail.setName("d1");
-
-        detail1.setName("d2");
-
-        context.commitChanges();
-        context.invalidateObjects(master, master1, detail, detail1);
-
-        Expression qual = ExpressionFactory.matchExp("toCompoundPk", master);
-        SelectQuery q = new SelectQuery(CompoundFkTestEntity.class, qual);
-        List<?> objs = context1.performQuery(q);
-        assertEquals(1, objs.size());
-
-        detail = (CompoundFkTestEntity) objs.get(0);
-        assertEquals("d1", detail.getName());
-    }
-
-    public void testFetchQualifyingToMany() throws Exception {
-        CompoundPkTestEntity master = (CompoundPkTestEntity) context
-                .newObject("CompoundPkTestEntity");
-        CompoundPkTestEntity master1 = (CompoundPkTestEntity) context
-                .newObject("CompoundPkTestEntity");
-        CompoundFkTestEntity detail = (CompoundFkTestEntity) context
-                .newObject("CompoundFkTestEntity");
-        CompoundFkTestEntity detail1 = (CompoundFkTestEntity) context
-                .newObject("CompoundFkTestEntity");
-        master.addToCompoundFkArray(detail);
-        master1.addToCompoundFkArray(detail1);
-
-        master.setName("m1");
-        master.setKey1("key11");
-        master.setKey2("key21");
-
-        master1.setName("m2");
-        master1.setKey1("key12");
-        master1.setKey2("key22");
-
-        detail.setName("d1");
-
-        detail1.setName("d2");
-
-        context.commitChanges();
-        context.invalidateObjects(master, master1, detail, detail1);
-
-        Expression qual = ExpressionFactory.matchExp("compoundFkArray", detail1);
-        SelectQuery q = new SelectQuery(CompoundPkTestEntity.class, qual);
-        List<?> objs = context1.performQuery(q);
-        assertEquals(1, objs.size());
-
-        master = (CompoundPkTestEntity) objs.get(0);
-        assertEquals("m2", master.getName());
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCrossDBIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCrossDBIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCrossDBIT.java
new file mode 100644
index 0000000..2a50584
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCrossDBIT.java
@@ -0,0 +1,65 @@
+/*****************************************************************
+ *   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.access;
+
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.testdo.db1.CrossdbM1E1;
+import org.apache.cayenne.testdo.db2.CrossdbM2E1;
+import org.apache.cayenne.testdo.db2.CrossdbM2E2;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ServerCase.MULTINODE_PROJECT)
+public class DataContextCrossDBIT extends ServerCase {
+
+    @Inject
+    private DataContext context;
+
+    public void testMultiDBUpdate() {
+
+        // for now testing that no exceptions are thrown... wouldn't hurt to check the
+        // data as well???
+
+        // insert
+        CrossdbM1E1 o1 = context.newObject(CrossdbM1E1.class);
+        o1.setName("o1");
+
+        CrossdbM2E1 o2 = context.newObject(CrossdbM2E1.class);
+        o2.setName("o2");
+
+        CrossdbM2E2 o3 = context.newObject(CrossdbM2E2.class);
+        o3.setName("o3");
+
+        o3.setToM1E1(o1);
+        o3.setToM2E1(o2);
+        context.commitChanges();
+
+        // update
+        CrossdbM1E1 o11 = context.newObject(CrossdbM1E1.class);
+        o11.setName("o11");
+        o3.setToM1E1(o11);
+        context.commitChanges();
+
+        // update with existing
+
+        o3.setToM1E1(o1);
+        context.commitChanges();
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCrossDBTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCrossDBTest.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCrossDBTest.java
deleted file mode 100644
index a43be8c..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCrossDBTest.java
+++ /dev/null
@@ -1,65 +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.access;
-
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.testdo.db1.CrossdbM1E1;
-import org.apache.cayenne.testdo.db2.CrossdbM2E1;
-import org.apache.cayenne.testdo.db2.CrossdbM2E2;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.MULTINODE_PROJECT)
-public class DataContextCrossDBTest extends ServerCase {
-
-    @Inject
-    private DataContext context;
-
-    public void testMultiDBUpdate() {
-
-        // for now testing that no exceptions are thrown... wouldn't hurt to check the
-        // data as well???
-
-        // insert
-        CrossdbM1E1 o1 = context.newObject(CrossdbM1E1.class);
-        o1.setName("o1");
-
-        CrossdbM2E1 o2 = context.newObject(CrossdbM2E1.class);
-        o2.setName("o2");
-
-        CrossdbM2E2 o3 = context.newObject(CrossdbM2E2.class);
-        o3.setName("o3");
-
-        o3.setToM1E1(o1);
-        o3.setToM2E1(o2);
-        context.commitChanges();
-
-        // update
-        CrossdbM1E1 o11 = context.newObject(CrossdbM1E1.class);
-        o11.setName("o11");
-        o3.setToM1E1(o11);
-        context.commitChanges();
-
-        // update with existing
-
-        o3.setToM1E1(o1);
-        context.commitChanges();
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDataChannelEventsIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDataChannelEventsIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDataChannelEventsIT.java
new file mode 100644
index 0000000..2f9bdbc
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDataChannelEventsIT.java
@@ -0,0 +1,190 @@
+/*****************************************************************
+ *   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.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.test.parallel.ParallelTestContainer;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+import org.apache.cayenne.util.EventUtil;
+
+/**
+ * Tests that DataContext sends DataChannel events.
+ */
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextDataChannelEventsIT extends ServerCase {
+
+    @Inject
+    private DataContext context;
+
+    @Inject
+    private DataContext peer;
+
+    @Inject
+    private ServerRuntime runtime;
+
+    public void testCommitEvent() throws Exception {
+        Artist a = context.newObject(Artist.class);
+        a.setArtistName("X");
+        context.commitChanges();
+
+        final MockChannelListener listener = new MockChannelListener();
+        EventUtil.listenForChannelEvents(context, listener);
+
+        a.setArtistName("Y");
+        context.commitChanges();
+
+        new ParallelTestContainer() {
+
+            @Override
+            protected void assertResult() throws Exception {
+                assertTrue(listener.graphCommitted);
+                assertFalse(listener.graphChanged);
+                assertFalse(listener.graphRolledBack);
+            }
+        }.runTest(10000);
+
+    }
+
+    public void testRollbackEvent() throws Exception {
+        Artist a = context.newObject(Artist.class);
+        a.setArtistName("X");
+        context.commitChanges();
+
+        final MockChannelListener listener = new MockChannelListener();
+        EventUtil.listenForChannelEvents(context, listener);
+
+        a.setArtistName("Y");
+        context.rollbackChanges();
+
+        new ParallelTestContainer() {
+
+            @Override
+            protected void assertResult() throws Exception {
+                assertFalse(listener.graphCommitted);
+                assertFalse(listener.graphChanged);
+                assertTrue(listener.graphRolledBack);
+            }
+        }.runTest(10000);
+    }
+
+    public void testChangeEventOnChildChange() throws Exception {
+        Artist a = context.newObject(Artist.class);
+        a.setArtistName("X");
+        context.commitChanges();
+
+        final MockChannelListener listener = new MockChannelListener();
+        EventUtil.listenForChannelEvents(context, listener);
+
+        ObjectContext childContext = runtime.newContext(context);
+
+        Artist a1 = childContext.localObject(a);
+
+        a1.setArtistName("Y");
+        childContext.commitChangesToParent();
+
+        new ParallelTestContainer() {
+
+            @Override
+            protected void assertResult() throws Exception {
+                assertFalse(listener.graphCommitted);
+                assertTrue(listener.graphChanged);
+                assertFalse(listener.graphRolledBack);
+            }
+        }.runTest(10000);
+    }
+
+    public void testChangeEventOnPeerChange() throws Exception {
+        Artist a = context.newObject(Artist.class);
+        a.setArtistName("X");
+        context.commitChanges();
+
+        final MockChannelListener listener = new MockChannelListener();
+        EventUtil.listenForChannelEvents(context, listener);
+
+        Artist a1 = peer.localObject(a);
+
+        a1.setArtistName("Y");
+        peer.commitChangesToParent();
+
+        new ParallelTestContainer() {
+
+            @Override
+            protected void assertResult() throws Exception {
+                assertFalse(listener.graphCommitted);
+                assertTrue(listener.graphChanged);
+                assertFalse(listener.graphRolledBack);
+            }
+        }.runTest(10000);
+    }
+
+    public void testChangeEventOnPeerChangeSecondNestingLevel() throws Exception {
+        ObjectContext childPeer1 = runtime.newContext(context);
+
+        Artist a = childPeer1.newObject(Artist.class);
+        a.setArtistName("X");
+        childPeer1.commitChanges();
+
+        final MockChannelListener listener = new MockChannelListener();
+        EventUtil.listenForChannelEvents((DataChannel) childPeer1, listener);
+
+        ObjectContext childPeer2 = runtime.newContext(context);
+
+        Artist a1 = childPeer2.localObject(a);
+
+        a1.setArtistName("Y");
+        childPeer2.commitChangesToParent();
+
+        new ParallelTestContainer() {
+
+            @Override
+            protected void assertResult() throws Exception {
+                assertFalse(listener.graphCommitted);
+                assertTrue(listener.graphChanged);
+                assertFalse(listener.graphRolledBack);
+            }
+        }.runTest(10000);
+    }
+
+    class MockChannelListener implements DataChannelListener {
+
+        boolean graphChanged;
+        boolean graphCommitted;
+        boolean graphRolledBack;
+
+        public void graphChanged(GraphEvent event) {
+            graphChanged = true;
+        }
+
+        public void graphFlushed(GraphEvent event) {
+            graphCommitted = true;
+        }
+
+        public void graphRolledback(GraphEvent event) {
+            graphRolledBack = true;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDataChannelEventsTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDataChannelEventsTest.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDataChannelEventsTest.java
deleted file mode 100644
index 733d3d4..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDataChannelEventsTest.java
+++ /dev/null
@@ -1,190 +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.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.test.parallel.ParallelTestContainer;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-import org.apache.cayenne.util.EventUtil;
-
-/**
- * Tests that DataContext sends DataChannel events.
- */
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class DataContextDataChannelEventsTest extends ServerCase {
-
-    @Inject
-    private DataContext context;
-
-    @Inject
-    private DataContext peer;
-
-    @Inject
-    private ServerRuntime runtime;
-
-    public void testCommitEvent() throws Exception {
-        Artist a = context.newObject(Artist.class);
-        a.setArtistName("X");
-        context.commitChanges();
-
-        final MockChannelListener listener = new MockChannelListener();
-        EventUtil.listenForChannelEvents(context, listener);
-
-        a.setArtistName("Y");
-        context.commitChanges();
-
-        new ParallelTestContainer() {
-
-            @Override
-            protected void assertResult() throws Exception {
-                assertTrue(listener.graphCommitted);
-                assertFalse(listener.graphChanged);
-                assertFalse(listener.graphRolledBack);
-            }
-        }.runTest(10000);
-
-    }
-
-    public void testRollbackEvent() throws Exception {
-        Artist a = context.newObject(Artist.class);
-        a.setArtistName("X");
-        context.commitChanges();
-
-        final MockChannelListener listener = new MockChannelListener();
-        EventUtil.listenForChannelEvents(context, listener);
-
-        a.setArtistName("Y");
-        context.rollbackChanges();
-
-        new ParallelTestContainer() {
-
-            @Override
-            protected void assertResult() throws Exception {
-                assertFalse(listener.graphCommitted);
-                assertFalse(listener.graphChanged);
-                assertTrue(listener.graphRolledBack);
-            }
-        }.runTest(10000);
-    }
-
-    public void testChangeEventOnChildChange() throws Exception {
-        Artist a = context.newObject(Artist.class);
-        a.setArtistName("X");
-        context.commitChanges();
-
-        final MockChannelListener listener = new MockChannelListener();
-        EventUtil.listenForChannelEvents(context, listener);
-
-        ObjectContext childContext = runtime.newContext(context);
-
-        Artist a1 = childContext.localObject(a);
-
-        a1.setArtistName("Y");
-        childContext.commitChangesToParent();
-
-        new ParallelTestContainer() {
-
-            @Override
-            protected void assertResult() throws Exception {
-                assertFalse(listener.graphCommitted);
-                assertTrue(listener.graphChanged);
-                assertFalse(listener.graphRolledBack);
-            }
-        }.runTest(10000);
-    }
-
-    public void testChangeEventOnPeerChange() throws Exception {
-        Artist a = context.newObject(Artist.class);
-        a.setArtistName("X");
-        context.commitChanges();
-
-        final MockChannelListener listener = new MockChannelListener();
-        EventUtil.listenForChannelEvents(context, listener);
-
-        Artist a1 = peer.localObject(a);
-
-        a1.setArtistName("Y");
-        peer.commitChangesToParent();
-
-        new ParallelTestContainer() {
-
-            @Override
-            protected void assertResult() throws Exception {
-                assertFalse(listener.graphCommitted);
-                assertTrue(listener.graphChanged);
-                assertFalse(listener.graphRolledBack);
-            }
-        }.runTest(10000);
-    }
-
-    public void testChangeEventOnPeerChangeSecondNestingLevel() throws Exception {
-        ObjectContext childPeer1 = runtime.newContext(context);
-
-        Artist a = childPeer1.newObject(Artist.class);
-        a.setArtistName("X");
-        childPeer1.commitChanges();
-
-        final MockChannelListener listener = new MockChannelListener();
-        EventUtil.listenForChannelEvents((DataChannel) childPeer1, listener);
-
-        ObjectContext childPeer2 = runtime.newContext(context);
-
-        Artist a1 = childPeer2.localObject(a);
-
-        a1.setArtistName("Y");
-        childPeer2.commitChangesToParent();
-
-        new ParallelTestContainer() {
-
-            @Override
-            protected void assertResult() throws Exception {
-                assertFalse(listener.graphCommitted);
-                assertTrue(listener.graphChanged);
-                assertFalse(listener.graphRolledBack);
-            }
-        }.runTest(10000);
-    }
-
-    class MockChannelListener implements DataChannelListener {
-
-        boolean graphChanged;
-        boolean graphCommitted;
-        boolean graphRolledBack;
-
-        public void graphChanged(GraphEvent event) {
-            graphChanged = true;
-        }
-
-        public void graphFlushed(GraphEvent event) {
-            graphCommitted = true;
-        }
-
-        public void graphRolledback(GraphEvent event) {
-            graphRolledBack = true;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDecoratedStackIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDecoratedStackIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDecoratedStackIT.java
new file mode 100644
index 0000000..a740643
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDecoratedStackIT.java
@@ -0,0 +1,131 @@
+/*****************************************************************
+ *   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.access;
+
+import org.apache.cayenne.Cayenne;
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.QueryResponse;
+import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.dba.frontbase.FrontBaseAdapter;
+import org.apache.cayenne.dba.openbase.OpenBaseAdapter;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.event.EventManager;
+import org.apache.cayenne.graph.GraphDiff;
+import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.query.Query;
+import org.apache.cayenne.query.SQLTemplate;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.util.Map;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextDecoratedStackIT extends ServerCase {
+
+    @Inject
+    private ServerRuntime runtime;
+
+    @Inject
+    private DBHelper dbHelper;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("PAINTING_INFO");
+        dbHelper.deleteAll("PAINTING");
+        dbHelper.deleteAll("ARTIST_EXHIBIT");
+        dbHelper.deleteAll("ARTIST_GROUP");
+        dbHelper.deleteAll("ARTIST");
+    }
+
+    public void testCommitDecorated() {
+        DataDomain dd = runtime.getDataDomain();
+        DataChannel decorator = new DataChannelDecorator(dd);
+        DataContext context = (DataContext) runtime.newContext(decorator);
+
+        Artist a = context.newObject(Artist.class);
+        a.setArtistName("XXX");
+        context.commitChanges();
+
+        SQLTemplate query = new SQLTemplate(
+                Artist.class,
+                "select #result('count(1)' 'int' 'x') from ARTIST");
+        query.setFetchingDataRows(true);
+        query.setTemplate(
+                FrontBaseAdapter.class.getName(),
+                "select #result('COUNT(ARTIST_ID)' 'int' 'x') from ARTIST");
+        query.setTemplate(
+                OpenBaseAdapter.class.getName(),
+                "select #result('COUNT(ARTIST_ID)' 'int' 'x') from ARTIST");
+        Map<?, ?> count = (Map<?, ?>) Cayenne.objectForQuery(context, query);
+        assertNotNull(count);
+        assertEquals(new Integer(1), count.get("x"));
+    }
+
+    public void testGetParentDataDomain() {
+        DataDomain dd = runtime.getDataDomain();
+        DataChannel decorator = new DataChannelDecorator(dd);
+        DataContext context = (DataContext) runtime.newContext(decorator);
+
+        assertSame(dd, context.getParentDataDomain());
+    }
+
+    class DataChannelDecorator implements DataChannel {
+
+        protected DataChannel channel;
+
+        protected DataChannelDecorator() {
+
+        }
+
+        public DataChannelDecorator(DataChannel channel) {
+            setChannel(channel);
+        }
+
+        public EntityResolver getEntityResolver() {
+            return channel.getEntityResolver();
+        }
+
+        public EventManager getEventManager() {
+            return channel.getEventManager();
+        }
+
+        public QueryResponse onQuery(ObjectContext originatingContext, Query query) {
+            return channel.onQuery(originatingContext, query);
+        }
+
+        public GraphDiff onSync(
+                ObjectContext originatingContext,
+                GraphDiff changes,
+                int syncType) {
+            return channel.onSync(originatingContext, changes, syncType);
+        }
+
+        public DataChannel getChannel() {
+            return channel;
+        }
+
+        public void setChannel(DataChannel channel) {
+            this.channel = channel;
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDecoratedStackTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDecoratedStackTest.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDecoratedStackTest.java
deleted file mode 100644
index dad7953..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDecoratedStackTest.java
+++ /dev/null
@@ -1,131 +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.access;
-
-import java.util.Map;
-
-import org.apache.cayenne.Cayenne;
-import org.apache.cayenne.DataChannel;
-import org.apache.cayenne.ObjectContext;
-import org.apache.cayenne.QueryResponse;
-import org.apache.cayenne.configuration.server.ServerRuntime;
-import org.apache.cayenne.dba.frontbase.FrontBaseAdapter;
-import org.apache.cayenne.dba.openbase.OpenBaseAdapter;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.event.EventManager;
-import org.apache.cayenne.graph.GraphDiff;
-import org.apache.cayenne.map.EntityResolver;
-import org.apache.cayenne.query.Query;
-import org.apache.cayenne.query.SQLTemplate;
-import org.apache.cayenne.test.jdbc.DBHelper;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class DataContextDecoratedStackTest extends ServerCase {
-
-    @Inject
-    private ServerRuntime runtime;
-
-    @Inject
-    private DBHelper dbHelper;
-
-    @Override
-    protected void setUpAfterInjection() throws Exception {
-        dbHelper.deleteAll("PAINTING_INFO");
-        dbHelper.deleteAll("PAINTING");
-        dbHelper.deleteAll("ARTIST_EXHIBIT");
-        dbHelper.deleteAll("ARTIST_GROUP");
-        dbHelper.deleteAll("ARTIST");
-    }
-
-    public void testCommitDecorated() {
-        DataDomain dd = runtime.getDataDomain();
-        DataChannel decorator = new DataChannelDecorator(dd);
-        DataContext context = (DataContext) runtime.newContext(decorator);
-
-        Artist a = context.newObject(Artist.class);
-        a.setArtistName("XXX");
-        context.commitChanges();
-
-        SQLTemplate query = new SQLTemplate(
-                Artist.class,
-                "select #result('count(1)' 'int' 'x') from ARTIST");
-        query.setFetchingDataRows(true);
-        query.setTemplate(
-                FrontBaseAdapter.class.getName(),
-                "select #result('COUNT(ARTIST_ID)' 'int' 'x') from ARTIST");
-        query.setTemplate(
-                OpenBaseAdapter.class.getName(),
-                "select #result('COUNT(ARTIST_ID)' 'int' 'x') from ARTIST");
-        Map<?, ?> count = (Map<?, ?>) Cayenne.objectForQuery(context, query);
-        assertNotNull(count);
-        assertEquals(new Integer(1), count.get("x"));
-    }
-
-    public void testGetParentDataDomain() {
-        DataDomain dd = runtime.getDataDomain();
-        DataChannel decorator = new DataChannelDecorator(dd);
-        DataContext context = (DataContext) runtime.newContext(decorator);
-
-        assertSame(dd, context.getParentDataDomain());
-    }
-
-    class DataChannelDecorator implements DataChannel {
-
-        protected DataChannel channel;
-
-        protected DataChannelDecorator() {
-
-        }
-
-        public DataChannelDecorator(DataChannel channel) {
-            setChannel(channel);
-        }
-
-        public EntityResolver getEntityResolver() {
-            return channel.getEntityResolver();
-        }
-
-        public EventManager getEventManager() {
-            return channel.getEventManager();
-        }
-
-        public QueryResponse onQuery(ObjectContext originatingContext, Query query) {
-            return channel.onQuery(originatingContext, query);
-        }
-
-        public GraphDiff onSync(
-                ObjectContext originatingContext,
-                GraphDiff changes,
-                int syncType) {
-            return channel.onSync(originatingContext, changes, syncType);
-        }
-
-        public DataChannel getChannel() {
-            return channel;
-        }
-
-        public void setChannel(DataChannel channel) {
-            this.channel = channel;
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDelegateIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDelegateIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDelegateIT.java
new file mode 100644
index 0000000..a86b751
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDelegateIT.java
@@ -0,0 +1,163 @@
+/*****************************************************************
+ *   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.access;
+
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.query.MockQuery;
+import org.apache.cayenne.query.Query;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.testdo.testmap.Gallery;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Tests various DataContextDelegate methods invocation and consequences on DataContext
+ * behavior.
+ */
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextDelegateIT extends ServerCase {
+
+    @Inject
+    private DataContext context;
+
+    @Inject
+    private DBHelper dbHelper;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+
+        dbHelper.deleteAll("PAINTING_INFO");
+        dbHelper.deleteAll("PAINTING");
+        dbHelper.deleteAll("ARTIST_EXHIBIT");
+        dbHelper.deleteAll("ARTIST_GROUP");
+        dbHelper.deleteAll("ARTIST");
+        dbHelper.deleteAll("EXHIBIT");
+        dbHelper.deleteAll("GALLERY");
+
+        // prepare a single gallery record
+        Gallery gallery = (Gallery) context.newObject("Gallery");
+        gallery.setGalleryName("version1");
+
+        // prepare a single artist record
+        Artist artist = (Artist) context.newObject("Artist");
+        artist.setArtistName("version1");
+
+        context.commitChanges();
+    }
+
+    public void testWillPerformGenericQuery() throws Exception {
+
+        final List<Query> queriesPerformed = new ArrayList<Query>(1);
+        DataContextDelegate delegate = new MockDataContextDelegate() {
+
+            @Override
+            public Query willPerformGenericQuery(DataContext context, Query query) {
+                queriesPerformed.add(query);
+                return query;
+            }
+        };
+        context.setDelegate(delegate);
+
+        // test that delegate is consulted before select
+        MockQuery query = new MockQuery();
+        context.performGenericQuery(query);
+
+        assertTrue("Delegate is not notified of a query being run.", queriesPerformed
+                .contains(query));
+        assertEquals(1, queriesPerformed.size());
+        assertTrue("Delegate unexpectedly blocked the query.", query.isRouteCalled());
+    }
+
+    public void testWillPerformGenericQueryBlocked() throws Exception {
+
+        final List<Query> queriesPerformed = new ArrayList<Query>(1);
+        DataContextDelegate delegate = new MockDataContextDelegate() {
+
+            @Override
+            public Query willPerformGenericQuery(DataContext context, Query query) {
+                queriesPerformed.add(query);
+                return null;
+            }
+        };
+
+        context.setDelegate(delegate);
+        MockQuery query = new MockQuery();
+        context.performGenericQuery(query);
+
+        assertTrue("Delegate is not notified of a query being run.", queriesPerformed
+                .contains(query));
+        assertEquals(1, queriesPerformed.size());
+        assertFalse("Delegate couldn't block the query.", query.isRouteCalled());
+    }
+
+    public void testWillPerformQuery() throws Exception {
+
+        final List<Query> queriesPerformed = new ArrayList<Query>(1);
+        DataContextDelegate delegate = new MockDataContextDelegate() {
+
+            @Override
+            public Query willPerformQuery(DataContext context, Query query) {
+                queriesPerformed.add(query);
+                return query;
+            }
+        };
+        context.setDelegate(delegate);
+
+        // test that delegate is consulted before select
+        SelectQuery query = new SelectQuery(Gallery.class);
+        List<?> results = context.performQuery(query);
+
+        assertTrue("Delegate is not notified of a query being run.", queriesPerformed
+                .contains(query));
+        assertEquals(1, queriesPerformed.size());
+        assertNotNull(results);
+    }
+
+    public void testWillPerformQueryBlocked() throws Exception {
+
+        final List<Query> queriesPerformed = new ArrayList<Query>(1);
+        DataContextDelegate delegate = new MockDataContextDelegate() {
+
+            @Override
+            public Query willPerformQuery(DataContext context, Query query) {
+                queriesPerformed.add(query);
+                return null;
+            }
+        };
+
+        context.setDelegate(delegate);
+        SelectQuery query = new SelectQuery(Gallery.class);
+        List<?> results = context.performQuery(query);
+
+        assertTrue("Delegate is not notified of a query being run.", queriesPerformed
+                .contains(query));
+        assertEquals(1, queriesPerformed.size());
+
+        assertNotNull(results);
+
+        // blocked
+        assertEquals("Delegate couldn't block the query.", 0, results.size());
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDelegateSharedCacheIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDelegateSharedCacheIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDelegateSharedCacheIT.java
new file mode 100644
index 0000000..d18d4de
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDelegateSharedCacheIT.java
@@ -0,0 +1,216 @@
+/*****************************************************************
+ *   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.access;
+
+import org.apache.cayenne.DataObject;
+import org.apache.cayenne.DataRow;
+import org.apache.cayenne.PersistenceState;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.test.parallel.ParallelTestContainer;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.util.Date;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextDelegateSharedCacheIT extends ServerCase {
+
+    @Inject
+    private DataContext context;
+
+    @Inject
+    private DataContext context1;
+
+    private Artist artist;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+
+        // prepare a single artist record
+        artist = (Artist) context.newObject("Artist");
+        artist.setArtistName("version1");
+        artist.setDateOfBirth(new Date());
+        context.commitChanges();
+    }
+
+    /**
+     * Test case to prove that delegate method is invoked on external change of object in
+     * the store.
+     */
+    public void testShouldMergeChanges() throws Exception {
+
+        final boolean[] methodInvoked = new boolean[1];
+        DataContextDelegate delegate = new MockDataContextDelegate() {
+
+            @Override
+            public boolean shouldMergeChanges(DataObject object, DataRow snapshotInStore) {
+                methodInvoked[0] = true;
+                return true;
+            }
+        };
+
+        // make sure we have a fully resolved copy of an artist object
+        // in the second context
+        Artist altArtist = context1.localObject(artist);
+        assertNotNull(altArtist);
+        assertNotSame(altArtist, artist);
+        assertEquals(artist.getArtistName(), altArtist.getArtistName());
+        assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());
+
+        context1.setDelegate(delegate);
+
+        // Update and save artist in peer context
+        artist.setArtistName("version2");
+        context.commitChanges();
+
+        // assert that delegate was consulted when an object store
+        // was refreshed
+        ParallelTestContainer helper = new ParallelTestContainer() {
+
+            @Override
+            protected void assertResult() throws Exception {
+                assertTrue("Delegate was not consulted", methodInvoked[0]);
+            }
+        };
+        helper.runTest(3000);
+    }
+
+    /**
+     * Test case to prove that delegate method can block changes made by ObjectStore.
+     * 
+     * @throws Exception
+     */
+    public void testBlockedShouldMergeChanges() throws Exception {
+        String oldName = artist.getArtistName();
+
+        DataContextDelegate delegate = new MockDataContextDelegate() {
+
+            @Override
+            public boolean shouldMergeChanges(DataObject object, DataRow snapshotInStore) {
+                return false;
+            }
+        };
+        context1.setDelegate(delegate);
+
+        // make sure we have a fully resolved copy of an artist object
+        // in the second context
+        Artist altArtist = context1.localObject(artist);
+        assertNotNull(altArtist);
+        assertFalse(altArtist == artist);
+        assertEquals(oldName, altArtist.getArtistName());
+        assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());
+
+        // Update and save artist in peer context
+        artist.setArtistName("version2");
+        context.commitChanges();
+
+        // assert that delegate was able to block the merge
+        assertEquals(oldName, altArtist.getArtistName());
+    }
+
+    /**
+     * Test case to prove that delegate method is invoked on external change of object in
+     * the store.
+     * 
+     * @throws Exception
+     */
+    public void testShouldProcessDeleteOnExternalChange() throws Exception {
+
+        final boolean[] methodInvoked = new boolean[1];
+        DataContextDelegate delegate = new MockDataContextDelegate() {
+
+            @Override
+            public boolean shouldProcessDelete(DataObject object) {
+                methodInvoked[0] = true;
+                return true;
+            }
+        };
+        context1.setDelegate(delegate);
+
+        // make sure we have a fully resolved copy of an artist object
+        // in the second context
+        Artist altArtist = context1.localObject(artist);
+        assertNotNull(altArtist);
+        assertFalse(altArtist == artist);
+        assertEquals(artist.getArtistName(), altArtist.getArtistName());
+        assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());
+
+        // Update and save artist in peer context
+        context.deleteObjects(artist);
+        context.commitChanges();
+
+        // assert that delegate was consulted when an object store
+        // was refreshed
+        ParallelTestContainer helper = new ParallelTestContainer() {
+
+            @Override
+            protected void assertResult() throws Exception {
+                assertTrue("Delegate was not consulted", methodInvoked[0]);
+            }
+        };
+        helper.runTest(3000);
+    }
+
+    /**
+     * Test case to prove that delegate method is invoked on external change of object in
+     * the store, and is able to block further object processing.
+     * 
+     * @throws Exception
+     */
+    public void testBlockShouldProcessDeleteOnExternalChange() throws Exception {
+
+        final boolean[] methodInvoked = new boolean[1];
+        DataContextDelegate delegate = new MockDataContextDelegate() {
+
+            @Override
+            public boolean shouldProcessDelete(DataObject object) {
+                methodInvoked[0] = true;
+                return false;
+            }
+        };
+        context1.setDelegate(delegate);
+
+        // make sure we have a fully resolved copy of an artist object
+        // in the second context
+        Artist altArtist = context1.localObject(artist);
+        assertNotNull(altArtist);
+        assertFalse(altArtist == artist);
+        assertEquals(artist.getArtistName(), altArtist.getArtistName());
+        assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());
+
+        // Update and save artist in peer context
+        context.deleteObjects(artist);
+        context.commitChanges();
+
+        // assert that delegate was consulted when an object store
+        // was refreshed, and actually blocked object expulsion
+        ParallelTestContainer helper = new ParallelTestContainer() {
+
+            @Override
+            protected void assertResult() throws Exception {
+                assertTrue("Delegate was not consulted", methodInvoked[0]);
+            }
+        };
+        helper.runTest(3000);
+        assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());
+        assertNotNull(altArtist.getObjectContext());
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDelegateSharedCacheTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDelegateSharedCacheTest.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDelegateSharedCacheTest.java
deleted file mode 100644
index 965bf9a..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDelegateSharedCacheTest.java
+++ /dev/null
@@ -1,216 +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.access;
-
-import java.util.Date;
-
-import org.apache.cayenne.DataObject;
-import org.apache.cayenne.DataRow;
-import org.apache.cayenne.PersistenceState;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.test.parallel.ParallelTestContainer;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class DataContextDelegateSharedCacheTest extends ServerCase {
-
-    @Inject
-    private DataContext context;
-
-    @Inject
-    private DataContext context1;
-
-    private Artist artist;
-
-    @Override
-    protected void setUpAfterInjection() throws Exception {
-
-        // prepare a single artist record
-        artist = (Artist) context.newObject("Artist");
-        artist.setArtistName("version1");
-        artist.setDateOfBirth(new Date());
-        context.commitChanges();
-    }
-
-    /**
-     * Test case to prove that delegate method is invoked on external change of object in
-     * the store.
-     */
-    public void testShouldMergeChanges() throws Exception {
-
-        final boolean[] methodInvoked = new boolean[1];
-        DataContextDelegate delegate = new MockDataContextDelegate() {
-
-            @Override
-            public boolean shouldMergeChanges(DataObject object, DataRow snapshotInStore) {
-                methodInvoked[0] = true;
-                return true;
-            }
-        };
-
-        // make sure we have a fully resolved copy of an artist object
-        // in the second context
-        Artist altArtist = context1.localObject(artist);
-        assertNotNull(altArtist);
-        assertNotSame(altArtist, artist);
-        assertEquals(artist.getArtistName(), altArtist.getArtistName());
-        assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());
-
-        context1.setDelegate(delegate);
-
-        // Update and save artist in peer context
-        artist.setArtistName("version2");
-        context.commitChanges();
-
-        // assert that delegate was consulted when an object store
-        // was refreshed
-        ParallelTestContainer helper = new ParallelTestContainer() {
-
-            @Override
-            protected void assertResult() throws Exception {
-                assertTrue("Delegate was not consulted", methodInvoked[0]);
-            }
-        };
-        helper.runTest(3000);
-    }
-
-    /**
-     * Test case to prove that delegate method can block changes made by ObjectStore.
-     * 
-     * @throws Exception
-     */
-    public void testBlockedShouldMergeChanges() throws Exception {
-        String oldName = artist.getArtistName();
-
-        DataContextDelegate delegate = new MockDataContextDelegate() {
-
-            @Override
-            public boolean shouldMergeChanges(DataObject object, DataRow snapshotInStore) {
-                return false;
-            }
-        };
-        context1.setDelegate(delegate);
-
-        // make sure we have a fully resolved copy of an artist object
-        // in the second context
-        Artist altArtist = context1.localObject(artist);
-        assertNotNull(altArtist);
-        assertFalse(altArtist == artist);
-        assertEquals(oldName, altArtist.getArtistName());
-        assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());
-
-        // Update and save artist in peer context
-        artist.setArtistName("version2");
-        context.commitChanges();
-
-        // assert that delegate was able to block the merge
-        assertEquals(oldName, altArtist.getArtistName());
-    }
-
-    /**
-     * Test case to prove that delegate method is invoked on external change of object in
-     * the store.
-     * 
-     * @throws Exception
-     */
-    public void testShouldProcessDeleteOnExternalChange() throws Exception {
-
-        final boolean[] methodInvoked = new boolean[1];
-        DataContextDelegate delegate = new MockDataContextDelegate() {
-
-            @Override
-            public boolean shouldProcessDelete(DataObject object) {
-                methodInvoked[0] = true;
-                return true;
-            }
-        };
-        context1.setDelegate(delegate);
-
-        // make sure we have a fully resolved copy of an artist object
-        // in the second context
-        Artist altArtist = context1.localObject(artist);
-        assertNotNull(altArtist);
-        assertFalse(altArtist == artist);
-        assertEquals(artist.getArtistName(), altArtist.getArtistName());
-        assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());
-
-        // Update and save artist in peer context
-        context.deleteObjects(artist);
-        context.commitChanges();
-
-        // assert that delegate was consulted when an object store
-        // was refreshed
-        ParallelTestContainer helper = new ParallelTestContainer() {
-
-            @Override
-            protected void assertResult() throws Exception {
-                assertTrue("Delegate was not consulted", methodInvoked[0]);
-            }
-        };
-        helper.runTest(3000);
-    }
-
-    /**
-     * Test case to prove that delegate method is invoked on external change of object in
-     * the store, and is able to block further object processing.
-     * 
-     * @throws Exception
-     */
-    public void testBlockShouldProcessDeleteOnExternalChange() throws Exception {
-
-        final boolean[] methodInvoked = new boolean[1];
-        DataContextDelegate delegate = new MockDataContextDelegate() {
-
-            @Override
-            public boolean shouldProcessDelete(DataObject object) {
-                methodInvoked[0] = true;
-                return false;
-            }
-        };
-        context1.setDelegate(delegate);
-
-        // make sure we have a fully resolved copy of an artist object
-        // in the second context
-        Artist altArtist = context1.localObject(artist);
-        assertNotNull(altArtist);
-        assertFalse(altArtist == artist);
-        assertEquals(artist.getArtistName(), altArtist.getArtistName());
-        assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());
-
-        // Update and save artist in peer context
-        context.deleteObjects(artist);
-        context.commitChanges();
-
-        // assert that delegate was consulted when an object store
-        // was refreshed, and actually blocked object expulsion
-        ParallelTestContainer helper = new ParallelTestContainer() {
-
-            @Override
-            protected void assertResult() throws Exception {
-                assertTrue("Delegate was not consulted", methodInvoked[0]);
-            }
-        };
-        helper.runTest(3000);
-        assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());
-        assertNotNull(altArtist.getObjectContext());
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDelegateTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDelegateTest.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDelegateTest.java
deleted file mode 100644
index 62852c2..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDelegateTest.java
+++ /dev/null
@@ -1,163 +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.access;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.query.MockQuery;
-import org.apache.cayenne.query.Query;
-import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.test.jdbc.DBHelper;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.testdo.testmap.Gallery;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-/**
- * Tests various DataContextDelegate methods invocation and consequences on DataContext
- * behavior.
- */
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class DataContextDelegateTest extends ServerCase {
-
-    @Inject
-    private DataContext context;
-
-    @Inject
-    private DBHelper dbHelper;
-
-    @Override
-    protected void setUpAfterInjection() throws Exception {
-
-        dbHelper.deleteAll("PAINTING_INFO");
-        dbHelper.deleteAll("PAINTING");
-        dbHelper.deleteAll("ARTIST_EXHIBIT");
-        dbHelper.deleteAll("ARTIST_GROUP");
-        dbHelper.deleteAll("ARTIST");
-        dbHelper.deleteAll("EXHIBIT");
-        dbHelper.deleteAll("GALLERY");
-
-        // prepare a single gallery record
-        Gallery gallery = (Gallery) context.newObject("Gallery");
-        gallery.setGalleryName("version1");
-
-        // prepare a single artist record
-        Artist artist = (Artist) context.newObject("Artist");
-        artist.setArtistName("version1");
-
-        context.commitChanges();
-    }
-
-    public void testWillPerformGenericQuery() throws Exception {
-
-        final List<Query> queriesPerformed = new ArrayList<Query>(1);
-        DataContextDelegate delegate = new MockDataContextDelegate() {
-
-            @Override
-            public Query willPerformGenericQuery(DataContext context, Query query) {
-                queriesPerformed.add(query);
-                return query;
-            }
-        };
-        context.setDelegate(delegate);
-
-        // test that delegate is consulted before select
-        MockQuery query = new MockQuery();
-        context.performGenericQuery(query);
-
-        assertTrue("Delegate is not notified of a query being run.", queriesPerformed
-                .contains(query));
-        assertEquals(1, queriesPerformed.size());
-        assertTrue("Delegate unexpectedly blocked the query.", query.isRouteCalled());
-    }
-
-    public void testWillPerformGenericQueryBlocked() throws Exception {
-
-        final List<Query> queriesPerformed = new ArrayList<Query>(1);
-        DataContextDelegate delegate = new MockDataContextDelegate() {
-
-            @Override
-            public Query willPerformGenericQuery(DataContext context, Query query) {
-                queriesPerformed.add(query);
-                return null;
-            }
-        };
-
-        context.setDelegate(delegate);
-        MockQuery query = new MockQuery();
-        context.performGenericQuery(query);
-
-        assertTrue("Delegate is not notified of a query being run.", queriesPerformed
-                .contains(query));
-        assertEquals(1, queriesPerformed.size());
-        assertFalse("Delegate couldn't block the query.", query.isRouteCalled());
-    }
-
-    public void testWillPerformQuery() throws Exception {
-
-        final List<Query> queriesPerformed = new ArrayList<Query>(1);
-        DataContextDelegate delegate = new MockDataContextDelegate() {
-
-            @Override
-            public Query willPerformQuery(DataContext context, Query query) {
-                queriesPerformed.add(query);
-                return query;
-            }
-        };
-        context.setDelegate(delegate);
-
-        // test that delegate is consulted before select
-        SelectQuery query = new SelectQuery(Gallery.class);
-        List<?> results = context.performQuery(query);
-
-        assertTrue("Delegate is not notified of a query being run.", queriesPerformed
-                .contains(query));
-        assertEquals(1, queriesPerformed.size());
-        assertNotNull(results);
-    }
-
-    public void testWillPerformQueryBlocked() throws Exception {
-
-        final List<Query> queriesPerformed = new ArrayList<Query>(1);
-        DataContextDelegate delegate = new MockDataContextDelegate() {
-
-            @Override
-            public Query willPerformQuery(DataContext context, Query query) {
-                queriesPerformed.add(query);
-                return null;
-            }
-        };
-
-        context.setDelegate(delegate);
-        SelectQuery query = new SelectQuery(Gallery.class);
-        List<?> results = context.performQuery(query);
-
-        assertTrue("Delegate is not notified of a query being run.", queriesPerformed
-                .contains(query));
-        assertEquals(1, queriesPerformed.size());
-
-        assertNotNull(results);
-
-        // blocked
-        assertEquals("Delegate couldn't block the query.", 0, results.size());
-    }
-}


Mime
View raw message