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:34 UTC
[46/48] Installing Maven Failsafe Plugin
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CDOMapRelationshipIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CDOMapRelationshipIT.java b/cayenne-server/src/test/java/org/apache/cayenne/CDOMapRelationshipIT.java
new file mode 100644
index 0000000..7323dd7
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/CDOMapRelationshipIT.java
@@ -0,0 +1,234 @@
+/*****************************************************************
+ * 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.IdMapToMany;
+import org.apache.cayenne.testdo.relationship.MapToMany;
+import org.apache.cayenne.testdo.relationship.MapToManyTarget;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.util.Map;
+
+@UseServerRuntime(ServerCase.RELATIONSHIPS_PROJECT)
+public class CDOMapRelationshipIT extends ServerCase {
+
+ @Inject
+ protected ObjectContext context;
+
+ @Inject
+ protected DBHelper dbHelper;
+
+ protected TableHelper tMapToMany;
+ protected TableHelper tMapToManyTarget;
+ protected TableHelper tIdMapToMany;
+ protected TableHelper tIdMapToManyTarget;
+
+ @Override
+ protected void setUpAfterInjection() throws Exception {
+ dbHelper.deleteAll("MAP_TO_MANY_TARGET");
+ dbHelper.deleteAll("MAP_TO_MANY");
+
+ dbHelper.deleteAll("ID_MAP_TO_MANY_TARGET");
+ dbHelper.deleteAll("ID_MAP_TO_MANY");
+
+ tMapToMany = new TableHelper(dbHelper, "MAP_TO_MANY");
+ tMapToMany.setColumns("ID");
+
+ tMapToManyTarget = new TableHelper(dbHelper, "MAP_TO_MANY_TARGET");
+ tMapToManyTarget.setColumns("ID", "MAP_TO_MANY_ID", "NAME");
+
+ tIdMapToMany = new TableHelper(dbHelper, "ID_MAP_TO_MANY");
+ tIdMapToMany.setColumns("ID");
+
+ tIdMapToManyTarget = new TableHelper(dbHelper, "ID_MAP_TO_MANY_TARGET");
+ tIdMapToManyTarget.setColumns("ID", "MAP_TO_MANY_ID");
+ }
+
+ protected void createTestDataSet() throws Exception {
+ tMapToMany.insert(1);
+ tMapToMany.insert(2);
+ tMapToManyTarget.insert(1, 1, "A");
+ tMapToManyTarget.insert(2, 1, "B");
+ tMapToManyTarget.insert(3, 1, "C");
+ tMapToManyTarget.insert(4, 2, "A");
+ }
+
+ protected void createTestIdDataSet() throws Exception {
+ tIdMapToMany.insert(1);
+ tIdMapToMany.insert(2);
+ tIdMapToManyTarget.insert(1, 1);
+ tIdMapToManyTarget.insert(2, 1);
+ tIdMapToManyTarget.insert(3, 1);
+ tIdMapToManyTarget.insert(4, 2);
+ }
+
+ public void testReadToMany() throws Exception {
+ createTestDataSet();
+
+ MapToMany o1 = Cayenne.objectForPK(context, MapToMany.class, 1);
+
+ Map targets = o1.getTargets();
+
+ assertTrue(((ValueHolder) targets).isFault());
+
+ assertNotNull(targets);
+ assertEquals(3, targets.size());
+ assertNotNull(targets.get("A"));
+ assertNotNull(targets.get("B"));
+ assertNotNull(targets.get("C"));
+
+ assertEquals(1, Cayenne.intPKForObject((Persistent) targets.get("A")));
+ assertEquals(2, Cayenne.intPKForObject((Persistent) targets.get("B")));
+ assertEquals(3, Cayenne.intPKForObject((Persistent) targets.get("C")));
+ }
+
+ public void testReadToManyId() throws Exception {
+ createTestIdDataSet();
+
+ IdMapToMany o1 = Cayenne.objectForPK(context, IdMapToMany.class, 1);
+
+ Map targets = o1.getTargets();
+
+ assertTrue(((ValueHolder) targets).isFault());
+
+ assertNotNull(targets);
+ assertEquals(3, targets.size());
+ assertNotNull(targets.get(new Integer(1)));
+ assertNotNull(targets.get(new Integer(2)));
+ assertNotNull(targets.get(new Integer(3)));
+
+ assertEquals(1, Cayenne.intPKForObject((Persistent) targets.get(new Integer(1))));
+ assertEquals(2, Cayenne.intPKForObject((Persistent) targets.get(new Integer(2))));
+ assertEquals(3, Cayenne.intPKForObject((Persistent) targets.get(new Integer(3))));
+ }
+
+ public void testReadToManyPrefetching() throws Exception {
+ createTestDataSet();
+
+ SelectQuery query = new SelectQuery(MapToMany.class, ExpressionFactory
+ .matchDbExp(MapToMany.ID_PK_COLUMN, new Integer(1)));
+ query.addPrefetch(MapToMany.TARGETS_PROPERTY);
+ MapToMany o1 = (MapToMany) Cayenne.objectForQuery(context, query);
+
+ Map targets = o1.getTargets();
+
+ assertFalse(((ValueHolder) targets).isFault());
+
+ assertNotNull(targets);
+ assertEquals(3, targets.size());
+ assertNotNull(targets.get("A"));
+ assertNotNull(targets.get("B"));
+ assertNotNull(targets.get("C"));
+ }
+
+ public void testAddToMany() throws Exception {
+ createTestDataSet();
+
+ MapToMany o1 = Cayenne.objectForPK(context, MapToMany.class, 1);
+
+ Map targets = o1.getTargets();
+ assertNotNull(targets);
+ assertEquals(3, targets.size());
+
+ MapToManyTarget newTarget = o1
+ .getObjectContext()
+ .newObject(MapToManyTarget.class);
+
+ newTarget.setName("X");
+ o1.addToTargets(newTarget);
+ assertEquals(4, targets.size());
+ assertSame(newTarget, o1.getTargets().get("X"));
+ assertSame(o1, newTarget.getMapToMany());
+
+ o1.getObjectContext().commitChanges();
+
+ o1.getObjectContext().performGenericQuery(new RefreshQuery());
+ assertEquals(4, o1.getTargets().size());
+ }
+
+ public void testRemoveToMany() throws Exception {
+ createTestDataSet();
+
+ MapToMany o1 = Cayenne.objectForPK(context, MapToMany.class, 1);
+
+ Map targets = o1.getTargets();
+ assertEquals(3, targets.size());
+
+ MapToManyTarget target = (MapToManyTarget) targets.get("B");
+ o1.removeFromTargets(target);
+
+ assertEquals(2, targets.size());
+ assertNull(o1.getTargets().get("B"));
+ assertNull(target.getMapToMany());
+
+ o1.getObjectContext().commitChanges();
+
+ o1.getObjectContext().performGenericQuery(new RefreshQuery());
+ assertEquals(2, o1.getTargets().size());
+ assertNotNull(o1.getTargets().get("A"));
+ assertNotNull(o1.getTargets().get("C"));
+ }
+
+ public void testAddToManyViaReverse() throws Exception {
+ createTestDataSet();
+
+ MapToMany o1 = Cayenne.objectForPK(context, MapToMany.class, 1);
+
+ Map targets = o1.getTargets();
+ assertNotNull(targets);
+ assertEquals(3, targets.size());
+
+ MapToManyTarget newTarget = o1
+ .getObjectContext()
+ .newObject(MapToManyTarget.class);
+
+ newTarget.setName("X");
+ newTarget.setMapToMany(o1);
+ assertSame(o1, newTarget.getMapToMany());
+ assertEquals(4, targets.size());
+ assertSame(newTarget, o1.getTargets().get("X"));
+
+ o1.getObjectContext().commitChanges();
+
+ o1.getObjectContext().performGenericQuery(new RefreshQuery());
+ assertEquals(4, o1.getTargets().size());
+ }
+
+ public void testModifyToManyKey() throws Exception {
+ createTestDataSet();
+
+ MapToMany o1 = Cayenne.objectForPK(context, MapToMany.class, 1);
+
+ Map targets = o1.getTargets();
+ MapToManyTarget target = (MapToManyTarget) targets.get("B");
+ target.setName("B1");
+
+ o1.getObjectContext().commitChanges();
+
+ assertNull(o1.getTargets().get("B"));
+ assertSame(target, o1.getTargets().get("B1"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CDOMapRelationshipTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CDOMapRelationshipTest.java b/cayenne-server/src/test/java/org/apache/cayenne/CDOMapRelationshipTest.java
deleted file mode 100644
index f38d212..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/CDOMapRelationshipTest.java
+++ /dev/null
@@ -1,234 +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.Map;
-
-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.IdMapToMany;
-import org.apache.cayenne.testdo.relationship.MapToMany;
-import org.apache.cayenne.testdo.relationship.MapToManyTarget;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.RELATIONSHIPS_PROJECT)
-public class CDOMapRelationshipTest extends ServerCase {
-
- @Inject
- protected ObjectContext context;
-
- @Inject
- protected DBHelper dbHelper;
-
- protected TableHelper tMapToMany;
- protected TableHelper tMapToManyTarget;
- protected TableHelper tIdMapToMany;
- protected TableHelper tIdMapToManyTarget;
-
- @Override
- protected void setUpAfterInjection() throws Exception {
- dbHelper.deleteAll("MAP_TO_MANY_TARGET");
- dbHelper.deleteAll("MAP_TO_MANY");
-
- dbHelper.deleteAll("ID_MAP_TO_MANY_TARGET");
- dbHelper.deleteAll("ID_MAP_TO_MANY");
-
- tMapToMany = new TableHelper(dbHelper, "MAP_TO_MANY");
- tMapToMany.setColumns("ID");
-
- tMapToManyTarget = new TableHelper(dbHelper, "MAP_TO_MANY_TARGET");
- tMapToManyTarget.setColumns("ID", "MAP_TO_MANY_ID", "NAME");
-
- tIdMapToMany = new TableHelper(dbHelper, "ID_MAP_TO_MANY");
- tIdMapToMany.setColumns("ID");
-
- tIdMapToManyTarget = new TableHelper(dbHelper, "ID_MAP_TO_MANY_TARGET");
- tIdMapToManyTarget.setColumns("ID", "MAP_TO_MANY_ID");
- }
-
- protected void createTestDataSet() throws Exception {
- tMapToMany.insert(1);
- tMapToMany.insert(2);
- tMapToManyTarget.insert(1, 1, "A");
- tMapToManyTarget.insert(2, 1, "B");
- tMapToManyTarget.insert(3, 1, "C");
- tMapToManyTarget.insert(4, 2, "A");
- }
-
- protected void createTestIdDataSet() throws Exception {
- tIdMapToMany.insert(1);
- tIdMapToMany.insert(2);
- tIdMapToManyTarget.insert(1, 1);
- tIdMapToManyTarget.insert(2, 1);
- tIdMapToManyTarget.insert(3, 1);
- tIdMapToManyTarget.insert(4, 2);
- }
-
- public void testReadToMany() throws Exception {
- createTestDataSet();
-
- MapToMany o1 = Cayenne.objectForPK(context, MapToMany.class, 1);
-
- Map targets = o1.getTargets();
-
- assertTrue(((ValueHolder) targets).isFault());
-
- assertNotNull(targets);
- assertEquals(3, targets.size());
- assertNotNull(targets.get("A"));
- assertNotNull(targets.get("B"));
- assertNotNull(targets.get("C"));
-
- assertEquals(1, Cayenne.intPKForObject((Persistent) targets.get("A")));
- assertEquals(2, Cayenne.intPKForObject((Persistent) targets.get("B")));
- assertEquals(3, Cayenne.intPKForObject((Persistent) targets.get("C")));
- }
-
- public void testReadToManyId() throws Exception {
- createTestIdDataSet();
-
- IdMapToMany o1 = Cayenne.objectForPK(context, IdMapToMany.class, 1);
-
- Map targets = o1.getTargets();
-
- assertTrue(((ValueHolder) targets).isFault());
-
- assertNotNull(targets);
- assertEquals(3, targets.size());
- assertNotNull(targets.get(new Integer(1)));
- assertNotNull(targets.get(new Integer(2)));
- assertNotNull(targets.get(new Integer(3)));
-
- assertEquals(1, Cayenne.intPKForObject((Persistent) targets.get(new Integer(1))));
- assertEquals(2, Cayenne.intPKForObject((Persistent) targets.get(new Integer(2))));
- assertEquals(3, Cayenne.intPKForObject((Persistent) targets.get(new Integer(3))));
- }
-
- public void testReadToManyPrefetching() throws Exception {
- createTestDataSet();
-
- SelectQuery query = new SelectQuery(MapToMany.class, ExpressionFactory
- .matchDbExp(MapToMany.ID_PK_COLUMN, new Integer(1)));
- query.addPrefetch(MapToMany.TARGETS_PROPERTY);
- MapToMany o1 = (MapToMany) Cayenne.objectForQuery(context, query);
-
- Map targets = o1.getTargets();
-
- assertFalse(((ValueHolder) targets).isFault());
-
- assertNotNull(targets);
- assertEquals(3, targets.size());
- assertNotNull(targets.get("A"));
- assertNotNull(targets.get("B"));
- assertNotNull(targets.get("C"));
- }
-
- public void testAddToMany() throws Exception {
- createTestDataSet();
-
- MapToMany o1 = Cayenne.objectForPK(context, MapToMany.class, 1);
-
- Map targets = o1.getTargets();
- assertNotNull(targets);
- assertEquals(3, targets.size());
-
- MapToManyTarget newTarget = o1
- .getObjectContext()
- .newObject(MapToManyTarget.class);
-
- newTarget.setName("X");
- o1.addToTargets(newTarget);
- assertEquals(4, targets.size());
- assertSame(newTarget, o1.getTargets().get("X"));
- assertSame(o1, newTarget.getMapToMany());
-
- o1.getObjectContext().commitChanges();
-
- o1.getObjectContext().performGenericQuery(new RefreshQuery());
- assertEquals(4, o1.getTargets().size());
- }
-
- public void testRemoveToMany() throws Exception {
- createTestDataSet();
-
- MapToMany o1 = Cayenne.objectForPK(context, MapToMany.class, 1);
-
- Map targets = o1.getTargets();
- assertEquals(3, targets.size());
-
- MapToManyTarget target = (MapToManyTarget) targets.get("B");
- o1.removeFromTargets(target);
-
- assertEquals(2, targets.size());
- assertNull(o1.getTargets().get("B"));
- assertNull(target.getMapToMany());
-
- o1.getObjectContext().commitChanges();
-
- o1.getObjectContext().performGenericQuery(new RefreshQuery());
- assertEquals(2, o1.getTargets().size());
- assertNotNull(o1.getTargets().get("A"));
- assertNotNull(o1.getTargets().get("C"));
- }
-
- public void testAddToManyViaReverse() throws Exception {
- createTestDataSet();
-
- MapToMany o1 = Cayenne.objectForPK(context, MapToMany.class, 1);
-
- Map targets = o1.getTargets();
- assertNotNull(targets);
- assertEquals(3, targets.size());
-
- MapToManyTarget newTarget = o1
- .getObjectContext()
- .newObject(MapToManyTarget.class);
-
- newTarget.setName("X");
- newTarget.setMapToMany(o1);
- assertSame(o1, newTarget.getMapToMany());
- assertEquals(4, targets.size());
- assertSame(newTarget, o1.getTargets().get("X"));
-
- o1.getObjectContext().commitChanges();
-
- o1.getObjectContext().performGenericQuery(new RefreshQuery());
- assertEquals(4, o1.getTargets().size());
- }
-
- public void testModifyToManyKey() throws Exception {
- createTestDataSet();
-
- MapToMany o1 = Cayenne.objectForPK(context, MapToMany.class, 1);
-
- Map targets = o1.getTargets();
- MapToManyTarget target = (MapToManyTarget) targets.get("B");
- target.setName("B1");
-
- o1.getObjectContext().commitChanges();
-
- assertNull(o1.getTargets().get("B"));
- assertSame(target, o1.getTargets().get("B1"));
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CDOOne2ManyIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CDOOne2ManyIT.java b/cayenne-server/src/test/java/org/apache/cayenne/CDOOne2ManyIT.java
new file mode 100644
index 0000000..6a219f7
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/CDOOne2ManyIT.java
@@ -0,0 +1,299 @@
+/*****************************************************************
+ * 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.configuration.server.ServerRuntime;
+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.test.jdbc.TableHelper;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.testdo.testmap.ArtistExhibit;
+import org.apache.cayenne.testdo.testmap.Exhibit;
+import org.apache.cayenne.testdo.testmap.Gallery;
+import org.apache.cayenne.testdo.testmap.Painting;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.util.Date;
+import java.util.List;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class CDOOne2ManyIT extends ServerCase {
+
+ @Inject
+ private ServerRuntime runtime;
+
+ @Inject
+ private ObjectContext context;
+
+ @Inject
+ private DBHelper dbHelper;
+
+ protected TableHelper tArtist;
+ protected TableHelper tPainting;
+
+ @Override
+ protected void setUpAfterInjection() throws Exception {
+ dbHelper.deleteAll("PAINTING_INFO");
+ dbHelper.deleteAll("PAINTING");
+ dbHelper.deleteAll("PAINTING1");
+ dbHelper.deleteAll("ARTIST_EXHIBIT");
+ dbHelper.deleteAll("ARTIST_GROUP");
+ dbHelper.deleteAll("ARTIST");
+ dbHelper.deleteAll("EXHIBIT");
+ dbHelper.deleteAll("GALLERY");
+
+ tArtist = new TableHelper(dbHelper, "ARTIST");
+ tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
+
+ tPainting = new TableHelper(dbHelper, "PAINTING");
+ tPainting.setColumns("PAINTING_ID", "PAINTING_TITLE", "ARTIST_ID", "GALLERY_ID");
+ }
+
+ public void testSelectWithToManyDBQualifier() throws Exception {
+
+ // intentionally add more than 1 painting to artist
+ // since this reduces a chance that painting and artist primary keys
+ // would accidentally match, resulting in success when it should fail
+
+ Artist a1 = context.newObject(Artist.class);
+ a1.setArtistName("Xyz");
+
+ Painting p1 = context.newObject(Painting.class);
+ p1.setPaintingTitle("1");
+ a1.addToPaintingArray(p1);
+
+ Painting p2 = context.newObject(Painting.class);
+ p2.setPaintingTitle("2");
+ a1.addToPaintingArray(p2);
+
+ Painting p3 = context.newObject(Painting.class);
+ p3.setPaintingTitle("3");
+ a1.addToPaintingArray(p3);
+
+ context.commitChanges();
+
+ // do select
+ Expression e = ExpressionFactory.matchDbExp("paintingArray", p2);
+ SelectQuery q = new SelectQuery(Artist.class, e);
+
+ // *** TESTING THIS ***
+ List<Artist> artists = context.performQuery(q);
+ assertEquals(1, artists.size());
+ assertSame(a1, artists.get(0));
+ }
+
+ public void testSelectWithToManyQualifier() throws Exception {
+
+ // intentionally add more than 1 painting to artist
+ // since this reduces a chance that painting and artist primary keys
+ // would accidentally match, resulting in success when it should fail
+
+ Artist a1 = context.newObject(Artist.class);
+ a1.setArtistName("Xyz");
+
+ Painting p1 = context.newObject(Painting.class);
+ p1.setPaintingTitle("1");
+ a1.addToPaintingArray(p1);
+
+ Painting p2 = context.newObject(Painting.class);
+ p2.setPaintingTitle("2");
+ a1.addToPaintingArray(p2);
+
+ Painting p3 = context.newObject(Painting.class);
+ p3.setPaintingTitle("3");
+ a1.addToPaintingArray(p3);
+
+ context.commitChanges();
+
+ // do select
+ Expression e = ExpressionFactory.matchExp("paintingArray", p2);
+ SelectQuery q = new SelectQuery(Artist.class, e);
+
+ // *** TESTING THIS ***
+ List<Artist> artists = context.performQuery(q);
+ assertEquals(1, artists.size());
+ assertSame(a1, artists.get(0));
+ }
+
+ public void testNewAdd() throws Exception {
+ Artist a1 = context.newObject(Artist.class);
+ a1.setArtistName("XyzQ");
+
+ Painting p1 = context.newObject(Painting.class);
+ p1.setPaintingTitle("1");
+
+ // *** TESTING THIS ***
+ a1.addToPaintingArray(p1);
+
+ // test before save
+ assertSame(p1, a1.getPaintingArray().get(0));
+ assertSame(a1, p1.getToArtist());
+
+ context.commitChanges();
+
+ // test database data
+
+ Object[] aRow = tArtist.select();
+
+ // have to trim CHAR column to ensure consistent comparison results across DB's
+ // should really be using VARCHAR in this test
+ assertEquals("XyzQ", String.valueOf(aRow[1]).trim());
+
+ Object[] pRow = tPainting.select();
+ assertEquals("1", pRow[1]);
+ assertEquals(aRow[0], pRow[2]);
+ }
+
+ public void testNewAddMultiples() throws Exception {
+ Artist a1 = context.newObject(Artist.class);
+ a1.setArtistName("XyzV");
+
+ Painting p1 = context.newObject(Painting.class);
+ p1.setPaintingTitle("1");
+ a1.addToPaintingArray(p1);
+
+ Painting p2 = context.newObject(Painting.class);
+ p2.setPaintingTitle("2");
+ a1.addToPaintingArray(p2);
+
+ // test before save
+ assertEquals(2, a1.getPaintingArray().size());
+ assertSame(a1, p1.getToArtist());
+ assertSame(a1, p2.getToArtist());
+
+ context.commitChanges();
+
+ ObjectContext context2 = runtime.newContext();
+
+ // test database data
+ Artist a2 = (Artist) Cayenne.objectForQuery(context2, new SelectQuery(
+ Artist.class));
+ assertEquals(2, a2.getPaintingArray().size());
+ }
+
+ public void testRemove1() throws Exception {
+ Artist a1 = context.newObject(Artist.class);
+ a1.setArtistName("XyzE");
+
+ Painting p1 = context.newObject(Painting.class);
+ p1.setPaintingTitle("1");
+ a1.addToPaintingArray(p1);
+
+ context.commitChanges();
+
+ ObjectContext context2 = runtime.newContext();
+
+ // test database data
+ Artist a2 = (Artist) Cayenne.objectForQuery(context2, new SelectQuery(
+ Artist.class));
+ Painting p2 = a2.getPaintingArray().get(0);
+
+ // *** TESTING THIS ***
+ a2.removeFromPaintingArray(p2);
+
+ // test before save
+ assertEquals(0, a2.getPaintingArray().size());
+ assertNull(p2.getToGallery());
+
+ // do save II
+ context2.commitChanges();
+
+ ObjectContext context3 = runtime.newContext();
+
+ Painting p3 = (Painting) Cayenne.objectForQuery(context3, new SelectQuery(
+ Painting.class));
+ assertNull(p3.getToArtist());
+
+ Artist a3 = (Artist) Cayenne.objectForQuery(context3, new SelectQuery(
+ Artist.class));
+ assertEquals(0, a3.getPaintingArray().size());
+ }
+
+ public void testRemove2() throws Exception {
+ Artist a1 = context.newObject(Artist.class);
+ a1.setArtistName("XyzQ");
+
+ Painting p01 = context.newObject(Painting.class);
+ p01.setPaintingTitle("1");
+ a1.addToPaintingArray(p01);
+
+ Painting p02 = context.newObject(Painting.class);
+ p02.setPaintingTitle("2");
+ a1.addToPaintingArray(p02);
+
+ context.commitChanges();
+
+ ObjectContext context2 = runtime.newContext();
+
+ // test database data
+ Artist a2 = (Artist) Cayenne.objectForQuery(context2, new SelectQuery(
+ Artist.class));
+ assertEquals(2, a2.getPaintingArray().size());
+ Painting p2 = a2.getPaintingArray().get(0);
+
+ // *** TESTING THIS ***
+ a2.removeFromPaintingArray(p2);
+
+ // test before save
+ assertEquals(1, a2.getPaintingArray().size());
+ assertNull(p2.getToArtist());
+
+ // do save II
+ context2.commitChanges();
+
+ ObjectContext context3 = runtime.newContext();
+
+ Artist a3 = (Artist) Cayenne.objectForQuery(context3, new SelectQuery(
+ Artist.class));
+ assertEquals(1, a3.getPaintingArray().size());
+ }
+
+ public void testPropagatePK() throws Exception {
+ Artist a1 = context.newObject(Artist.class);
+ a1.setArtistName("XyBn");
+
+ Gallery g1 = context.newObject(Gallery.class);
+ g1.setGalleryName("Tyu");
+
+ Exhibit e1 = context.newObject(Exhibit.class);
+ e1.setToGallery(g1);
+ e1.setOpeningDate(new Date());
+ e1.setClosingDate(new Date());
+
+ context.commitChanges();
+
+ // *** TESTING THIS ***
+ ArtistExhibit ae1 = context.newObject(ArtistExhibit.class);
+ e1.addToArtistExhibitArray(ae1);
+ a1.addToArtistExhibitArray(ae1);
+
+ // check before save
+ assertSame(e1, ae1.getToExhibit());
+ assertSame(a1, ae1.getToArtist());
+
+ // save
+ // test "assertion" is that commit succeeds (PK of ae1 was set properly)
+ context.commitChanges();
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CDOOne2ManyTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CDOOne2ManyTest.java b/cayenne-server/src/test/java/org/apache/cayenne/CDOOne2ManyTest.java
deleted file mode 100644
index 4b96441..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/CDOOne2ManyTest.java
+++ /dev/null
@@ -1,299 +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.Date;
-import java.util.List;
-
-import org.apache.cayenne.configuration.server.ServerRuntime;
-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.test.jdbc.TableHelper;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.testdo.testmap.ArtistExhibit;
-import org.apache.cayenne.testdo.testmap.Exhibit;
-import org.apache.cayenne.testdo.testmap.Gallery;
-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 CDOOne2ManyTest extends ServerCase {
-
- @Inject
- private ServerRuntime runtime;
-
- @Inject
- private ObjectContext context;
-
- @Inject
- private DBHelper dbHelper;
-
- protected TableHelper tArtist;
- protected TableHelper tPainting;
-
- @Override
- protected void setUpAfterInjection() throws Exception {
- dbHelper.deleteAll("PAINTING_INFO");
- dbHelper.deleteAll("PAINTING");
- dbHelper.deleteAll("PAINTING1");
- dbHelper.deleteAll("ARTIST_EXHIBIT");
- dbHelper.deleteAll("ARTIST_GROUP");
- dbHelper.deleteAll("ARTIST");
- dbHelper.deleteAll("EXHIBIT");
- dbHelper.deleteAll("GALLERY");
-
- tArtist = new TableHelper(dbHelper, "ARTIST");
- tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
-
- tPainting = new TableHelper(dbHelper, "PAINTING");
- tPainting.setColumns("PAINTING_ID", "PAINTING_TITLE", "ARTIST_ID", "GALLERY_ID");
- }
-
- public void testSelectWithToManyDBQualifier() throws Exception {
-
- // intentionally add more than 1 painting to artist
- // since this reduces a chance that painting and artist primary keys
- // would accidentally match, resulting in success when it should fail
-
- Artist a1 = context.newObject(Artist.class);
- a1.setArtistName("Xyz");
-
- Painting p1 = context.newObject(Painting.class);
- p1.setPaintingTitle("1");
- a1.addToPaintingArray(p1);
-
- Painting p2 = context.newObject(Painting.class);
- p2.setPaintingTitle("2");
- a1.addToPaintingArray(p2);
-
- Painting p3 = context.newObject(Painting.class);
- p3.setPaintingTitle("3");
- a1.addToPaintingArray(p3);
-
- context.commitChanges();
-
- // do select
- Expression e = ExpressionFactory.matchDbExp("paintingArray", p2);
- SelectQuery q = new SelectQuery(Artist.class, e);
-
- // *** TESTING THIS ***
- List<Artist> artists = context.performQuery(q);
- assertEquals(1, artists.size());
- assertSame(a1, artists.get(0));
- }
-
- public void testSelectWithToManyQualifier() throws Exception {
-
- // intentionally add more than 1 painting to artist
- // since this reduces a chance that painting and artist primary keys
- // would accidentally match, resulting in success when it should fail
-
- Artist a1 = context.newObject(Artist.class);
- a1.setArtistName("Xyz");
-
- Painting p1 = context.newObject(Painting.class);
- p1.setPaintingTitle("1");
- a1.addToPaintingArray(p1);
-
- Painting p2 = context.newObject(Painting.class);
- p2.setPaintingTitle("2");
- a1.addToPaintingArray(p2);
-
- Painting p3 = context.newObject(Painting.class);
- p3.setPaintingTitle("3");
- a1.addToPaintingArray(p3);
-
- context.commitChanges();
-
- // do select
- Expression e = ExpressionFactory.matchExp("paintingArray", p2);
- SelectQuery q = new SelectQuery(Artist.class, e);
-
- // *** TESTING THIS ***
- List<Artist> artists = context.performQuery(q);
- assertEquals(1, artists.size());
- assertSame(a1, artists.get(0));
- }
-
- public void testNewAdd() throws Exception {
- Artist a1 = context.newObject(Artist.class);
- a1.setArtistName("XyzQ");
-
- Painting p1 = context.newObject(Painting.class);
- p1.setPaintingTitle("1");
-
- // *** TESTING THIS ***
- a1.addToPaintingArray(p1);
-
- // test before save
- assertSame(p1, a1.getPaintingArray().get(0));
- assertSame(a1, p1.getToArtist());
-
- context.commitChanges();
-
- // test database data
-
- Object[] aRow = tArtist.select();
-
- // have to trim CHAR column to ensure consistent comparison results across DB's
- // should really be using VARCHAR in this test
- assertEquals("XyzQ", String.valueOf(aRow[1]).trim());
-
- Object[] pRow = tPainting.select();
- assertEquals("1", pRow[1]);
- assertEquals(aRow[0], pRow[2]);
- }
-
- public void testNewAddMultiples() throws Exception {
- Artist a1 = context.newObject(Artist.class);
- a1.setArtistName("XyzV");
-
- Painting p1 = context.newObject(Painting.class);
- p1.setPaintingTitle("1");
- a1.addToPaintingArray(p1);
-
- Painting p2 = context.newObject(Painting.class);
- p2.setPaintingTitle("2");
- a1.addToPaintingArray(p2);
-
- // test before save
- assertEquals(2, a1.getPaintingArray().size());
- assertSame(a1, p1.getToArtist());
- assertSame(a1, p2.getToArtist());
-
- context.commitChanges();
-
- ObjectContext context2 = runtime.newContext();
-
- // test database data
- Artist a2 = (Artist) Cayenne.objectForQuery(context2, new SelectQuery(
- Artist.class));
- assertEquals(2, a2.getPaintingArray().size());
- }
-
- public void testRemove1() throws Exception {
- Artist a1 = context.newObject(Artist.class);
- a1.setArtistName("XyzE");
-
- Painting p1 = context.newObject(Painting.class);
- p1.setPaintingTitle("1");
- a1.addToPaintingArray(p1);
-
- context.commitChanges();
-
- ObjectContext context2 = runtime.newContext();
-
- // test database data
- Artist a2 = (Artist) Cayenne.objectForQuery(context2, new SelectQuery(
- Artist.class));
- Painting p2 = a2.getPaintingArray().get(0);
-
- // *** TESTING THIS ***
- a2.removeFromPaintingArray(p2);
-
- // test before save
- assertEquals(0, a2.getPaintingArray().size());
- assertNull(p2.getToGallery());
-
- // do save II
- context2.commitChanges();
-
- ObjectContext context3 = runtime.newContext();
-
- Painting p3 = (Painting) Cayenne.objectForQuery(context3, new SelectQuery(
- Painting.class));
- assertNull(p3.getToArtist());
-
- Artist a3 = (Artist) Cayenne.objectForQuery(context3, new SelectQuery(
- Artist.class));
- assertEquals(0, a3.getPaintingArray().size());
- }
-
- public void testRemove2() throws Exception {
- Artist a1 = context.newObject(Artist.class);
- a1.setArtistName("XyzQ");
-
- Painting p01 = context.newObject(Painting.class);
- p01.setPaintingTitle("1");
- a1.addToPaintingArray(p01);
-
- Painting p02 = context.newObject(Painting.class);
- p02.setPaintingTitle("2");
- a1.addToPaintingArray(p02);
-
- context.commitChanges();
-
- ObjectContext context2 = runtime.newContext();
-
- // test database data
- Artist a2 = (Artist) Cayenne.objectForQuery(context2, new SelectQuery(
- Artist.class));
- assertEquals(2, a2.getPaintingArray().size());
- Painting p2 = a2.getPaintingArray().get(0);
-
- // *** TESTING THIS ***
- a2.removeFromPaintingArray(p2);
-
- // test before save
- assertEquals(1, a2.getPaintingArray().size());
- assertNull(p2.getToArtist());
-
- // do save II
- context2.commitChanges();
-
- ObjectContext context3 = runtime.newContext();
-
- Artist a3 = (Artist) Cayenne.objectForQuery(context3, new SelectQuery(
- Artist.class));
- assertEquals(1, a3.getPaintingArray().size());
- }
-
- public void testPropagatePK() throws Exception {
- Artist a1 = context.newObject(Artist.class);
- a1.setArtistName("XyBn");
-
- Gallery g1 = context.newObject(Gallery.class);
- g1.setGalleryName("Tyu");
-
- Exhibit e1 = context.newObject(Exhibit.class);
- e1.setToGallery(g1);
- e1.setOpeningDate(new Date());
- e1.setClosingDate(new Date());
-
- context.commitChanges();
-
- // *** TESTING THIS ***
- ArtistExhibit ae1 = context.newObject(ArtistExhibit.class);
- e1.addToArtistExhibitArray(ae1);
- a1.addToArtistExhibitArray(ae1);
-
- // check before save
- assertSame(e1, ae1.getToExhibit());
- assertSame(a1, ae1.getToArtist());
-
- // save
- // test "assertion" is that commit succeeds (PK of ae1 was set properly)
- context.commitChanges();
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CDOOne2OneDepIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CDOOne2OneDepIT.java b/cayenne-server/src/test/java/org/apache/cayenne/CDOOne2OneDepIT.java
new file mode 100644
index 0000000..30a4ac4
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/CDOOne2OneDepIT.java
@@ -0,0 +1,135 @@
+/*****************************************************************
+ * 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.di.Inject;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.testdo.testmap.Painting;
+import org.apache.cayenne.testdo.testmap.PaintingInfo;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime("cayenne-small-testmap.xml")
+public class CDOOne2OneDepIT extends CayenneDOTestBase {
+
+ @Inject
+ private ObjectContext context1;
+
+ public void testRollbackDependent() {
+ Artist a1 = newArtist();
+ Painting p1 = newPainting();
+
+ // needed to save without errors
+ p1.setToArtist(a1);
+ context.commitChanges();
+
+ PaintingInfo info = context.newObject(PaintingInfo.class);
+ info.setTextReview("XXX");
+ p1.setToPaintingInfo(info);
+
+ assertSame(info, p1.getToPaintingInfo());
+
+ context.rollbackChanges();
+ assertNull(p1.getToPaintingInfo());
+ }
+
+ public void test2Null() throws Exception {
+ Artist a1 = newArtist();
+ Painting p1 = newPainting();
+
+ // needed to save without errors
+ p1.setToArtist(a1);
+ context.commitChanges();
+ context = context1;
+
+ // test database data
+ Painting p2 = fetchPainting();
+
+ // *** TESTING THIS ***
+ assertNull(p2.getToPaintingInfo());
+ }
+
+ public void testReplaceNull() throws Exception {
+ Artist a1 = newArtist();
+ Painting p1 = newPainting();
+
+ // needed to save without errors
+ p1.setToArtist(a1);
+ context.commitChanges();
+ context = context1;
+
+ // test database data
+ Painting p2 = fetchPainting();
+
+ // *** TESTING THIS ***
+ p2.setToPaintingInfo(null);
+
+ assertNull(p2.getToPaintingInfo());
+ }
+
+ public void testNewAdd() throws Exception {
+ Artist a1 = newArtist();
+ PaintingInfo pi1 = newPaintingInfo();
+ Painting p1 = newPainting();
+
+ // needed to save without errors
+ p1.setToArtist(a1);
+
+ // *** TESTING THIS ***
+ p1.setToPaintingInfo(pi1);
+
+ // test before save
+ assertSame(pi1, p1.getToPaintingInfo());
+ assertSame(p1, pi1.getPainting());
+
+ // do save
+ context.commitChanges();
+ context = context1;
+
+ // test database data
+ Painting p2 = fetchPainting();
+ PaintingInfo pi2 = p2.getToPaintingInfo();
+ assertNotNull(pi2);
+ assertEquals(textReview, pi2.getTextReview());
+ }
+
+ public void testTakeObjectSnapshotDependentFault() throws Exception {
+ // prepare data
+ Artist a1 = newArtist();
+ PaintingInfo pi1 = newPaintingInfo();
+ Painting p1 = newPainting();
+
+ p1.setToArtist(a1);
+ p1.setToPaintingInfo(pi1);
+ context.commitChanges();
+
+ context = context1;
+ Painting painting = fetchPainting();
+
+ assertTrue(painting.readPropertyDirectly("toPaintingInfo") instanceof Fault);
+
+ // test that taking a snapshot does not trigger a fault, and generally works well
+ DataRow snapshot = ((DataContext) context).currentSnapshot(painting);
+
+ assertEquals(paintingName, snapshot.get("PAINTING_TITLE"));
+ assertTrue(painting.readPropertyDirectly("toPaintingInfo") instanceof Fault);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CDOOne2OneDepTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CDOOne2OneDepTest.java b/cayenne-server/src/test/java/org/apache/cayenne/CDOOne2OneDepTest.java
deleted file mode 100644
index ee0e1ee..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/CDOOne2OneDepTest.java
+++ /dev/null
@@ -1,135 +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.access.DataContext;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.testdo.testmap.Painting;
-import org.apache.cayenne.testdo.testmap.PaintingInfo;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime("cayenne-small-testmap.xml")
-public class CDOOne2OneDepTest extends CayenneDOTestBase {
-
- @Inject
- private ObjectContext context1;
-
- public void testRollbackDependent() {
- Artist a1 = newArtist();
- Painting p1 = newPainting();
-
- // needed to save without errors
- p1.setToArtist(a1);
- context.commitChanges();
-
- PaintingInfo info = context.newObject(PaintingInfo.class);
- info.setTextReview("XXX");
- p1.setToPaintingInfo(info);
-
- assertSame(info, p1.getToPaintingInfo());
-
- context.rollbackChanges();
- assertNull(p1.getToPaintingInfo());
- }
-
- public void test2Null() throws Exception {
- Artist a1 = newArtist();
- Painting p1 = newPainting();
-
- // needed to save without errors
- p1.setToArtist(a1);
- context.commitChanges();
- context = context1;
-
- // test database data
- Painting p2 = fetchPainting();
-
- // *** TESTING THIS ***
- assertNull(p2.getToPaintingInfo());
- }
-
- public void testReplaceNull() throws Exception {
- Artist a1 = newArtist();
- Painting p1 = newPainting();
-
- // needed to save without errors
- p1.setToArtist(a1);
- context.commitChanges();
- context = context1;
-
- // test database data
- Painting p2 = fetchPainting();
-
- // *** TESTING THIS ***
- p2.setToPaintingInfo(null);
-
- assertNull(p2.getToPaintingInfo());
- }
-
- public void testNewAdd() throws Exception {
- Artist a1 = newArtist();
- PaintingInfo pi1 = newPaintingInfo();
- Painting p1 = newPainting();
-
- // needed to save without errors
- p1.setToArtist(a1);
-
- // *** TESTING THIS ***
- p1.setToPaintingInfo(pi1);
-
- // test before save
- assertSame(pi1, p1.getToPaintingInfo());
- assertSame(p1, pi1.getPainting());
-
- // do save
- context.commitChanges();
- context = context1;
-
- // test database data
- Painting p2 = fetchPainting();
- PaintingInfo pi2 = p2.getToPaintingInfo();
- assertNotNull(pi2);
- assertEquals(textReview, pi2.getTextReview());
- }
-
- public void testTakeObjectSnapshotDependentFault() throws Exception {
- // prepare data
- Artist a1 = newArtist();
- PaintingInfo pi1 = newPaintingInfo();
- Painting p1 = newPainting();
-
- p1.setToArtist(a1);
- p1.setToPaintingInfo(pi1);
- context.commitChanges();
-
- context = context1;
- Painting painting = fetchPainting();
-
- assertTrue(painting.readPropertyDirectly("toPaintingInfo") instanceof Fault);
-
- // test that taking a snapshot does not trigger a fault, and generally works well
- DataRow snapshot = ((DataContext) context).currentSnapshot(painting);
-
- assertEquals(paintingName, snapshot.get("PAINTING_TITLE"));
- assertTrue(painting.readPropertyDirectly("toPaintingInfo") instanceof Fault);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CDOOneDep2OneIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CDOOneDep2OneIT.java b/cayenne-server/src/test/java/org/apache/cayenne/CDOOneDep2OneIT.java
new file mode 100644
index 0000000..695ffec
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/CDOOneDep2OneIT.java
@@ -0,0 +1,136 @@
+/*****************************************************************
+ * 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.types.ByteArrayTypeTest;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.testdo.testmap.ArtistExhibit;
+import org.apache.cayenne.testdo.testmap.Exhibit;
+import org.apache.cayenne.testdo.testmap.Gallery;
+import org.apache.cayenne.testdo.testmap.Painting;
+import org.apache.cayenne.testdo.testmap.PaintingInfo;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.sql.Timestamp;
+
+@UseServerRuntime("cayenne-small-testmap.xml")
+public class CDOOneDep2OneIT extends CayenneDOTestBase {
+
+ @Inject
+ private ObjectContext context1;
+
+ public void testNewAdd1() throws Exception {
+ Artist a1 = newArtist();
+ PaintingInfo pi1 = newPaintingInfo();
+ Painting p1 = newPainting();
+
+ // needed to save without errors
+ p1.setToArtist(a1);
+
+ // *** TESTING THIS ***
+ pi1.setPainting(p1);
+
+ // test before save
+ assertSame(pi1, p1.getToPaintingInfo());
+ assertSame(p1, pi1.getPainting());
+
+ // do save
+ context.commitChanges();
+ context = context1;
+
+ // test database data
+ PaintingInfo pi2 = fetchPaintingInfo();
+ Painting p2 = pi2.getPainting();
+ assertNotNull(p2);
+ assertEquals(paintingName, p2.getPaintingTitle());
+ }
+
+ /** Tests how primary key is propagated from one new object to another. */
+ public void testNewAdd2() throws Exception {
+ Artist a1 = this.newArtist();
+ Gallery g1 = context.newObject(Gallery.class);
+ g1.setGalleryName(galleryName);
+
+ Exhibit e1 = context.newObject(Exhibit.class);
+ e1.setOpeningDate(new Timestamp(System.currentTimeMillis()));
+ e1.setClosingDate(new Timestamp(System.currentTimeMillis()));
+ e1.setToGallery(g1);
+
+ ArtistExhibit ae1 = context.newObject(ArtistExhibit.class);
+ ae1.setToArtist(a1);
+ ae1.setToExhibit(e1);
+
+ // *** TESTING THIS ***
+ context.commitChanges();
+ }
+
+ public void testReplace() throws Exception {
+ String altPaintingName = "alt painting";
+
+ PaintingInfo pi1 = newPaintingInfo();
+ Painting p1 = newPainting();
+ p1.setPaintingTitle(altPaintingName);
+
+ pi1.setPainting(p1);
+
+ assertTrue(context.hasChanges());
+
+ // do save
+ context.commitChanges();
+ context = context1;
+
+ // test database data
+ PaintingInfo pi2 = fetchPaintingInfo();
+ Painting p21 = pi2.getPainting();
+ assertNotNull(p21);
+ assertEquals(altPaintingName, p21.getPaintingTitle());
+ assertSame(pi2, p21.getToPaintingInfo());
+ ByteArrayTypeTest.assertByteArraysEqual(paintingImage, p21
+ .getToPaintingInfo()
+ .getImageBlob());
+
+ Painting p22 = newPainting();
+
+ // *** TESTING THIS ***
+ pi2.setPainting(p22);
+
+ // test before save
+ assertNull(p21.getToPaintingInfo());
+ assertSame(pi2, p22.getToPaintingInfo());
+ assertSame(p22, pi2.getPainting());
+ assertEquals(PersistenceState.MODIFIED, pi2.getPersistenceState());
+
+ // do save II
+ context.commitChanges();
+ ObjectId pi2oid = pi2.getObjectId();
+ context = context1;
+
+ PaintingInfo pi3 = fetchPaintingInfo();
+ Painting p3 = pi3.getPainting();
+ assertNotNull(p3);
+ assertEquals(paintingName, p3.getPaintingTitle());
+ assertSame(pi3, p3.getToPaintingInfo());
+
+ // test that object id was updated.
+ assertEquals(pi2oid, pi3.getObjectId());
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CDOOneDep2OneTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CDOOneDep2OneTest.java b/cayenne-server/src/test/java/org/apache/cayenne/CDOOneDep2OneTest.java
deleted file mode 100644
index 190412c..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/CDOOneDep2OneTest.java
+++ /dev/null
@@ -1,136 +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.Timestamp;
-
-import org.apache.cayenne.access.types.ByteArrayTypeTest;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.testdo.testmap.ArtistExhibit;
-import org.apache.cayenne.testdo.testmap.Exhibit;
-import org.apache.cayenne.testdo.testmap.Gallery;
-import org.apache.cayenne.testdo.testmap.Painting;
-import org.apache.cayenne.testdo.testmap.PaintingInfo;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime("cayenne-small-testmap.xml")
-public class CDOOneDep2OneTest extends CayenneDOTestBase {
-
- @Inject
- private ObjectContext context1;
-
- public void testNewAdd1() throws Exception {
- Artist a1 = newArtist();
- PaintingInfo pi1 = newPaintingInfo();
- Painting p1 = newPainting();
-
- // needed to save without errors
- p1.setToArtist(a1);
-
- // *** TESTING THIS ***
- pi1.setPainting(p1);
-
- // test before save
- assertSame(pi1, p1.getToPaintingInfo());
- assertSame(p1, pi1.getPainting());
-
- // do save
- context.commitChanges();
- context = context1;
-
- // test database data
- PaintingInfo pi2 = fetchPaintingInfo();
- Painting p2 = pi2.getPainting();
- assertNotNull(p2);
- assertEquals(paintingName, p2.getPaintingTitle());
- }
-
- /** Tests how primary key is propagated from one new object to another. */
- public void testNewAdd2() throws Exception {
- Artist a1 = this.newArtist();
- Gallery g1 = context.newObject(Gallery.class);
- g1.setGalleryName(galleryName);
-
- Exhibit e1 = context.newObject(Exhibit.class);
- e1.setOpeningDate(new Timestamp(System.currentTimeMillis()));
- e1.setClosingDate(new Timestamp(System.currentTimeMillis()));
- e1.setToGallery(g1);
-
- ArtistExhibit ae1 = context.newObject(ArtistExhibit.class);
- ae1.setToArtist(a1);
- ae1.setToExhibit(e1);
-
- // *** TESTING THIS ***
- context.commitChanges();
- }
-
- public void testReplace() throws Exception {
- String altPaintingName = "alt painting";
-
- PaintingInfo pi1 = newPaintingInfo();
- Painting p1 = newPainting();
- p1.setPaintingTitle(altPaintingName);
-
- pi1.setPainting(p1);
-
- assertTrue(context.hasChanges());
-
- // do save
- context.commitChanges();
- context = context1;
-
- // test database data
- PaintingInfo pi2 = fetchPaintingInfo();
- Painting p21 = pi2.getPainting();
- assertNotNull(p21);
- assertEquals(altPaintingName, p21.getPaintingTitle());
- assertSame(pi2, p21.getToPaintingInfo());
- ByteArrayTypeTest.assertByteArraysEqual(paintingImage, p21
- .getToPaintingInfo()
- .getImageBlob());
-
- Painting p22 = newPainting();
-
- // *** TESTING THIS ***
- pi2.setPainting(p22);
-
- // test before save
- assertNull(p21.getToPaintingInfo());
- assertSame(pi2, p22.getToPaintingInfo());
- assertSame(p22, pi2.getPainting());
- assertEquals(PersistenceState.MODIFIED, pi2.getPersistenceState());
-
- // do save II
- context.commitChanges();
- ObjectId pi2oid = pi2.getObjectId();
- context = context1;
-
- PaintingInfo pi3 = fetchPaintingInfo();
- Painting p3 = pi3.getPainting();
- assertNotNull(p3);
- assertEquals(paintingName, p3.getPaintingTitle());
- assertSame(pi3, p3.getToPaintingInfo());
-
- // test that object id was updated.
- assertEquals(pi2oid, pi3.getObjectId());
-
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CDOOneToManyFKIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CDOOneToManyFKIT.java b/cayenne-server/src/test/java/org/apache/cayenne/CDOOneToManyFKIT.java
new file mode 100644
index 0000000..39dad81
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/CDOOneToManyFKIT.java
@@ -0,0 +1,83 @@
+/*****************************************************************
+ * 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.di.Inject;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.testdo.relationship.ToManyFkDep;
+import org.apache.cayenne.testdo.relationship.ToManyFkRoot;
+import org.apache.cayenne.testdo.relationship.ToManyRoot2;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+// TODO: this mapping scenario is really unsupported ... this is just an attempt at
+// partial solution
+@UseServerRuntime(ServerCase.RELATIONSHIPS_PROJECT)
+public class CDOOneToManyFKIT extends ServerCase {
+
+ @Inject
+ protected DataContext context;
+
+ @Inject
+ private DBHelper dbHelper;
+
+ @Override
+ protected void setUpAfterInjection() throws Exception {
+ dbHelper.deleteAll("TO_ONEFK2");
+ dbHelper.deleteAll("TO_ONEFK1");
+ }
+
+ public void testReadRelationship() throws Exception {
+
+ ToManyRoot2 src2 = context.newObject(ToManyRoot2.class);
+ ToManyFkRoot src = context.newObject(ToManyFkRoot.class);
+
+ // this should go away when such mapping becomes fully supported
+ src.setDepId(new Integer(1));
+ ToManyFkDep target = context.newObject(ToManyFkDep.class);
+
+ // this should go away when such mapping becomes fully supported
+ target.setDepId(new Integer(1));
+ target.setRoot2(src2);
+
+ src.addToDeps(target);
+ context.commitChanges();
+
+ context.invalidateObjects(src, target, src2);
+
+ ToManyFkRoot src1 = (ToManyFkRoot) Cayenne
+ .objectForPK(context, src.getObjectId());
+ assertNotNull(src1.getDeps());
+ assertEquals(1, src1.getDeps().size());
+ // resolve HOLLOW
+ assertSame(src1, ((ToManyFkDep) src1.getDeps().get(0)).getRoot());
+
+ context.invalidateObjects(src1, src1.getDeps().get(0));
+
+ ToManyFkDep target2 = (ToManyFkDep) Cayenne.objectForPK(context, target
+ .getObjectId());
+ assertNotNull(target2.getRoot());
+
+ // resolve HOLLOW
+ assertSame(target2, target2.getRoot().getDeps().get(0));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CDOOneToManyFKTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CDOOneToManyFKTest.java b/cayenne-server/src/test/java/org/apache/cayenne/CDOOneToManyFKTest.java
deleted file mode 100644
index a3bed72..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/CDOOneToManyFKTest.java
+++ /dev/null
@@ -1,83 +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.access.DataContext;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.test.jdbc.DBHelper;
-import org.apache.cayenne.testdo.relationship.ToManyFkDep;
-import org.apache.cayenne.testdo.relationship.ToManyFkRoot;
-import org.apache.cayenne.testdo.relationship.ToManyRoot2;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-// TODO: this mapping scenario is really unsupported ... this is just an attempt at
-// partial solution
-@UseServerRuntime(ServerCase.RELATIONSHIPS_PROJECT)
-public class CDOOneToManyFKTest extends ServerCase {
-
- @Inject
- protected DataContext context;
-
- @Inject
- private DBHelper dbHelper;
-
- @Override
- protected void setUpAfterInjection() throws Exception {
- dbHelper.deleteAll("TO_ONEFK2");
- dbHelper.deleteAll("TO_ONEFK1");
- }
-
- public void testReadRelationship() throws Exception {
-
- ToManyRoot2 src2 = context.newObject(ToManyRoot2.class);
- ToManyFkRoot src = context.newObject(ToManyFkRoot.class);
-
- // this should go away when such mapping becomes fully supported
- src.setDepId(new Integer(1));
- ToManyFkDep target = context.newObject(ToManyFkDep.class);
-
- // this should go away when such mapping becomes fully supported
- target.setDepId(new Integer(1));
- target.setRoot2(src2);
-
- src.addToDeps(target);
- context.commitChanges();
-
- context.invalidateObjects(src, target, src2);
-
- ToManyFkRoot src1 = (ToManyFkRoot) Cayenne
- .objectForPK(context, src.getObjectId());
- assertNotNull(src1.getDeps());
- assertEquals(1, src1.getDeps().size());
- // resolve HOLLOW
- assertSame(src1, ((ToManyFkDep) src1.getDeps().get(0)).getRoot());
-
- context.invalidateObjects(src1, src1.getDeps().get(0));
-
- ToManyFkDep target2 = (ToManyFkDep) Cayenne.objectForPK(context, target
- .getObjectId());
- assertNotNull(target2.getRoot());
-
- // resolve HOLLOW
- assertSame(target2, target2.getRoot().getDeps().get(0));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CDOOneToOneFKIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CDOOneToOneFKIT.java b/cayenne-server/src/test/java/org/apache/cayenne/CDOOneToOneFKIT.java
new file mode 100644
index 0000000..5990596
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/CDOOneToOneFKIT.java
@@ -0,0 +1,197 @@
+/*****************************************************************
+ * 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.di.Inject;
+import org.apache.cayenne.query.ObjectIdQuery;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.testdo.relationship.ToOneFK1;
+import org.apache.cayenne.testdo.relationship.ToOneFK2;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+/**
+ * Tests the behavior of one-to-one relationship where to-one is pointing to an FK.
+ */
+@UseServerRuntime(ServerCase.RELATIONSHIPS_PROJECT)
+public class CDOOneToOneFKIT extends ServerCase {
+
+ @Inject
+ private DataContext context;
+
+ @Inject
+ private DataContext context1;
+
+ @Inject
+ private DBHelper dbHelper;
+
+ @Override
+ protected void setUpAfterInjection() throws Exception {
+ dbHelper.deleteAll("TO_ONEFK1");
+ dbHelper.deleteAll("TO_ONEFK2");
+ }
+
+ public void testReadRelationship() {
+ ToOneFK2 src = context.newObject(ToOneFK2.class);
+ ToOneFK1 target = context.newObject(ToOneFK1.class);
+ src.setToOneToFK(target);
+ context.commitChanges();
+
+ context.invalidateObjects(src, target);
+
+ ToOneFK2 src1 = (ToOneFK2) Cayenne.objectForPK(context, src.getObjectId());
+ assertNotNull(src1.getToOneToFK());
+ // resolve HOLLOW
+ assertSame(src1, src1.getToOneToFK().getToPK());
+
+ context.invalidateObjects(src1, src1.getToOneToFK());
+
+ ToOneFK1 target2 = (ToOneFK1) Cayenne.objectForPK(context, target.getObjectId());
+ assertNotNull(target2.getToPK());
+
+ // resolve HOLLOW
+ assertSame(target2, target2.getToPK().getToOneToFK());
+ }
+
+ public void test2Null() throws Exception {
+ ToOneFK2 src = context.newObject(ToOneFK2.class);
+ context.commitChanges();
+
+ // test database data
+ ObjectIdQuery refetch = new ObjectIdQuery(
+ src.getObjectId(),
+ false,
+ ObjectIdQuery.CACHE_REFRESH);
+ ToOneFK2 src2 = (ToOneFK2) Cayenne.objectForQuery(context1, refetch);
+
+ // *** TESTING THIS ***
+ assertNull(src2.getToOneToFK());
+ }
+
+ public void testReplaceNull1() throws Exception {
+ ToOneFK2 src = context.newObject(ToOneFK2.class);
+ context.commitChanges();
+
+ // test database data
+ ObjectIdQuery refetch = new ObjectIdQuery(
+ src.getObjectId(),
+ false,
+ ObjectIdQuery.CACHE_REFRESH);
+ ToOneFK2 src2 = (ToOneFK2) Cayenne.objectForQuery(context1, refetch);
+ assertEquals(src.getObjectId(), src2.getObjectId());
+
+ // *** TESTING THIS ***
+ src2.setToOneToFK(null);
+ assertNull(src2.getToOneToFK());
+ }
+
+ public void testReplaceNull2() throws Exception {
+ ToOneFK2 src = context.newObject(ToOneFK2.class);
+ context.commitChanges();
+
+ ToOneFK1 target = context.newObject(ToOneFK1.class);
+
+ // *** TESTING THIS ***
+ src.setToOneToFK(target);
+
+ // test before save
+ assertSame(target, src.getToOneToFK());
+
+ // do save
+ context.commitChanges();
+
+ // test database data
+ ObjectIdQuery refetch = new ObjectIdQuery(
+ src.getObjectId(),
+ false,
+ ObjectIdQuery.CACHE_REFRESH);
+ ToOneFK2 src2 = (ToOneFK2) Cayenne.objectForQuery(context1, refetch);
+ ToOneFK1 target2 = src2.getToOneToFK();
+ assertNotNull(target2);
+ assertEquals(src.getObjectId(), src2.getObjectId());
+ assertEquals(target.getObjectId(), target2.getObjectId());
+ }
+
+ public void testNewAdd() throws Exception {
+ ToOneFK2 src = context.newObject(ToOneFK2.class);
+ ToOneFK1 target = context.newObject(ToOneFK1.class);
+
+ // *** TESTING THIS ***
+ src.setToOneToFK(target);
+
+ // test before save
+ assertSame(target, src.getToOneToFK());
+
+ // do save
+ context.commitChanges();
+
+ // test database data
+ ObjectIdQuery refetch = new ObjectIdQuery(
+ src.getObjectId(),
+ false,
+ ObjectIdQuery.CACHE_REFRESH);
+ ToOneFK2 src2 = (ToOneFK2) Cayenne.objectForQuery(context1, refetch);
+ ToOneFK1 target2 = src2.getToOneToFK();
+ assertNotNull(target2);
+ assertEquals(src.getObjectId(), src2.getObjectId());
+ assertEquals(target.getObjectId(), target2.getObjectId());
+ }
+
+ public void testTakeObjectSnapshotDependentFault() throws Exception {
+ ToOneFK2 src = context.newObject(ToOneFK2.class);
+ ToOneFK1 target = context.newObject(ToOneFK1.class);
+ src.setToOneToFK(target);
+ context.commitChanges();
+
+ ObjectIdQuery refetch = new ObjectIdQuery(
+ src.getObjectId(),
+ false,
+ ObjectIdQuery.CACHE_REFRESH);
+ ToOneFK2 src2 = (ToOneFK2) Cayenne.objectForQuery(context1, refetch);
+
+ assertTrue(src2.readPropertyDirectly("toOneToFK") instanceof Fault);
+
+ // test that taking a snapshot does not trigger a fault, and generally works well
+ context.currentSnapshot(src2);
+ assertTrue(src2.readPropertyDirectly("toOneToFK") instanceof Fault);
+ }
+
+ public void testDelete() throws Exception {
+ ToOneFK2 src = context.newObject(ToOneFK2.class);
+ ToOneFK1 target = context.newObject(ToOneFK1.class);
+ src.setToOneToFK(target);
+ context.commitChanges();
+
+ src.setToOneToFK(null);
+ context.deleteObjects(target);
+ context.commitChanges();
+
+ // test database data
+
+ ObjectIdQuery refetch = new ObjectIdQuery(
+ src.getObjectId(),
+ false,
+ ObjectIdQuery.CACHE_REFRESH);
+ ToOneFK2 src2 = (ToOneFK2) Cayenne.objectForQuery(context1, refetch);
+ assertNull(src.getToOneToFK());
+ assertEquals(src.getObjectId(), src2.getObjectId());
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CDOOneToOneFKTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CDOOneToOneFKTest.java b/cayenne-server/src/test/java/org/apache/cayenne/CDOOneToOneFKTest.java
deleted file mode 100644
index 65ff1cc..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/CDOOneToOneFKTest.java
+++ /dev/null
@@ -1,197 +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.access.DataContext;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.query.ObjectIdQuery;
-import org.apache.cayenne.test.jdbc.DBHelper;
-import org.apache.cayenne.testdo.relationship.ToOneFK1;
-import org.apache.cayenne.testdo.relationship.ToOneFK2;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-/**
- * Tests the behavior of one-to-one relationship where to-one is pointing to an FK.
- */
-@UseServerRuntime(ServerCase.RELATIONSHIPS_PROJECT)
-public class CDOOneToOneFKTest extends ServerCase {
-
- @Inject
- private DataContext context;
-
- @Inject
- private DataContext context1;
-
- @Inject
- private DBHelper dbHelper;
-
- @Override
- protected void setUpAfterInjection() throws Exception {
- dbHelper.deleteAll("TO_ONEFK1");
- dbHelper.deleteAll("TO_ONEFK2");
- }
-
- public void testReadRelationship() {
- ToOneFK2 src = context.newObject(ToOneFK2.class);
- ToOneFK1 target = context.newObject(ToOneFK1.class);
- src.setToOneToFK(target);
- context.commitChanges();
-
- context.invalidateObjects(src, target);
-
- ToOneFK2 src1 = (ToOneFK2) Cayenne.objectForPK(context, src.getObjectId());
- assertNotNull(src1.getToOneToFK());
- // resolve HOLLOW
- assertSame(src1, src1.getToOneToFK().getToPK());
-
- context.invalidateObjects(src1, src1.getToOneToFK());
-
- ToOneFK1 target2 = (ToOneFK1) Cayenne.objectForPK(context, target.getObjectId());
- assertNotNull(target2.getToPK());
-
- // resolve HOLLOW
- assertSame(target2, target2.getToPK().getToOneToFK());
- }
-
- public void test2Null() throws Exception {
- ToOneFK2 src = context.newObject(ToOneFK2.class);
- context.commitChanges();
-
- // test database data
- ObjectIdQuery refetch = new ObjectIdQuery(
- src.getObjectId(),
- false,
- ObjectIdQuery.CACHE_REFRESH);
- ToOneFK2 src2 = (ToOneFK2) Cayenne.objectForQuery(context1, refetch);
-
- // *** TESTING THIS ***
- assertNull(src2.getToOneToFK());
- }
-
- public void testReplaceNull1() throws Exception {
- ToOneFK2 src = context.newObject(ToOneFK2.class);
- context.commitChanges();
-
- // test database data
- ObjectIdQuery refetch = new ObjectIdQuery(
- src.getObjectId(),
- false,
- ObjectIdQuery.CACHE_REFRESH);
- ToOneFK2 src2 = (ToOneFK2) Cayenne.objectForQuery(context1, refetch);
- assertEquals(src.getObjectId(), src2.getObjectId());
-
- // *** TESTING THIS ***
- src2.setToOneToFK(null);
- assertNull(src2.getToOneToFK());
- }
-
- public void testReplaceNull2() throws Exception {
- ToOneFK2 src = context.newObject(ToOneFK2.class);
- context.commitChanges();
-
- ToOneFK1 target = context.newObject(ToOneFK1.class);
-
- // *** TESTING THIS ***
- src.setToOneToFK(target);
-
- // test before save
- assertSame(target, src.getToOneToFK());
-
- // do save
- context.commitChanges();
-
- // test database data
- ObjectIdQuery refetch = new ObjectIdQuery(
- src.getObjectId(),
- false,
- ObjectIdQuery.CACHE_REFRESH);
- ToOneFK2 src2 = (ToOneFK2) Cayenne.objectForQuery(context1, refetch);
- ToOneFK1 target2 = src2.getToOneToFK();
- assertNotNull(target2);
- assertEquals(src.getObjectId(), src2.getObjectId());
- assertEquals(target.getObjectId(), target2.getObjectId());
- }
-
- public void testNewAdd() throws Exception {
- ToOneFK2 src = context.newObject(ToOneFK2.class);
- ToOneFK1 target = context.newObject(ToOneFK1.class);
-
- // *** TESTING THIS ***
- src.setToOneToFK(target);
-
- // test before save
- assertSame(target, src.getToOneToFK());
-
- // do save
- context.commitChanges();
-
- // test database data
- ObjectIdQuery refetch = new ObjectIdQuery(
- src.getObjectId(),
- false,
- ObjectIdQuery.CACHE_REFRESH);
- ToOneFK2 src2 = (ToOneFK2) Cayenne.objectForQuery(context1, refetch);
- ToOneFK1 target2 = src2.getToOneToFK();
- assertNotNull(target2);
- assertEquals(src.getObjectId(), src2.getObjectId());
- assertEquals(target.getObjectId(), target2.getObjectId());
- }
-
- public void testTakeObjectSnapshotDependentFault() throws Exception {
- ToOneFK2 src = context.newObject(ToOneFK2.class);
- ToOneFK1 target = context.newObject(ToOneFK1.class);
- src.setToOneToFK(target);
- context.commitChanges();
-
- ObjectIdQuery refetch = new ObjectIdQuery(
- src.getObjectId(),
- false,
- ObjectIdQuery.CACHE_REFRESH);
- ToOneFK2 src2 = (ToOneFK2) Cayenne.objectForQuery(context1, refetch);
-
- assertTrue(src2.readPropertyDirectly("toOneToFK") instanceof Fault);
-
- // test that taking a snapshot does not trigger a fault, and generally works well
- context.currentSnapshot(src2);
- assertTrue(src2.readPropertyDirectly("toOneToFK") instanceof Fault);
- }
-
- public void testDelete() throws Exception {
- ToOneFK2 src = context.newObject(ToOneFK2.class);
- ToOneFK1 target = context.newObject(ToOneFK1.class);
- src.setToOneToFK(target);
- context.commitChanges();
-
- src.setToOneToFK(null);
- context.deleteObjects(target);
- context.commitChanges();
-
- // test database data
-
- ObjectIdQuery refetch = new ObjectIdQuery(
- src.getObjectId(),
- false,
- ObjectIdQuery.CACHE_REFRESH);
- ToOneFK2 src2 = (ToOneFK2) Cayenne.objectForQuery(context1, refetch);
- assertNull(src.getToOneToFK());
- assertEquals(src.getObjectId(), src2.getObjectId());
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/CDOQualifiedEntitiesIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CDOQualifiedEntitiesIT.java b/cayenne-server/src/test/java/org/apache/cayenne/CDOQualifiedEntitiesIT.java
new file mode 100644
index 0000000..2b40b30
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/CDOQualifiedEntitiesIT.java
@@ -0,0 +1,126 @@
+/*****************************************************************
+ * 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.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;
+
+import java.sql.Types;
+import java.util.List;
+
+@UseServerRuntime(ServerCase.DEFAULT_PROJECT)
+public class CDOQualifiedEntitiesIT 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);
+ }
+ }
+}