You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2014/11/02 08:10:33 UTC

[45/48] Installing Maven Failsafe Plugin

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CDOQualifiedEntitiesTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CDOQualifiedEntitiesTest.java b/cayenne-server/src/test/java/org/apache/cayenne/CDOQualifiedEntitiesTest.java
deleted file mode 100644
index 5d4ad69..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/CDOQualifiedEntitiesTest.java
+++ /dev/null
@@ -1,126 +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.List;
-
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.test.jdbc.DBHelper;
-import org.apache.cayenne.test.jdbc.TableHelper;
-import org.apache.cayenne.testdo.qualified.Qualified1;
-import org.apache.cayenne.testdo.qualified.Qualified2;
-import org.apache.cayenne.unit.UnitDbAdapter;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.DEFAULT_PROJECT)
-public class CDOQualifiedEntitiesTest extends ServerCase {
-
-    @Inject
-    private ObjectContext context;
-
-    @Inject
-    private UnitDbAdapter accessStackAdapter;
-
-    @Inject
-    private DBHelper dbHelper;
-
-    private TableHelper tQualified1;
-    private TableHelper tQualified2;
-
-    @Override
-    protected void setUpAfterInjection() throws Exception {
-        dbHelper.deleteAll("TEST_QUALIFIED2");
-        dbHelper.deleteAll("TEST_QUALIFIED1");
-
-        int bool = accessStackAdapter.supportsBoolean() ? Types.BOOLEAN : Types.INTEGER;
-
-        tQualified1 = new TableHelper(dbHelper, "TEST_QUALIFIED1");
-        tQualified1.setColumns("ID", "NAME", "DELETED").setColumnTypes(
-                Types.INTEGER,
-                Types.VARCHAR,
-                bool);
-
-        tQualified2 = new TableHelper(dbHelper, "TEST_QUALIFIED2");
-        tQualified2.setColumns("ID", "NAME", "DELETED", "QUALIFIED1_ID").setColumnTypes(
-                Types.INTEGER,
-                Types.VARCHAR,
-                bool,
-                Types.INTEGER);
-    }
-
-    private void createReadToManyDataSet() throws Exception {
-        
-        tQualified1.insert(1, "OX1", null);
-        tQualified1.insert(2, "OX2", accessStackAdapter.supportsBoolean() ? true : 1);
-
-        tQualified2.insert(1, "OY1", null, 1);
-        tQualified2.insert(2, "OY2", accessStackAdapter.supportsBoolean() ? true : 1, 1);
-        tQualified2.insert(3, "OY3", null, 2);
-        tQualified2.insert(4, "OY4", accessStackAdapter.supportsBoolean() ? true : 1, 2);
-    }
-
-    private void createReadToOneDataSet() throws Exception {
-        tQualified1.insert(1, "OX1", null);
-        tQualified1.insert(2, "OX2", accessStackAdapter.supportsBoolean() ? true : 1);
-
-        tQualified2.insert(1, "OY1", null, 2);
-    }
-
-    public void testReadToMany() throws Exception {
-        if (accessStackAdapter.supportsNullBoolean()) {
-
-            createReadToManyDataSet();
-
-            SelectQuery rootSelect = new SelectQuery(Qualified1.class);
-            List<Qualified1> roots = context.performQuery(rootSelect);
-
-            assertEquals(1, roots.size());
-
-            Qualified1 root = roots.get(0);
-
-            assertEquals("OX1", root.getName());
-
-            List<Qualified2> related = root.getQualified2s();
-            assertEquals(1, related.size());
-
-            Qualified2 r = related.get(0);
-            assertEquals("OY1", r.getName());
-        }
-    }
-
-    public void testReadToOne() throws Exception {
-        if (accessStackAdapter.supportsNullBoolean()) {
-
-            createReadToOneDataSet();
-
-            SelectQuery rootSelect = new SelectQuery(Qualified2.class);
-            List<Qualified2> roots = context.performQuery(rootSelect);
-            assertEquals(1, roots.size());
-
-            Qualified2 root = roots.get(0);
-            assertEquals("OY1", root.getName());
-
-            Qualified1 target = root.getQualified1();
-            assertNull("" + target, target);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CDOReflexiveRelDeleteIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CDOReflexiveRelDeleteIT.java b/cayenne-server/src/test/java/org/apache/cayenne/CDOReflexiveRelDeleteIT.java
new file mode 100644
index 0000000..18c721e
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/CDOReflexiveRelDeleteIT.java
@@ -0,0 +1,96 @@
+/*****************************************************************
+ *   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.testdo.testmap.ArtGroup;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime("cayenne-small-testmap.xml")
+public class CDOReflexiveRelDeleteIT extends ServerCase {
+
+    @Inject
+    private ObjectContext context;
+    
+    private ArtGroup parentGroup;
+    private ArtGroup childGroup1;
+    private ArtGroup childGroup2;
+    private ArtGroup childGroup3;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        super.setUpAfterInjection();
+
+        parentGroup = context.newObject(ArtGroup.class);
+        parentGroup.setName("parent");
+
+        childGroup1 = context.newObject(ArtGroup.class);
+        childGroup1.setName("child1");
+        childGroup1.setToParentGroup(parentGroup);
+
+        childGroup2 = context.newObject(ArtGroup.class);
+        childGroup2.setName("child2");
+        childGroup2.setToParentGroup(parentGroup);
+
+        childGroup3 = context.newObject(ArtGroup.class);
+        childGroup3.setName("subchild");
+        childGroup3.setToParentGroup(childGroup1);
+
+        context.commitChanges();
+    }
+
+    // Test various delete orders. There are more possible literal combinations, but the
+    // ones below fairly well
+    // encompass the various orders that might be a problem. Add more if additional
+    // problems come to light
+    public void testReflexiveRelationshipDelete1() {
+        context.deleteObjects(parentGroup);
+        context.deleteObjects(childGroup1);
+        context.deleteObjects(childGroup2);
+        context.deleteObjects(childGroup3);
+        context.commitChanges();
+    }
+
+    public void testReflexiveRelationshipDelete2() {
+        context.deleteObjects(childGroup1);
+        context.deleteObjects(parentGroup);
+        context.deleteObjects(childGroup2);
+        context.deleteObjects(childGroup3);
+        context.commitChanges();
+    }
+
+    public void testReflexiveRelationshipDelete3() {
+        context.deleteObjects(childGroup1);
+        context.deleteObjects(childGroup3);
+        context.deleteObjects(parentGroup);
+        context.deleteObjects(childGroup2);
+        context.commitChanges();
+    }
+
+    public void testReflexiveRelationshipDelete4() {
+        context.deleteObjects(childGroup3);
+        context.deleteObjects(parentGroup);
+        context.deleteObjects(childGroup1);
+        context.deleteObjects(childGroup2);
+        context.commitChanges();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CDOReflexiveRelDeleteTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CDOReflexiveRelDeleteTest.java b/cayenne-server/src/test/java/org/apache/cayenne/CDOReflexiveRelDeleteTest.java
deleted file mode 100644
index adbdfd4..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/CDOReflexiveRelDeleteTest.java
+++ /dev/null
@@ -1,96 +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.testdo.testmap.ArtGroup;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime("cayenne-small-testmap.xml")
-public class CDOReflexiveRelDeleteTest extends ServerCase {
-
-    @Inject
-    private ObjectContext context;
-    
-    private ArtGroup parentGroup;
-    private ArtGroup childGroup1;
-    private ArtGroup childGroup2;
-    private ArtGroup childGroup3;
-
-    @Override
-    protected void setUpAfterInjection() throws Exception {
-        super.setUpAfterInjection();
-
-        parentGroup = context.newObject(ArtGroup.class);
-        parentGroup.setName("parent");
-
-        childGroup1 = context.newObject(ArtGroup.class);
-        childGroup1.setName("child1");
-        childGroup1.setToParentGroup(parentGroup);
-
-        childGroup2 = context.newObject(ArtGroup.class);
-        childGroup2.setName("child2");
-        childGroup2.setToParentGroup(parentGroup);
-
-        childGroup3 = context.newObject(ArtGroup.class);
-        childGroup3.setName("subchild");
-        childGroup3.setToParentGroup(childGroup1);
-
-        context.commitChanges();
-    }
-
-    // Test various delete orders. There are more possible literal combinations, but the
-    // ones below fairly well
-    // encompass the various orders that might be a problem. Add more if additional
-    // problems come to light
-    public void testReflexiveRelationshipDelete1() {
-        context.deleteObjects(parentGroup);
-        context.deleteObjects(childGroup1);
-        context.deleteObjects(childGroup2);
-        context.deleteObjects(childGroup3);
-        context.commitChanges();
-    }
-
-    public void testReflexiveRelationshipDelete2() {
-        context.deleteObjects(childGroup1);
-        context.deleteObjects(parentGroup);
-        context.deleteObjects(childGroup2);
-        context.deleteObjects(childGroup3);
-        context.commitChanges();
-    }
-
-    public void testReflexiveRelationshipDelete3() {
-        context.deleteObjects(childGroup1);
-        context.deleteObjects(childGroup3);
-        context.deleteObjects(parentGroup);
-        context.deleteObjects(childGroup2);
-        context.commitChanges();
-    }
-
-    public void testReflexiveRelationshipDelete4() {
-        context.deleteObjects(childGroup3);
-        context.deleteObjects(parentGroup);
-        context.deleteObjects(childGroup1);
-        context.deleteObjects(childGroup2);
-        context.commitChanges();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CDOReflexiveRelIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CDOReflexiveRelIT.java b/cayenne-server/src/test/java/org/apache/cayenne/CDOReflexiveRelIT.java
new file mode 100644
index 0000000..fa94fe9
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/CDOReflexiveRelIT.java
@@ -0,0 +1,120 @@
+/*****************************************************************
+ *   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.testdo.testmap.ArtGroup;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+/**
+ * Some more tests regarding reflexive relationships, especially related to delete rules
+ * etc. The implementation is hairy, and so needs a really good workout.
+ */
+@UseServerRuntime("cayenne-small-testmap.xml")
+public class CDOReflexiveRelIT extends ServerCase {
+
+    @Inject
+    private ObjectContext context;
+
+    public void testAddDeleteNoCommit() {
+        ArtGroup parentGroup = context.newObject(ArtGroup.class);
+        parentGroup.setName("parent");
+
+        ArtGroup childGroup1 = context.newObject(ArtGroup.class);
+        childGroup1.setName("child1");
+        childGroup1.setToParentGroup(parentGroup);
+
+        context.deleteObjects(parentGroup);
+    }
+
+    public void testAddDeleteWithCommit() {
+        ArtGroup parentGroup = context.newObject(ArtGroup.class);
+        parentGroup.setName("parent");
+
+        ArtGroup childGroup1 = context.newObject(ArtGroup.class);
+        childGroup1.setName("child1");
+        childGroup1.setToParentGroup(parentGroup);
+        context.commitChanges();
+
+        context.deleteObjects(parentGroup);
+        context.commitChanges();
+    }
+
+    public void testReplaceDeleteNoCommit() {
+        ArtGroup parentGroup1 = context.newObject(ArtGroup.class);
+        parentGroup1.setName("parent1");
+        ArtGroup parentGroup2 = context.newObject(ArtGroup.class);
+        parentGroup2.setName("parent2");
+
+        ArtGroup childGroup1 = context.newObject(ArtGroup.class);
+        childGroup1.setName("child1");
+        childGroup1.setToParentGroup(parentGroup1);
+
+        childGroup1.setToParentGroup(parentGroup2);
+
+        context.deleteObjects(parentGroup1);
+        context.deleteObjects(parentGroup2);
+    }
+
+    public void testReplaceDeleteWithCommit() {
+        ArtGroup parentGroup1 = context.newObject(ArtGroup.class);
+        parentGroup1.setName("parent1");
+        ArtGroup parentGroup2 = context.newObject(ArtGroup.class);
+        parentGroup2.setName("parent2");
+
+        ArtGroup childGroup1 = context.newObject(ArtGroup.class);
+        childGroup1.setName("child1");
+        childGroup1.setToParentGroup(parentGroup1);
+        childGroup1.setToParentGroup(parentGroup2);
+        context.commitChanges();
+
+        context.deleteObjects(parentGroup1);
+        context.deleteObjects(parentGroup2);
+        context.commitChanges();
+    }
+
+    public void testCommitReplaceCommit() {
+        ArtGroup parentGroup1 = context.newObject(ArtGroup.class);
+        parentGroup1.setName("parent1");
+        ArtGroup parentGroup2 = context.newObject(ArtGroup.class);
+        parentGroup2.setName("parent2");
+
+        ArtGroup childGroup1 = context.newObject(ArtGroup.class);
+        childGroup1.setName("child1");
+        childGroup1.setToParentGroup(parentGroup1);
+        context.commitChanges();
+        childGroup1.setToParentGroup(parentGroup2);
+        context.commitChanges();
+    }
+
+    public void testComplexInsertUpdateOrdering() {
+        ArtGroup parentGroup = context.newObject(ArtGroup.class);
+        parentGroup.setName("parent");
+        context.commitChanges();
+
+        // Check that the update and insert both work write
+        ArtGroup childGroup1 = context.newObject(ArtGroup.class);
+        childGroup1.setName("child1");
+        childGroup1.setToParentGroup(parentGroup);
+        context.commitChanges();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CDOReflexiveRelTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CDOReflexiveRelTest.java b/cayenne-server/src/test/java/org/apache/cayenne/CDOReflexiveRelTest.java
deleted file mode 100644
index 7c77b04..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/CDOReflexiveRelTest.java
+++ /dev/null
@@ -1,120 +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.testdo.testmap.ArtGroup;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-/**
- * Some more tests regarding reflexive relationships, especially related to delete rules
- * etc. The implementation is hairy, and so needs a really good workout.
- */
-@UseServerRuntime("cayenne-small-testmap.xml")
-public class CDOReflexiveRelTest extends ServerCase {
-
-    @Inject
-    private ObjectContext context;
-
-    public void testAddDeleteNoCommit() {
-        ArtGroup parentGroup = context.newObject(ArtGroup.class);
-        parentGroup.setName("parent");
-
-        ArtGroup childGroup1 = context.newObject(ArtGroup.class);
-        childGroup1.setName("child1");
-        childGroup1.setToParentGroup(parentGroup);
-
-        context.deleteObjects(parentGroup);
-    }
-
-    public void testAddDeleteWithCommit() {
-        ArtGroup parentGroup = context.newObject(ArtGroup.class);
-        parentGroup.setName("parent");
-
-        ArtGroup childGroup1 = context.newObject(ArtGroup.class);
-        childGroup1.setName("child1");
-        childGroup1.setToParentGroup(parentGroup);
-        context.commitChanges();
-
-        context.deleteObjects(parentGroup);
-        context.commitChanges();
-    }
-
-    public void testReplaceDeleteNoCommit() {
-        ArtGroup parentGroup1 = context.newObject(ArtGroup.class);
-        parentGroup1.setName("parent1");
-        ArtGroup parentGroup2 = context.newObject(ArtGroup.class);
-        parentGroup2.setName("parent2");
-
-        ArtGroup childGroup1 = context.newObject(ArtGroup.class);
-        childGroup1.setName("child1");
-        childGroup1.setToParentGroup(parentGroup1);
-
-        childGroup1.setToParentGroup(parentGroup2);
-
-        context.deleteObjects(parentGroup1);
-        context.deleteObjects(parentGroup2);
-    }
-
-    public void testReplaceDeleteWithCommit() {
-        ArtGroup parentGroup1 = context.newObject(ArtGroup.class);
-        parentGroup1.setName("parent1");
-        ArtGroup parentGroup2 = context.newObject(ArtGroup.class);
-        parentGroup2.setName("parent2");
-
-        ArtGroup childGroup1 = context.newObject(ArtGroup.class);
-        childGroup1.setName("child1");
-        childGroup1.setToParentGroup(parentGroup1);
-        childGroup1.setToParentGroup(parentGroup2);
-        context.commitChanges();
-
-        context.deleteObjects(parentGroup1);
-        context.deleteObjects(parentGroup2);
-        context.commitChanges();
-    }
-
-    public void testCommitReplaceCommit() {
-        ArtGroup parentGroup1 = context.newObject(ArtGroup.class);
-        parentGroup1.setName("parent1");
-        ArtGroup parentGroup2 = context.newObject(ArtGroup.class);
-        parentGroup2.setName("parent2");
-
-        ArtGroup childGroup1 = context.newObject(ArtGroup.class);
-        childGroup1.setName("child1");
-        childGroup1.setToParentGroup(parentGroup1);
-        context.commitChanges();
-        childGroup1.setToParentGroup(parentGroup2);
-        context.commitChanges();
-    }
-
-    public void testComplexInsertUpdateOrdering() {
-        ArtGroup parentGroup = context.newObject(ArtGroup.class);
-        parentGroup.setName("parent");
-        context.commitChanges();
-
-        // Check that the update and insert both work write
-        ArtGroup childGroup1 = context.newObject(ArtGroup.class);
-        childGroup1.setName("child1");
-        childGroup1.setToParentGroup(parentGroup);
-        context.commitChanges();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CDOSetRelationshipIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CDOSetRelationshipIT.java b/cayenne-server/src/test/java/org/apache/cayenne/CDOSetRelationshipIT.java
new file mode 100644
index 0000000..213ec75
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/CDOSetRelationshipIT.java
@@ -0,0 +1,195 @@
+/*****************************************************************
+ *   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.exp.ExpressionFactory;
+import org.apache.cayenne.query.RefreshQuery;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
+import org.apache.cayenne.testdo.relationship.SetToMany;
+import org.apache.cayenne.testdo.relationship.SetToManyTarget;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.util.Set;
+
+@UseServerRuntime(ServerCase.RELATIONSHIPS_PROJECT)
+public class CDOSetRelationshipIT extends ServerCase {
+
+    @Inject
+    protected ObjectContext context;
+
+    @Inject
+    protected DBHelper dbHelper;
+
+    protected TableHelper tSetToMany;
+    protected TableHelper tSetToManyTarget;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("SET_TO_MANY_TARGET");
+        dbHelper.deleteAll("SET_TO_MANY");
+
+        tSetToMany = new TableHelper(dbHelper, "SET_TO_MANY");
+        tSetToMany.setColumns("ID");
+
+        tSetToManyTarget = new TableHelper(dbHelper, "SET_TO_MANY_TARGET");
+        tSetToManyTarget.setColumns("ID", "SET_TO_MANY_ID");
+    }
+
+    protected void createTestDataSet() throws Exception {
+        tSetToMany.insert(1);
+        tSetToMany.insert(2);
+        tSetToManyTarget.insert(1, 1);
+        tSetToManyTarget.insert(2, 1);
+        tSetToManyTarget.insert(3, 1);
+        tSetToManyTarget.insert(4, 2);
+    }
+
+    public void testReadToMany() throws Exception {
+        createTestDataSet();
+
+        SetToMany o1 = Cayenne.objectForPK(context, SetToMany.class, 1);
+
+        Set targets = o1.getTargets();
+
+        assertNotNull(targets);
+        assertTrue(((ValueHolder) targets).isFault());
+
+        assertEquals(3, targets.size());
+
+        assertTrue(targets.contains(Cayenne.objectForPK(
+                o1.getObjectContext(),
+                SetToManyTarget.class,
+                1)));
+        assertTrue(targets.contains(Cayenne.objectForPK(
+                o1.getObjectContext(),
+                SetToManyTarget.class,
+                2)));
+        assertTrue(targets.contains(Cayenne.objectForPK(
+                o1.getObjectContext(),
+                SetToManyTarget.class,
+                3)));
+    }
+
+    public void testReadToManyPrefetching() throws Exception {
+        createTestDataSet();
+
+        SelectQuery query = new SelectQuery(SetToMany.class, ExpressionFactory
+                .matchDbExp(SetToMany.ID_PK_COLUMN, new Integer(1)));
+        query.addPrefetch(SetToMany.TARGETS_PROPERTY);
+        SetToMany o1 = (SetToMany) Cayenne.objectForQuery(context, query);
+
+        Set targets = o1.getTargets();
+
+        assertFalse(((ValueHolder) targets).isFault());
+
+        assertNotNull(targets);
+        assertEquals(3, targets.size());
+
+        assertTrue(targets.contains(Cayenne.objectForPK(
+                o1.getObjectContext(),
+                SetToManyTarget.class,
+                1)));
+        assertTrue(targets.contains(Cayenne.objectForPK(
+                o1.getObjectContext(),
+                SetToManyTarget.class,
+                2)));
+        assertTrue(targets.contains(Cayenne.objectForPK(
+                o1.getObjectContext(),
+                SetToManyTarget.class,
+                3)));
+    }
+
+    public void testAddToMany() throws Exception {
+        createTestDataSet();
+
+        SetToMany o1 = Cayenne.objectForPK(context, SetToMany.class, 1);
+
+        Set targets = o1.getTargets();
+        assertNotNull(targets);
+        assertEquals(3, targets.size());
+
+        SetToManyTarget newTarget = o1
+                .getObjectContext()
+                .newObject(SetToManyTarget.class);
+
+        o1.addToTargets(newTarget);
+        assertEquals(4, targets.size());
+        assertTrue(o1.getTargets().contains(newTarget));
+        assertSame(o1, newTarget.getSetToMany());
+
+        o1.getObjectContext().commitChanges();
+
+        o1.getObjectContext().performGenericQuery(new RefreshQuery());
+        assertEquals(4, o1.getTargets().size());
+    }
+
+    public void testRemoveToMany() throws Exception {
+        createTestDataSet();
+
+        SetToMany o1 = Cayenne.objectForPK(context, SetToMany.class, 1);
+
+        Set targets = o1.getTargets();
+        assertEquals(3, targets.size());
+
+        SetToManyTarget target = Cayenne.objectForPK(
+                o1.getObjectContext(),
+                SetToManyTarget.class,
+                2);
+        o1.removeFromTargets(target);
+
+        assertEquals(2, targets.size());
+        assertFalse(o1.getTargets().contains(target));
+        assertNull(target.getSetToMany());
+
+        o1.getObjectContext().commitChanges();
+
+        o1.getObjectContext().performGenericQuery(new RefreshQuery());
+        assertEquals(2, o1.getTargets().size());
+        assertFalse(o1.getTargets().contains(target));
+    }
+
+    public void testAddToManyViaReverse() throws Exception {
+        createTestDataSet();
+
+        SetToMany o1 = Cayenne.objectForPK(context, SetToMany.class, 1);
+
+        Set targets = o1.getTargets();
+        assertNotNull(targets);
+        assertEquals(3, targets.size());
+
+        SetToManyTarget newTarget = o1
+                .getObjectContext()
+                .newObject(SetToManyTarget.class);
+
+        newTarget.setSetToMany(o1);
+        assertEquals(4, targets.size());
+        assertTrue(o1.getTargets().contains(newTarget));
+        assertSame(o1, newTarget.getSetToMany());
+
+        o1.getObjectContext().commitChanges();
+
+        o1.getObjectContext().performGenericQuery(new RefreshQuery());
+        assertEquals(4, o1.getTargets().size());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CDOSetRelationshipTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CDOSetRelationshipTest.java b/cayenne-server/src/test/java/org/apache/cayenne/CDOSetRelationshipTest.java
deleted file mode 100644
index 1d32309..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/CDOSetRelationshipTest.java
+++ /dev/null
@@ -1,195 +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.util.Set;
-
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.exp.ExpressionFactory;
-import org.apache.cayenne.query.RefreshQuery;
-import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.test.jdbc.DBHelper;
-import org.apache.cayenne.test.jdbc.TableHelper;
-import org.apache.cayenne.testdo.relationship.SetToMany;
-import org.apache.cayenne.testdo.relationship.SetToManyTarget;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.RELATIONSHIPS_PROJECT)
-public class CDOSetRelationshipTest extends ServerCase {
-
-    @Inject
-    protected ObjectContext context;
-
-    @Inject
-    protected DBHelper dbHelper;
-
-    protected TableHelper tSetToMany;
-    protected TableHelper tSetToManyTarget;
-
-    @Override
-    protected void setUpAfterInjection() throws Exception {
-        dbHelper.deleteAll("SET_TO_MANY_TARGET");
-        dbHelper.deleteAll("SET_TO_MANY");
-
-        tSetToMany = new TableHelper(dbHelper, "SET_TO_MANY");
-        tSetToMany.setColumns("ID");
-
-        tSetToManyTarget = new TableHelper(dbHelper, "SET_TO_MANY_TARGET");
-        tSetToManyTarget.setColumns("ID", "SET_TO_MANY_ID");
-    }
-
-    protected void createTestDataSet() throws Exception {
-        tSetToMany.insert(1);
-        tSetToMany.insert(2);
-        tSetToManyTarget.insert(1, 1);
-        tSetToManyTarget.insert(2, 1);
-        tSetToManyTarget.insert(3, 1);
-        tSetToManyTarget.insert(4, 2);
-    }
-
-    public void testReadToMany() throws Exception {
-        createTestDataSet();
-
-        SetToMany o1 = Cayenne.objectForPK(context, SetToMany.class, 1);
-
-        Set targets = o1.getTargets();
-
-        assertNotNull(targets);
-        assertTrue(((ValueHolder) targets).isFault());
-
-        assertEquals(3, targets.size());
-
-        assertTrue(targets.contains(Cayenne.objectForPK(
-                o1.getObjectContext(),
-                SetToManyTarget.class,
-                1)));
-        assertTrue(targets.contains(Cayenne.objectForPK(
-                o1.getObjectContext(),
-                SetToManyTarget.class,
-                2)));
-        assertTrue(targets.contains(Cayenne.objectForPK(
-                o1.getObjectContext(),
-                SetToManyTarget.class,
-                3)));
-    }
-
-    public void testReadToManyPrefetching() throws Exception {
-        createTestDataSet();
-
-        SelectQuery query = new SelectQuery(SetToMany.class, ExpressionFactory
-                .matchDbExp(SetToMany.ID_PK_COLUMN, new Integer(1)));
-        query.addPrefetch(SetToMany.TARGETS_PROPERTY);
-        SetToMany o1 = (SetToMany) Cayenne.objectForQuery(context, query);
-
-        Set targets = o1.getTargets();
-
-        assertFalse(((ValueHolder) targets).isFault());
-
-        assertNotNull(targets);
-        assertEquals(3, targets.size());
-
-        assertTrue(targets.contains(Cayenne.objectForPK(
-                o1.getObjectContext(),
-                SetToManyTarget.class,
-                1)));
-        assertTrue(targets.contains(Cayenne.objectForPK(
-                o1.getObjectContext(),
-                SetToManyTarget.class,
-                2)));
-        assertTrue(targets.contains(Cayenne.objectForPK(
-                o1.getObjectContext(),
-                SetToManyTarget.class,
-                3)));
-    }
-
-    public void testAddToMany() throws Exception {
-        createTestDataSet();
-
-        SetToMany o1 = Cayenne.objectForPK(context, SetToMany.class, 1);
-
-        Set targets = o1.getTargets();
-        assertNotNull(targets);
-        assertEquals(3, targets.size());
-
-        SetToManyTarget newTarget = o1
-                .getObjectContext()
-                .newObject(SetToManyTarget.class);
-
-        o1.addToTargets(newTarget);
-        assertEquals(4, targets.size());
-        assertTrue(o1.getTargets().contains(newTarget));
-        assertSame(o1, newTarget.getSetToMany());
-
-        o1.getObjectContext().commitChanges();
-
-        o1.getObjectContext().performGenericQuery(new RefreshQuery());
-        assertEquals(4, o1.getTargets().size());
-    }
-
-    public void testRemoveToMany() throws Exception {
-        createTestDataSet();
-
-        SetToMany o1 = Cayenne.objectForPK(context, SetToMany.class, 1);
-
-        Set targets = o1.getTargets();
-        assertEquals(3, targets.size());
-
-        SetToManyTarget target = Cayenne.objectForPK(
-                o1.getObjectContext(),
-                SetToManyTarget.class,
-                2);
-        o1.removeFromTargets(target);
-
-        assertEquals(2, targets.size());
-        assertFalse(o1.getTargets().contains(target));
-        assertNull(target.getSetToMany());
-
-        o1.getObjectContext().commitChanges();
-
-        o1.getObjectContext().performGenericQuery(new RefreshQuery());
-        assertEquals(2, o1.getTargets().size());
-        assertFalse(o1.getTargets().contains(target));
-    }
-
-    public void testAddToManyViaReverse() throws Exception {
-        createTestDataSet();
-
-        SetToMany o1 = Cayenne.objectForPK(context, SetToMany.class, 1);
-
-        Set targets = o1.getTargets();
-        assertNotNull(targets);
-        assertEquals(3, targets.size());
-
-        SetToManyTarget newTarget = o1
-                .getObjectContext()
-                .newObject(SetToManyTarget.class);
-
-        newTarget.setSetToMany(o1);
-        assertEquals(4, targets.size());
-        assertTrue(o1.getTargets().contains(newTarget));
-        assertSame(o1, newTarget.getSetToMany());
-
-        o1.getObjectContext().commitChanges();
-
-        o1.getObjectContext().performGenericQuery(new RefreshQuery());
-        assertEquals(4, o1.getTargets().size());
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectFlattenedRelIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectFlattenedRelIT.java b/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectFlattenedRelIT.java
new file mode 100644
index 0000000..e6a9730
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectFlattenedRelIT.java
@@ -0,0 +1,280 @@
+/*****************************************************************
+ *   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.access.MockDataNode;
+import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.exp.ExpressionFactory;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
+import org.apache.cayenne.testdo.testmap.ArtGroup;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.unit.di.DataChannelInterceptor;
+import org.apache.cayenne.unit.di.UnitTestClosure;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.sql.Types;
+import java.util.List;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class CayenneDataObjectFlattenedRelIT extends ServerCase {
+
+    @Inject
+    private ServerRuntime runtime;
+
+    @Inject
+    private ObjectContext context;
+
+    @Inject
+    private DBHelper dbHelper;
+
+    @Inject
+    private DataChannelInterceptor queryInterceptor;
+
+    private TableHelper tArtist;
+
+    private TableHelper tArtGroup;
+
+    private TableHelper tArtistGroup;
+
+    @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.update("ARTGROUP").set("PARENT_GROUP_ID", null, Types.INTEGER).execute();
+        dbHelper.deleteAll("ARTGROUP");
+
+        tArtist = new TableHelper(dbHelper, "ARTIST");
+        tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
+
+        tArtGroup = new TableHelper(dbHelper, "ARTGROUP");
+        tArtGroup.setColumns("GROUP_ID", "NAME");
+
+        tArtistGroup = new TableHelper(dbHelper, "ARTIST_GROUP");
+        tArtistGroup.setColumns("ARTIST_ID", "GROUP_ID");
+    }
+
+    private void create1Artist1ArtGroupDataSet() throws Exception {
+        tArtist.insert(33001, "artist1");
+        tArtGroup.insert(1, "g1");
+    }
+
+    private void create1Artist2ArtGroupDataSet() throws Exception {
+        create1Artist1ArtGroupDataSet();
+        tArtGroup.insert(2, "g2");
+    }
+
+    private void create1Artist1ArtGroup1ArtistGroupDataSet() throws Exception {
+        create1Artist1ArtGroupDataSet();
+        tArtistGroup.insert(33001, 1);
+    }
+
+    public void testReadFlattenedRelationship() throws Exception {
+        create1Artist1ArtGroupDataSet();
+
+        Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
+        List<ArtGroup> groupList = a1.getGroupArray();
+        assertNotNull(groupList);
+        assertEquals(0, groupList.size());
+    }
+
+    public void testReadFlattenedRelationship2() throws Exception {
+
+        create1Artist1ArtGroup1ArtistGroupDataSet();
+
+        Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
+        List<ArtGroup> groupList = a1.getGroupArray();
+        assertNotNull(groupList);
+        assertEquals(1, groupList.size());
+        assertEquals(PersistenceState.COMMITTED, groupList.get(0).getPersistenceState());
+        assertEquals("g1", groupList.get(0).getName());
+    }
+
+    public void testAddToFlattenedRelationship() throws Exception {
+
+        create1Artist1ArtGroupDataSet();
+
+        Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
+        assertEquals(0, a1.getGroupArray().size());
+
+        SelectQuery q = new SelectQuery(ArtGroup.class, ExpressionFactory.matchExp(
+                "name",
+                "g1"));
+        List<?> results = context.performQuery(q);
+        assertEquals(1, results.size());
+
+        assertFalse(context.hasChanges());
+        ArtGroup group = (ArtGroup) results.get(0);
+        a1.addToGroupArray(group);
+        assertTrue(context.hasChanges());
+
+        List<?> groupList = a1.getGroupArray();
+        assertEquals(1, groupList.size());
+        assertEquals("g1", ((ArtGroup) groupList.get(0)).getName());
+
+        // Ensure that the commit doesn't fail
+        a1.getObjectContext().commitChanges();
+
+        // and check again
+        assertFalse(context.hasChanges());
+
+        // refetch artist with a different context
+        ObjectContext context2 = runtime.newContext();
+        a1 = Cayenne.objectForPK(context2, Artist.class, 33001);
+        groupList = a1.getGroupArray();
+        assertEquals(1, groupList.size());
+        assertEquals("g1", ((ArtGroup) groupList.get(0)).getName());
+    }
+
+    // Test case to show up a bug in committing more than once
+    public void testDoubleCommitAddToFlattenedRelationship() throws Exception {
+        create1Artist1ArtGroupDataSet();
+
+        Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
+
+        SelectQuery q = new SelectQuery(ArtGroup.class, ExpressionFactory.matchExp(
+                "name",
+                "g1"));
+        List<?> results = context.performQuery(q);
+        assertEquals(1, results.size());
+
+        ArtGroup group = (ArtGroup) results.get(0);
+        a1.addToGroupArray(group);
+
+        List<?> groupList = a1.getGroupArray();
+        assertEquals(1, groupList.size());
+        assertEquals("g1", ((ArtGroup) groupList.get(0)).getName());
+
+        // Ensure that the commit doesn't fail
+        a1.getObjectContext().commitChanges();
+
+        try {
+            // The bug caused the second commit to fail (the link record
+            // was inserted again)
+            a1.getObjectContext().commitChanges();
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+            fail("Should not have thrown an exception");
+        }
+
+    }
+
+    public void testRemoveFromFlattenedRelationship() throws Exception {
+        create1Artist1ArtGroup1ArtistGroupDataSet();
+
+        Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
+
+        ArtGroup group = a1.getGroupArray().get(0);
+        a1.removeFromGroupArray(group);
+
+        List<ArtGroup> groupList = a1.getGroupArray();
+        assertEquals(0, groupList.size());
+
+        // Ensure that the commit doesn't fail
+        a1.getObjectContext().commitChanges();
+
+        // and check again
+        groupList = a1.getGroupArray();
+        assertEquals(0, groupList.size());
+    }
+
+    // Demonstrates a possible bug in ordering of deletes, when a flattened relationships
+    // link record is deleted at the same time (same transaction) as one of the record to
+    // which it links.
+    public void testRemoveFlattenedRelationshipAndRootRecord() throws Exception {
+        create1Artist1ArtGroup1ArtistGroupDataSet();
+        Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
+
+        ArtGroup group = a1.getGroupArray().get(0);
+        a1.removeFromGroupArray(group); // Cause the delete of the link record
+
+        context.deleteObjects(a1); // Cause the deletion of the artist
+
+        try {
+            context.commitChanges();
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+            fail("Should not have thrown the exception :" + e.getMessage());
+        }
+    }
+
+    public void testAddRemoveFlattenedRelationship1() throws Exception {
+        create1Artist1ArtGroupDataSet();
+
+        Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
+
+        SelectQuery q = new SelectQuery(ArtGroup.class, ExpressionFactory.matchExp(
+                "name",
+                "g1"));
+        List<?> results = context.performQuery(q);
+        assertEquals(1, results.size());
+
+        ArtGroup group = (ArtGroup) results.get(0);
+        a1.addToGroupArray(group);
+        group.removeFromArtistArray(a1);
+
+        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+            public void execute() {
+                context.commitChanges();
+            }
+        });
+    }
+
+    public void testAddRemoveFlattenedRelationship2() throws Exception {
+        create1Artist2ArtGroupDataSet();
+
+        Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
+
+        SelectQuery q = new SelectQuery(ArtGroup.class);
+        List<?> results = context.performQuery(q);
+        assertEquals(2, results.size());
+
+        ArtGroup g1 = (ArtGroup) results.get(0);
+        ArtGroup g2 = (ArtGroup) results.get(1);
+        a1.addToGroupArray(g1);
+        a1.addToGroupArray(g2);
+
+        // test that there is no delete query issued when a flattened join is first
+        // added and then deleted AND there are some other changes (CAY-548)
+        a1.removeFromGroupArray(g1);
+
+        MockDataNode nodeWrapper = MockDataNode.interceptNode(
+                runtime.getDataDomain(),
+                runtime.getDataDomain().getDataNodes().iterator().next());
+        try {
+            context.commitChanges();
+
+        }
+        finally {
+            nodeWrapper.stopInterceptNode();
+        }
+
+        assertEquals(1, nodeWrapper.getRunCount());
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectFlattenedRelTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectFlattenedRelTest.java b/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectFlattenedRelTest.java
deleted file mode 100644
index 44b0f0d..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectFlattenedRelTest.java
+++ /dev/null
@@ -1,280 +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.util.List;
-import java.sql.Types;
-
-import org.apache.cayenne.access.MockDataNode;
-import org.apache.cayenne.configuration.server.ServerRuntime;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.exp.ExpressionFactory;
-import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.test.jdbc.DBHelper;
-import org.apache.cayenne.test.jdbc.TableHelper;
-import org.apache.cayenne.testdo.testmap.ArtGroup;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.unit.di.DataChannelInterceptor;
-import org.apache.cayenne.unit.di.UnitTestClosure;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class CayenneDataObjectFlattenedRelTest extends ServerCase {
-
-    @Inject
-    private ServerRuntime runtime;
-
-    @Inject
-    private ObjectContext context;
-
-    @Inject
-    private DBHelper dbHelper;
-
-    @Inject
-    private DataChannelInterceptor queryInterceptor;
-
-    private TableHelper tArtist;
-
-    private TableHelper tArtGroup;
-
-    private TableHelper tArtistGroup;
-
-    @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.update("ARTGROUP").set("PARENT_GROUP_ID", null, Types.INTEGER).execute();
-        dbHelper.deleteAll("ARTGROUP");
-
-        tArtist = new TableHelper(dbHelper, "ARTIST");
-        tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
-
-        tArtGroup = new TableHelper(dbHelper, "ARTGROUP");
-        tArtGroup.setColumns("GROUP_ID", "NAME");
-
-        tArtistGroup = new TableHelper(dbHelper, "ARTIST_GROUP");
-        tArtistGroup.setColumns("ARTIST_ID", "GROUP_ID");
-    }
-
-    private void create1Artist1ArtGroupDataSet() throws Exception {
-        tArtist.insert(33001, "artist1");
-        tArtGroup.insert(1, "g1");
-    }
-
-    private void create1Artist2ArtGroupDataSet() throws Exception {
-        create1Artist1ArtGroupDataSet();
-        tArtGroup.insert(2, "g2");
-    }
-
-    private void create1Artist1ArtGroup1ArtistGroupDataSet() throws Exception {
-        create1Artist1ArtGroupDataSet();
-        tArtistGroup.insert(33001, 1);
-    }
-
-    public void testReadFlattenedRelationship() throws Exception {
-        create1Artist1ArtGroupDataSet();
-
-        Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
-        List<ArtGroup> groupList = a1.getGroupArray();
-        assertNotNull(groupList);
-        assertEquals(0, groupList.size());
-    }
-
-    public void testReadFlattenedRelationship2() throws Exception {
-
-        create1Artist1ArtGroup1ArtistGroupDataSet();
-
-        Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
-        List<ArtGroup> groupList = a1.getGroupArray();
-        assertNotNull(groupList);
-        assertEquals(1, groupList.size());
-        assertEquals(PersistenceState.COMMITTED, groupList.get(0).getPersistenceState());
-        assertEquals("g1", groupList.get(0).getName());
-    }
-
-    public void testAddToFlattenedRelationship() throws Exception {
-
-        create1Artist1ArtGroupDataSet();
-
-        Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
-        assertEquals(0, a1.getGroupArray().size());
-
-        SelectQuery q = new SelectQuery(ArtGroup.class, ExpressionFactory.matchExp(
-                "name",
-                "g1"));
-        List<?> results = context.performQuery(q);
-        assertEquals(1, results.size());
-
-        assertFalse(context.hasChanges());
-        ArtGroup group = (ArtGroup) results.get(0);
-        a1.addToGroupArray(group);
-        assertTrue(context.hasChanges());
-
-        List<?> groupList = a1.getGroupArray();
-        assertEquals(1, groupList.size());
-        assertEquals("g1", ((ArtGroup) groupList.get(0)).getName());
-
-        // Ensure that the commit doesn't fail
-        a1.getObjectContext().commitChanges();
-
-        // and check again
-        assertFalse(context.hasChanges());
-
-        // refetch artist with a different context
-        ObjectContext context2 = runtime.newContext();
-        a1 = Cayenne.objectForPK(context2, Artist.class, 33001);
-        groupList = a1.getGroupArray();
-        assertEquals(1, groupList.size());
-        assertEquals("g1", ((ArtGroup) groupList.get(0)).getName());
-    }
-
-    // Test case to show up a bug in committing more than once
-    public void testDoubleCommitAddToFlattenedRelationship() throws Exception {
-        create1Artist1ArtGroupDataSet();
-
-        Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
-
-        SelectQuery q = new SelectQuery(ArtGroup.class, ExpressionFactory.matchExp(
-                "name",
-                "g1"));
-        List<?> results = context.performQuery(q);
-        assertEquals(1, results.size());
-
-        ArtGroup group = (ArtGroup) results.get(0);
-        a1.addToGroupArray(group);
-
-        List<?> groupList = a1.getGroupArray();
-        assertEquals(1, groupList.size());
-        assertEquals("g1", ((ArtGroup) groupList.get(0)).getName());
-
-        // Ensure that the commit doesn't fail
-        a1.getObjectContext().commitChanges();
-
-        try {
-            // The bug caused the second commit to fail (the link record
-            // was inserted again)
-            a1.getObjectContext().commitChanges();
-        }
-        catch (Exception e) {
-            e.printStackTrace();
-            fail("Should not have thrown an exception");
-        }
-
-    }
-
-    public void testRemoveFromFlattenedRelationship() throws Exception {
-        create1Artist1ArtGroup1ArtistGroupDataSet();
-
-        Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
-
-        ArtGroup group = a1.getGroupArray().get(0);
-        a1.removeFromGroupArray(group);
-
-        List<ArtGroup> groupList = a1.getGroupArray();
-        assertEquals(0, groupList.size());
-
-        // Ensure that the commit doesn't fail
-        a1.getObjectContext().commitChanges();
-
-        // and check again
-        groupList = a1.getGroupArray();
-        assertEquals(0, groupList.size());
-    }
-
-    // Demonstrates a possible bug in ordering of deletes, when a flattened relationships
-    // link record is deleted at the same time (same transaction) as one of the record to
-    // which it links.
-    public void testRemoveFlattenedRelationshipAndRootRecord() throws Exception {
-        create1Artist1ArtGroup1ArtistGroupDataSet();
-        Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
-
-        ArtGroup group = a1.getGroupArray().get(0);
-        a1.removeFromGroupArray(group); // Cause the delete of the link record
-
-        context.deleteObjects(a1); // Cause the deletion of the artist
-
-        try {
-            context.commitChanges();
-        }
-        catch (Exception e) {
-            e.printStackTrace();
-            fail("Should not have thrown the exception :" + e.getMessage());
-        }
-    }
-
-    public void testAddRemoveFlattenedRelationship1() throws Exception {
-        create1Artist1ArtGroupDataSet();
-
-        Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
-
-        SelectQuery q = new SelectQuery(ArtGroup.class, ExpressionFactory.matchExp(
-                "name",
-                "g1"));
-        List<?> results = context.performQuery(q);
-        assertEquals(1, results.size());
-
-        ArtGroup group = (ArtGroup) results.get(0);
-        a1.addToGroupArray(group);
-        group.removeFromArtistArray(a1);
-
-        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
-
-            public void execute() {
-                context.commitChanges();
-            }
-        });
-    }
-
-    public void testAddRemoveFlattenedRelationship2() throws Exception {
-        create1Artist2ArtGroupDataSet();
-
-        Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
-
-        SelectQuery q = new SelectQuery(ArtGroup.class);
-        List<?> results = context.performQuery(q);
-        assertEquals(2, results.size());
-
-        ArtGroup g1 = (ArtGroup) results.get(0);
-        ArtGroup g2 = (ArtGroup) results.get(1);
-        a1.addToGroupArray(g1);
-        a1.addToGroupArray(g2);
-
-        // test that there is no delete query issued when a flattened join is first
-        // added and then deleted AND there are some other changes (CAY-548)
-        a1.removeFromGroupArray(g1);
-
-        MockDataNode nodeWrapper = MockDataNode.interceptNode(
-                runtime.getDataDomain(),
-                runtime.getDataDomain().getDataNodes().iterator().next());
-        try {
-            context.commitChanges();
-
-        }
-        finally {
-            nodeWrapper.stopInterceptNode();
-        }
-
-        assertEquals(1, nodeWrapper.getRunCount());
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectIT.java b/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectIT.java
new file mode 100644
index 0000000..c0e90c9
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectIT.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;
+
+import java.util.ArrayList;
+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.testdo.testmap.Artist;
+import org.apache.cayenne.testdo.testmap.ArtistExhibit;
+import org.apache.cayenne.testdo.testmap.Painting;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+import org.apache.cayenne.unit.util.TstBean;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class CayenneDataObjectIT extends ServerCase {
+
+    @Inject
+    private ObjectContext context;
+
+    public void testSetObjectId() throws Exception {
+        CayenneDataObject object = new CayenneDataObject();
+        ObjectId oid = new ObjectId("T");
+
+        assertNull(object.getObjectId());
+
+        object.setObjectId(oid);
+        assertSame(oid, object.getObjectId());
+    }
+
+    public void testSetPersistenceState() throws Exception {
+        CayenneDataObject obj = new CayenneDataObject();
+        assertEquals(PersistenceState.TRANSIENT, obj.getPersistenceState());
+
+        obj.setPersistenceState(PersistenceState.COMMITTED);
+        assertEquals(PersistenceState.COMMITTED, obj.getPersistenceState());
+    }
+
+    public void testReadNestedProperty1() throws Exception {
+        Artist a = new Artist();
+        assertNull(a.readNestedProperty("artistName"));
+        a.setArtistName("aaa");
+        assertEquals("aaa", a.readNestedProperty("artistName"));
+    }
+
+    public void testReadNestedPropertyNotPersistentString() throws Exception {
+        Artist a = new Artist();
+        assertNull(a.readNestedProperty("someOtherProperty"));
+        a.setSomeOtherProperty("aaa");
+        assertEquals("aaa", a.readNestedProperty("someOtherProperty"));
+    }
+
+    public void testReadNestedPropertyNonPersistentNotString() throws Exception {
+        Artist a = new Artist();
+        Object object = new Object();
+        assertNull(a.readNestedProperty("someOtherObjectProperty"));
+        a.setSomeOtherObjectProperty(object);
+        assertSame(object, a.readNestedProperty("someOtherObjectProperty"));
+    }
+
+    public void testReadNestedPropertyNonDataObjectPath() {
+        CayenneDataObject o1 = new CayenneDataObject();
+        TstBean o2 = new TstBean();
+        o2.setInteger(new Integer(55));
+        o1.writePropertyDirectly("o2", o2);
+
+        assertSame(o2, o1.readNestedProperty("o2"));
+        assertEquals(new Integer(55), o1.readNestedProperty("o2.integer"));
+        assertEquals(TstBean.class, o1.readNestedProperty("o2.class"));
+        assertEquals(TstBean.class.getName(), o1.readNestedProperty("o2.class.name"));
+    }
+
+    public void testReadNestedPropertyToManyInMiddle() throws Exception {
+
+        Artist a = context.newObject(Artist.class);
+        ArtistExhibit ex = context.newObject(ArtistExhibit.class);
+        Painting p1 = context.newObject(Painting.class);
+        Painting p2 = context.newObject(Painting.class);
+        p1.setPaintingTitle("p1");
+        p2.setPaintingTitle("p2");
+        a.addToPaintingArray(p1);
+        a.addToPaintingArray(p2);
+        ex.setToArtist(a);
+
+        List<String> names = (List<String>) a
+                .readNestedProperty("paintingArray.paintingTitle");
+        assertEquals(names.size(), 2);
+        assertEquals(names.get(0), "p1");
+        assertEquals(names.get(1), "p2");
+
+        List<String> names2 = (List<String>) ex
+                .readNestedProperty("toArtist.paintingArray.paintingTitle");
+        assertEquals(names, names2);
+    }
+
+    public void testReadNestedPropertyToManyInMiddle1() throws Exception {
+
+        Artist a = context.newObject(Artist.class);
+        ArtistExhibit ex = context.newObject(ArtistExhibit.class);
+        Painting p1 = context.newObject(Painting.class);
+        Painting p2 = context.newObject(Painting.class);
+        p1.setPaintingTitle("p1");
+        p2.setPaintingTitle("p2");
+        a.addToPaintingArray(p1);
+        a.addToPaintingArray(p2);
+        ex.setToArtist(a);
+
+        List<String> names = (List<String>) a
+                .readNestedProperty("paintingArray+.paintingTitle");
+        assertEquals(names.size(), 2);
+        assertEquals(names.get(0), "p1");
+        assertEquals(names.get(1), "p2");
+
+        List<String> names2 = (List<String>) ex
+                .readNestedProperty("toArtist.paintingArray+.paintingTitle");
+        assertEquals(names, names2);
+    }
+
+    public void testFilterObjects() {
+
+        List<Painting> paintingList = new ArrayList<Painting>();
+        Painting p1 = context.newObject(Painting.class);
+        Artist a1 = context.newObject(Artist.class);
+        a1.setArtistName("dddAd");
+        p1.setToArtist(a1);
+
+        paintingList.add(p1);
+        Expression exp = ExpressionFactory.likeExp("toArtist+.artistName", "d%");
+
+        List<Painting> rezult = exp.filterObjects(paintingList);
+        assertEquals(a1, rezult.get(0).getToArtist());
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectInContextIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectInContextIT.java b/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectInContextIT.java
new file mode 100644
index 0000000..aaa7c70
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectInContextIT.java
@@ -0,0 +1,308 @@
+/*****************************************************************
+ *   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.access.DataContext;
+import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.exp.ExpressionFactory;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.util.List;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class CayenneDataObjectInContextIT extends ServerCase {
+
+    @Inject
+    protected ServerRuntime runtime;
+
+    @Inject
+    protected DataContext context;
+
+    @Inject
+    protected DBHelper dbHelper;
+
+    protected TableHelper tArtist;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("PAINTING_INFO");
+        dbHelper.deleteAll("PAINTING");
+        dbHelper.deleteAll("ARTIST_EXHIBIT");
+        dbHelper.deleteAll("ARTIST_GROUP");
+        dbHelper.deleteAll("ARTIST");
+
+        tArtist = new TableHelper(dbHelper, "ARTIST");
+        tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
+    }
+
+    public void testDoubleRegistration() {
+
+        DataObject object = new Artist();
+        assertNull(object.getObjectId());
+
+        context.registerNewObject(object);
+        ObjectId tempID = object.getObjectId();
+        assertNotNull(tempID);
+        assertTrue(tempID.isTemporary());
+        assertSame(context, object.getObjectContext());
+
+        // double registration in the same context should be quietly ignored
+        context.registerNewObject(object);
+        assertSame(tempID, object.getObjectId());
+        assertSame(object, context.getGraphManager().getNode(tempID));
+
+        // registering in another context should throw an exception
+        ObjectContext anotherContext = runtime.newContext();
+        try {
+            anotherContext.registerNewObject(object);
+            fail("registerNewObject should've failed - object is already in another context");
+        }
+        catch (IllegalStateException e) {
+            // expected
+        }
+    }
+
+    public void testCommitChangesInBatch() {
+
+        Artist a1 = context.newObject(Artist.class);
+        a1.setArtistName("abc1");
+
+        Artist a2 = context.newObject(Artist.class);
+        a2.setArtistName("abc2");
+
+        Artist a3 = context.newObject(Artist.class);
+        a3.setArtistName("abc3");
+
+        context.commitChanges();
+
+        List<Artist> artists = context.performQuery(new SelectQuery(Artist.class));
+        assertEquals(3, artists.size());
+    }
+
+    public void testSetObjectId() {
+
+        Artist o1 = new Artist();
+        assertNull(o1.getObjectId());
+
+        context.registerNewObject(o1);
+        assertNotNull(o1.getObjectId());
+    }
+
+    public void testStateTransToNew() {
+
+        Artist o1 = new Artist();
+        assertEquals(PersistenceState.TRANSIENT, o1.getPersistenceState());
+
+        context.registerNewObject(o1);
+        assertEquals(PersistenceState.NEW, o1.getPersistenceState());
+    }
+
+    public void testStateNewToCommitted() {
+
+        Artist o1 = new Artist();
+        o1.setArtistName("a");
+
+        context.registerNewObject(o1);
+        assertEquals(PersistenceState.NEW, o1.getPersistenceState());
+
+        context.commitChanges();
+        assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
+    }
+
+    public void testStateCommittedToModified() {
+
+        Artist o1 = new Artist();
+        o1.setArtistName("a");
+        context.registerNewObject(o1);
+        context.commitChanges();
+        assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
+
+        o1.setArtistName(o1.getArtistName() + "_1");
+        assertEquals(PersistenceState.MODIFIED, o1.getPersistenceState());
+    }
+
+    public void testStateModifiedToCommitted() {
+
+        Artist o1 = context.newObject(Artist.class);
+        o1.setArtistName("qY");
+        context.commitChanges();
+
+        o1.setArtistName(o1.getArtistName() + "_1");
+        assertEquals(PersistenceState.MODIFIED, o1.getPersistenceState());
+
+        context.commitChanges();
+        assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
+    }
+
+    public void testStateCommittedToDeleted() {
+
+        Artist o1 = new Artist();
+        o1.setArtistName("a");
+        context.registerNewObject(o1);
+        context.commitChanges();
+        assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
+
+        context.deleteObjects(o1);
+        assertEquals(PersistenceState.DELETED, o1.getPersistenceState());
+    }
+
+    public void testStateDeletedToTransient() {
+
+        Artist o1 = context.newObject(Artist.class);
+        o1.setArtistName("qY");
+        context.commitChanges();
+
+        context.deleteObjects(o1);
+        assertEquals(PersistenceState.DELETED, o1.getPersistenceState());
+
+        context.commitChanges();
+        assertEquals(PersistenceState.TRANSIENT, o1.getPersistenceState());
+        assertFalse(context.getGraphManager().registeredNodes().contains(o1));
+        assertNull(o1.getObjectContext());
+    }
+
+    public void testSetContext() {
+
+        Artist o1 = new Artist();
+        assertNull(o1.getObjectContext());
+
+        context.registerNewObject(o1);
+        assertSame(context, o1.getObjectContext());
+    }
+
+    public void testFetchByAttribute() throws Exception {
+
+        tArtist.insert(7, "m6");
+
+        SelectQuery q = new SelectQuery(Artist.class, ExpressionFactory.matchExp(
+                Artist.ARTIST_NAME_PROPERTY,
+                "m6"));
+
+        List<Artist> artists = context.performQuery(q);
+        assertEquals(1, artists.size());
+        Artist o1 = artists.get(0);
+        assertNotNull(o1);
+        assertEquals("m6", o1.getArtistName());
+    }
+
+    public void testUniquing() throws Exception {
+
+        tArtist.insert(7, "m6");
+
+        SelectQuery q = new SelectQuery(Artist.class, ExpressionFactory.matchExp(
+                Artist.ARTIST_NAME_PROPERTY,
+                "m6"));
+
+        Artist a1 = (Artist) Cayenne.objectForQuery(context, q);
+        Artist a2 = (Artist) Cayenne.objectForQuery(context, q);
+
+        assertNotNull(a1);
+        assertNotNull(a2);
+        assertEquals(1, context.getGraphManager().registeredNodes().size());
+        assertSame(a1, a2);
+    }
+
+    public void testSnapshotVersion1() {
+
+        Artist artist = context.newObject(Artist.class);
+        assertEquals(DataObject.DEFAULT_VERSION, artist.getSnapshotVersion());
+
+        // test versions set on commit
+
+        artist.setArtistName("abc");
+        context.commitChanges();
+
+        DataRow cachedSnapshot = context.getObjectStore().getCachedSnapshot(
+                artist.getObjectId());
+
+        assertNotNull(cachedSnapshot);
+        assertEquals(cachedSnapshot.getVersion(), artist.getSnapshotVersion());
+    }
+
+    public void testSnapshotVersion2() throws Exception {
+
+        tArtist.insert(7, "m6");
+
+        // test versions assigned on fetch... clean up domain cache
+
+        List<Artist> artists = context.performQuery(new SelectQuery(Artist.class));
+        Artist artist = artists.get(0);
+
+        assertFalse(DataObject.DEFAULT_VERSION == artist.getSnapshotVersion());
+        assertEquals(context
+                .getObjectStore()
+                .getCachedSnapshot(artist.getObjectId())
+                .getVersion(), artist.getSnapshotVersion());
+    }
+
+    public void testSnapshotVersion3() {
+
+        Artist artist = context.newObject(Artist.class);
+        artist.setArtistName("qY");
+        context.commitChanges();
+
+        // test versions assigned after update
+        long oldVersion = artist.getSnapshotVersion();
+
+        artist.setArtistName(artist.getArtistName() + "---");
+        context.commitChanges();
+
+        assertFalse(oldVersion == artist.getSnapshotVersion());
+        assertEquals(context
+                .getObjectStore()
+                .getCachedSnapshot(artist.getObjectId())
+                .getVersion(), artist.getSnapshotVersion());
+    }
+
+    /**
+     * Tests a condition when user substitutes object id of a new object instead of
+     * setting replacement. This is demonstrated here -
+     * http://objectstyle.org/cayenne/lists/cayenne-user/2005/01/0210.html
+     */
+    public void testObjectsCommittedManualOID() {
+
+        Artist object = context.newObject(Artist.class);
+        object.setArtistName("ABC1");
+        assertEquals(PersistenceState.NEW, object.getPersistenceState());
+
+        // do a manual id substitution
+        object.setObjectId(new ObjectId(
+                "Artist",
+                Artist.ARTIST_ID_PK_COLUMN,
+                new Integer(3)));
+
+        context.commitChanges();
+        assertEquals(PersistenceState.COMMITTED, object.getPersistenceState());
+
+        // refetch
+        context.invalidateObjects(object);
+
+        Artist object2 = Cayenne.objectForPK(context, Artist.class, 3);
+        assertNotNull(object2);
+        assertEquals("ABC1", object2.getArtistName());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectInContextTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectInContextTest.java b/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectInContextTest.java
deleted file mode 100644
index 9034056..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/CayenneDataObjectInContextTest.java
+++ /dev/null
@@ -1,308 +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.util.List;
-
-import org.apache.cayenne.access.DataContext;
-import org.apache.cayenne.configuration.server.ServerRuntime;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.exp.ExpressionFactory;
-import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.test.jdbc.DBHelper;
-import org.apache.cayenne.test.jdbc.TableHelper;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class CayenneDataObjectInContextTest extends ServerCase {
-
-    @Inject
-    protected ServerRuntime runtime;
-
-    @Inject
-    protected DataContext context;
-
-    @Inject
-    protected DBHelper dbHelper;
-
-    protected TableHelper tArtist;
-
-    @Override
-    protected void setUpAfterInjection() throws Exception {
-        dbHelper.deleteAll("PAINTING_INFO");
-        dbHelper.deleteAll("PAINTING");
-        dbHelper.deleteAll("ARTIST_EXHIBIT");
-        dbHelper.deleteAll("ARTIST_GROUP");
-        dbHelper.deleteAll("ARTIST");
-
-        tArtist = new TableHelper(dbHelper, "ARTIST");
-        tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
-    }
-
-    public void testDoubleRegistration() {
-
-        DataObject object = new Artist();
-        assertNull(object.getObjectId());
-
-        context.registerNewObject(object);
-        ObjectId tempID = object.getObjectId();
-        assertNotNull(tempID);
-        assertTrue(tempID.isTemporary());
-        assertSame(context, object.getObjectContext());
-
-        // double registration in the same context should be quietly ignored
-        context.registerNewObject(object);
-        assertSame(tempID, object.getObjectId());
-        assertSame(object, context.getGraphManager().getNode(tempID));
-
-        // registering in another context should throw an exception
-        ObjectContext anotherContext = runtime.newContext();
-        try {
-            anotherContext.registerNewObject(object);
-            fail("registerNewObject should've failed - object is already in another context");
-        }
-        catch (IllegalStateException e) {
-            // expected
-        }
-    }
-
-    public void testCommitChangesInBatch() {
-
-        Artist a1 = context.newObject(Artist.class);
-        a1.setArtistName("abc1");
-
-        Artist a2 = context.newObject(Artist.class);
-        a2.setArtistName("abc2");
-
-        Artist a3 = context.newObject(Artist.class);
-        a3.setArtistName("abc3");
-
-        context.commitChanges();
-
-        List<Artist> artists = context.performQuery(new SelectQuery(Artist.class));
-        assertEquals(3, artists.size());
-    }
-
-    public void testSetObjectId() {
-
-        Artist o1 = new Artist();
-        assertNull(o1.getObjectId());
-
-        context.registerNewObject(o1);
-        assertNotNull(o1.getObjectId());
-    }
-
-    public void testStateTransToNew() {
-
-        Artist o1 = new Artist();
-        assertEquals(PersistenceState.TRANSIENT, o1.getPersistenceState());
-
-        context.registerNewObject(o1);
-        assertEquals(PersistenceState.NEW, o1.getPersistenceState());
-    }
-
-    public void testStateNewToCommitted() {
-
-        Artist o1 = new Artist();
-        o1.setArtistName("a");
-
-        context.registerNewObject(o1);
-        assertEquals(PersistenceState.NEW, o1.getPersistenceState());
-
-        context.commitChanges();
-        assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
-    }
-
-    public void testStateCommittedToModified() {
-
-        Artist o1 = new Artist();
-        o1.setArtistName("a");
-        context.registerNewObject(o1);
-        context.commitChanges();
-        assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
-
-        o1.setArtistName(o1.getArtistName() + "_1");
-        assertEquals(PersistenceState.MODIFIED, o1.getPersistenceState());
-    }
-
-    public void testStateModifiedToCommitted() {
-
-        Artist o1 = context.newObject(Artist.class);
-        o1.setArtistName("qY");
-        context.commitChanges();
-
-        o1.setArtistName(o1.getArtistName() + "_1");
-        assertEquals(PersistenceState.MODIFIED, o1.getPersistenceState());
-
-        context.commitChanges();
-        assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
-    }
-
-    public void testStateCommittedToDeleted() {
-
-        Artist o1 = new Artist();
-        o1.setArtistName("a");
-        context.registerNewObject(o1);
-        context.commitChanges();
-        assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
-
-        context.deleteObjects(o1);
-        assertEquals(PersistenceState.DELETED, o1.getPersistenceState());
-    }
-
-    public void testStateDeletedToTransient() {
-
-        Artist o1 = context.newObject(Artist.class);
-        o1.setArtistName("qY");
-        context.commitChanges();
-
-        context.deleteObjects(o1);
-        assertEquals(PersistenceState.DELETED, o1.getPersistenceState());
-
-        context.commitChanges();
-        assertEquals(PersistenceState.TRANSIENT, o1.getPersistenceState());
-        assertFalse(context.getGraphManager().registeredNodes().contains(o1));
-        assertNull(o1.getObjectContext());
-    }
-
-    public void testSetContext() {
-
-        Artist o1 = new Artist();
-        assertNull(o1.getObjectContext());
-
-        context.registerNewObject(o1);
-        assertSame(context, o1.getObjectContext());
-    }
-
-    public void testFetchByAttribute() throws Exception {
-
-        tArtist.insert(7, "m6");
-
-        SelectQuery q = new SelectQuery(Artist.class, ExpressionFactory.matchExp(
-                Artist.ARTIST_NAME_PROPERTY,
-                "m6"));
-
-        List<Artist> artists = context.performQuery(q);
-        assertEquals(1, artists.size());
-        Artist o1 = artists.get(0);
-        assertNotNull(o1);
-        assertEquals("m6", o1.getArtistName());
-    }
-
-    public void testUniquing() throws Exception {
-
-        tArtist.insert(7, "m6");
-
-        SelectQuery q = new SelectQuery(Artist.class, ExpressionFactory.matchExp(
-                Artist.ARTIST_NAME_PROPERTY,
-                "m6"));
-
-        Artist a1 = (Artist) Cayenne.objectForQuery(context, q);
-        Artist a2 = (Artist) Cayenne.objectForQuery(context, q);
-
-        assertNotNull(a1);
-        assertNotNull(a2);
-        assertEquals(1, context.getGraphManager().registeredNodes().size());
-        assertSame(a1, a2);
-    }
-
-    public void testSnapshotVersion1() {
-
-        Artist artist = context.newObject(Artist.class);
-        assertEquals(DataObject.DEFAULT_VERSION, artist.getSnapshotVersion());
-
-        // test versions set on commit
-
-        artist.setArtistName("abc");
-        context.commitChanges();
-
-        DataRow cachedSnapshot = context.getObjectStore().getCachedSnapshot(
-                artist.getObjectId());
-
-        assertNotNull(cachedSnapshot);
-        assertEquals(cachedSnapshot.getVersion(), artist.getSnapshotVersion());
-    }
-
-    public void testSnapshotVersion2() throws Exception {
-
-        tArtist.insert(7, "m6");
-
-        // test versions assigned on fetch... clean up domain cache
-
-        List<Artist> artists = context.performQuery(new SelectQuery(Artist.class));
-        Artist artist = artists.get(0);
-
-        assertFalse(DataObject.DEFAULT_VERSION == artist.getSnapshotVersion());
-        assertEquals(context
-                .getObjectStore()
-                .getCachedSnapshot(artist.getObjectId())
-                .getVersion(), artist.getSnapshotVersion());
-    }
-
-    public void testSnapshotVersion3() {
-
-        Artist artist = context.newObject(Artist.class);
-        artist.setArtistName("qY");
-        context.commitChanges();
-
-        // test versions assigned after update
-        long oldVersion = artist.getSnapshotVersion();
-
-        artist.setArtistName(artist.getArtistName() + "---");
-        context.commitChanges();
-
-        assertFalse(oldVersion == artist.getSnapshotVersion());
-        assertEquals(context
-                .getObjectStore()
-                .getCachedSnapshot(artist.getObjectId())
-                .getVersion(), artist.getSnapshotVersion());
-    }
-
-    /**
-     * Tests a condition when user substitutes object id of a new object instead of
-     * setting replacement. This is demonstrated here -
-     * http://objectstyle.org/cayenne/lists/cayenne-user/2005/01/0210.html
-     */
-    public void testObjectsCommittedManualOID() {
-
-        Artist object = context.newObject(Artist.class);
-        object.setArtistName("ABC1");
-        assertEquals(PersistenceState.NEW, object.getPersistenceState());
-
-        // do a manual id substitution
-        object.setObjectId(new ObjectId(
-                "Artist",
-                Artist.ARTIST_ID_PK_COLUMN,
-                new Integer(3)));
-
-        context.commitChanges();
-        assertEquals(PersistenceState.COMMITTED, object.getPersistenceState());
-
-        // refetch
-        context.invalidateObjects(object);
-
-        Artist object2 = Cayenne.objectForPK(context, Artist.class, 3);
-        assertNotNull(object2);
-        assertEquals("ABC1", object2.getArtistName());
-    }
-
-}