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:09:54 UTC
[06/48] Installing Maven Failsafe Plugin
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/merge/DropColumnToModelTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/merge/DropColumnToModelTest.java b/cayenne-server/src/test/java/org/apache/cayenne/merge/DropColumnToModelTest.java
deleted file mode 100644
index fce3fb5..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/merge/DropColumnToModelTest.java
+++ /dev/null
@@ -1,226 +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.merge;
-
-import java.sql.Types;
-import java.util.List;
-
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.DbJoin;
-import org.apache.cayenne.map.DbRelationship;
-import org.apache.cayenne.map.ObjAttribute;
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.map.ObjRelationship;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class DropColumnToModelTest extends MergeCase {
-
- public void testSimpleColumn() throws Exception {
- dropTableIfPresent("NEW_TABLE");
-
- assertTokensAndExecute(0, 0);
-
- DbEntity dbEntity = new DbEntity("NEW_TABLE");
-
- DbAttribute column1 = new DbAttribute("ID", Types.INTEGER, dbEntity);
- column1.setMandatory(true);
- column1.setPrimaryKey(true);
- dbEntity.addAttribute(column1);
-
- DbAttribute column2 = new DbAttribute("NAME", Types.VARCHAR, dbEntity);
- column2.setMaxLength(10);
- column2.setMandatory(false);
- dbEntity.addAttribute(column2);
-
- map.addDbEntity(dbEntity);
-
- assertTokensAndExecute(1, 0);
- assertTokensAndExecute(0, 0);
-
- ObjEntity objEntity = new ObjEntity("NewTable");
- objEntity.setDbEntity(dbEntity);
- ObjAttribute oatr1 = new ObjAttribute("name");
- oatr1.setDbAttributePath(column2.getName());
- oatr1.setType("java.lang.String");
- objEntity.addAttribute(oatr1);
- map.addObjEntity(objEntity);
-
- // force drop name column in db
- MergerToken token = mergerFactory().createDropColumnToDb(dbEntity, column2);
- execute(token);
-
- List<MergerToken> tokens = createMergeTokens();
- assertEquals(1, tokens.size());
- token = tokens.get(0);
- if (token.getDirection().isToDb()) {
- token = token.createReverse(mergerFactory());
- }
- assertTrue(token instanceof DropColumnToModel);
- execute(token);
- assertNull(dbEntity.getAttribute(column2.getName()));
- assertNull(objEntity.getAttribute(oatr1.getName()));
-
- // clear up
- map.removeObjEntity(objEntity.getName(), true);
- map.removeDbEntity(dbEntity.getName(), true);
- resolver.refreshMappingCache();
- assertNull(map.getObjEntity(objEntity.getName()));
- assertNull(map.getDbEntity(dbEntity.getName()));
- assertFalse(map.getDbEntities().contains(dbEntity));
-
- assertTokensAndExecute(1, 0);
- assertTokensAndExecute(0, 0);
- }
-
- public void testRemoveFKColumnWithoutRelationshipInDb() throws Exception {
- dropTableIfPresent("NEW_TABLE");
- dropTableIfPresent("NEW_TABLE2");
-
- assertTokensAndExecute(0, 0);
-
- DbEntity dbEntity1 = new DbEntity("NEW_TABLE");
-
- DbAttribute e1col1 = new DbAttribute("ID", Types.INTEGER, dbEntity1);
- e1col1.setMandatory(true);
- e1col1.setPrimaryKey(true);
- dbEntity1.addAttribute(e1col1);
-
- DbAttribute e1col2 = new DbAttribute("NAME", Types.VARCHAR, dbEntity1);
- e1col2.setMaxLength(10);
- e1col2.setMandatory(false);
- dbEntity1.addAttribute(e1col2);
-
- map.addDbEntity(dbEntity1);
-
- DbEntity dbEntity2 = new DbEntity("NEW_TABLE2");
- DbAttribute e2col1 = new DbAttribute("ID", Types.INTEGER, dbEntity2);
- e2col1.setMandatory(true);
- e2col1.setPrimaryKey(true);
- dbEntity2.addAttribute(e2col1);
- DbAttribute e2col2 = new DbAttribute("FK", Types.INTEGER, dbEntity2);
- dbEntity2.addAttribute(e2col2);
- DbAttribute e2col3 = new DbAttribute("NAME", Types.VARCHAR, dbEntity2);
- e2col3.setMaxLength(10);
- dbEntity2.addAttribute(e2col3);
-
- map.addDbEntity(dbEntity2);
-
- assertTokensAndExecute(2, 0);
- assertTokensAndExecute(0, 0);
-
- // force drop fk column in db
- execute(mergerFactory().createDropColumnToDb(dbEntity2, e2col2));
-
- // create db relationships, but do not sync them to db
- DbRelationship rel1To2 = new DbRelationship("rel1To2");
- rel1To2.setSourceEntity(dbEntity1);
- rel1To2.setTargetEntity(dbEntity2);
- rel1To2.setToMany(true);
- rel1To2.addJoin(new DbJoin(rel1To2, e1col1.getName(), e2col2.getName()));
- dbEntity1.addRelationship(rel1To2);
- DbRelationship rel2To1 = new DbRelationship("rel2To1");
- rel2To1.setSourceEntity(dbEntity2);
- rel2To1.setTargetEntity(dbEntity1);
- rel2To1.setToMany(false);
- rel2To1.addJoin(new DbJoin(rel2To1, e2col2.getName(), e1col1.getName()));
- dbEntity2.addRelationship(rel2To1);
- assertSame(rel1To2, rel2To1.getReverseRelationship());
- assertSame(rel2To1, rel1To2.getReverseRelationship());
-
- // create ObjEntities
- ObjEntity objEntity1 = new ObjEntity("NewTable");
- objEntity1.setDbEntity(dbEntity1);
- ObjAttribute oatr1 = new ObjAttribute("name");
- oatr1.setDbAttributePath(e1col2.getName());
- oatr1.setType("java.lang.String");
- objEntity1.addAttribute(oatr1);
- map.addObjEntity(objEntity1);
- ObjEntity objEntity2 = new ObjEntity("NewTable2");
- objEntity2.setDbEntity(dbEntity2);
- ObjAttribute o2a1 = new ObjAttribute("name");
- o2a1.setDbAttributePath(e2col3.getName());
- o2a1.setType("java.lang.String");
- objEntity2.addAttribute(o2a1);
- map.addObjEntity(objEntity2);
-
- // create ObjRelationships
- assertEquals(0, objEntity1.getRelationships().size());
- assertEquals(0, objEntity2.getRelationships().size());
- ObjRelationship objRel1To2 = new ObjRelationship("objRel1To2");
- objRel1To2.addDbRelationship(rel1To2);
- objRel1To2.setSourceEntity(objEntity1);
- objRel1To2.setTargetEntity(objEntity2);
- objEntity1.addRelationship(objRel1To2);
- ObjRelationship objRel2To1 = new ObjRelationship("objRel2To1");
- objRel2To1.addDbRelationship(rel2To1);
- objRel2To1.setSourceEntity(objEntity2);
- objRel2To1.setTargetEntity(objEntity1);
- objEntity2.addRelationship(objRel2To1);
- assertEquals(1, objEntity1.getRelationships().size());
- assertEquals(1, objEntity2.getRelationships().size());
- assertSame(objRel1To2, objRel2To1.getReverseRelationship());
- assertSame(objRel2To1, objRel1To2.getReverseRelationship());
-
- // try do use the merger to remove the column and relationship in the model
- List<MergerToken> tokens = createMergeTokens();
- assertTokens(tokens, 2, 0);
- // TODO: reversing the following two tokens should also reverse the order
- MergerToken token0 = tokens.get(0).createReverse(mergerFactory());
- MergerToken token1 = tokens.get(1).createReverse(mergerFactory());
- if (!(token0 instanceof DropRelationshipToModel && token1 instanceof DropColumnToModel
- || token1 instanceof DropRelationshipToModel && token0 instanceof DropColumnToModel)) {
- fail();
- }
- // do not execute DropRelationshipToModel, only DropColumnToModel.
- if (token1 instanceof DropColumnToModel) {
- execute(token1);
- } else {
- execute(token0);
- }
-
- // check after merging
- assertNull(dbEntity2.getAttribute(e2col2.getName()));
- assertEquals(0, dbEntity1.getRelationships().size());
- assertEquals(0, dbEntity2.getRelationships().size());
- assertEquals(0, objEntity1.getRelationships().size());
- assertEquals(0, objEntity2.getRelationships().size());
-
- // clear up
-
- dbEntity1.removeRelationship(rel1To2.getName());
- dbEntity2.removeRelationship(rel2To1.getName());
- map.removeObjEntity(objEntity1.getName(), true);
- map.removeDbEntity(dbEntity1.getName(), true);
- map.removeObjEntity(objEntity2.getName(), true);
- map.removeDbEntity(dbEntity2.getName(), true);
- resolver.refreshMappingCache();
- assertNull(map.getObjEntity(objEntity1.getName()));
- assertNull(map.getDbEntity(dbEntity1.getName()));
- assertNull(map.getObjEntity(objEntity2.getName()));
- assertNull(map.getDbEntity(dbEntity2.getName()));
- assertFalse(map.getDbEntities().contains(dbEntity1));
- assertFalse(map.getDbEntities().contains(dbEntity2));
-
- assertTokensAndExecute(2, 0);
- assertTokensAndExecute(0, 0);
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/merge/DropRelationshipToModelIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/merge/DropRelationshipToModelIT.java b/cayenne-server/src/test/java/org/apache/cayenne/merge/DropRelationshipToModelIT.java
new file mode 100644
index 0000000..cbfe05d
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/merge/DropRelationshipToModelIT.java
@@ -0,0 +1,177 @@
+/*****************************************************************
+ * 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.merge;
+
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.DbJoin;
+import org.apache.cayenne.map.DbRelationship;
+import org.apache.cayenne.map.ObjAttribute;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.map.ObjRelationship;
+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 DropRelationshipToModelIT extends MergeCase {
+
+ public void testForeignKey() throws Exception {
+ dropTableIfPresent("NEW_TABLE");
+ dropTableIfPresent("NEW_TABLE2");
+
+ assertTokensAndExecute(0, 0);
+
+ DbEntity dbEntity1 = new DbEntity("NEW_TABLE");
+
+ DbAttribute e1col1 = new DbAttribute("ID", Types.INTEGER, dbEntity1);
+ e1col1.setMandatory(true);
+ e1col1.setPrimaryKey(true);
+ dbEntity1.addAttribute(e1col1);
+
+ DbAttribute e1col2 = new DbAttribute("NAME", Types.VARCHAR, dbEntity1);
+ e1col2.setMaxLength(10);
+ e1col2.setMandatory(false);
+ dbEntity1.addAttribute(e1col2);
+
+ map.addDbEntity(dbEntity1);
+
+ DbEntity dbEntity2 = new DbEntity("NEW_TABLE2");
+ DbAttribute e2col1 = new DbAttribute("ID", Types.INTEGER, dbEntity2);
+ e2col1.setMandatory(true);
+ e2col1.setPrimaryKey(true);
+ dbEntity2.addAttribute(e2col1);
+ DbAttribute e2col2 = new DbAttribute("FK", Types.INTEGER, dbEntity2);
+ dbEntity2.addAttribute(e2col2);
+ DbAttribute e2col3 = new DbAttribute("NAME", Types.VARCHAR, dbEntity2);
+ e2col3.setMaxLength(10);
+ dbEntity2.addAttribute(e2col3);
+
+ map.addDbEntity(dbEntity2);
+
+ // create db relationships
+ DbRelationship rel1To2 = new DbRelationship("rel1To2");
+ rel1To2.setSourceEntity(dbEntity1);
+ rel1To2.setTargetEntity(dbEntity2);
+ rel1To2.setToMany(true);
+ rel1To2.addJoin(new DbJoin(rel1To2, e1col1.getName(), e2col2.getName()));
+ dbEntity1.addRelationship(rel1To2);
+ DbRelationship rel2To1 = new DbRelationship("rel2To1");
+ rel2To1.setSourceEntity(dbEntity2);
+ rel2To1.setTargetEntity(dbEntity1);
+ rel2To1.setToMany(false);
+ rel2To1.addJoin(new DbJoin(rel2To1, e2col2.getName(), e1col1.getName()));
+ dbEntity2.addRelationship(rel2To1);
+ assertSame(rel1To2, rel2To1.getReverseRelationship());
+ assertSame(rel2To1, rel1To2.getReverseRelationship());
+
+ assertTokensAndExecute(4, 0);
+ assertTokensAndExecute(0, 0);
+
+ // create ObjEntities
+ ObjEntity objEntity1 = new ObjEntity("NewTable");
+ objEntity1.setDbEntity(dbEntity1);
+ ObjAttribute oatr1 = new ObjAttribute("name");
+ oatr1.setDbAttributePath(e1col2.getName());
+ oatr1.setType("java.lang.String");
+ objEntity1.addAttribute(oatr1);
+ map.addObjEntity(objEntity1);
+ ObjEntity objEntity2 = new ObjEntity("NewTable2");
+ objEntity2.setDbEntity(dbEntity2);
+ ObjAttribute o2a1 = new ObjAttribute("name");
+ o2a1.setDbAttributePath(e2col3.getName());
+ o2a1.setType("java.lang.String");
+ objEntity2.addAttribute(o2a1);
+ map.addObjEntity(objEntity2);
+
+ // create ObjRelationships
+ assertEquals(0, objEntity1.getRelationships().size());
+ assertEquals(0, objEntity2.getRelationships().size());
+ ObjRelationship objRel1To2 = new ObjRelationship("objRel1To2");
+ objRel1To2.addDbRelationship(rel1To2);
+ objRel1To2.setSourceEntity(objEntity1);
+ objRel1To2.setTargetEntity(objEntity2);
+ objEntity1.addRelationship(objRel1To2);
+ ObjRelationship objRel2To1 = new ObjRelationship("objRel2To1");
+ objRel2To1.addDbRelationship(rel2To1);
+ objRel2To1.setSourceEntity(objEntity2);
+ objRel2To1.setTargetEntity(objEntity1);
+ objEntity2.addRelationship(objRel2To1);
+ assertEquals(1, objEntity1.getRelationships().size());
+ assertEquals(1, objEntity2.getRelationships().size());
+ assertSame(objRel1To2, objRel2To1.getReverseRelationship());
+ assertSame(objRel2To1, objRel1To2.getReverseRelationship());
+
+ // remove relationship and fk from model, merge to db and read to model
+ dbEntity2.removeRelationship(rel2To1.getName());
+ dbEntity1.removeRelationship(rel1To2.getName());
+ dbEntity2.removeAttribute(e2col2.getName());
+ List<MergerToken> tokens = createMergeTokens();
+ assertTokens(tokens, 2, 1);
+ for (MergerToken token : tokens) {
+ if (token.getDirection().isToDb()) {
+ execute(token);
+ }
+ }
+ assertTokensAndExecute(0, 0);
+ dbEntity2.addRelationship(rel2To1);
+ dbEntity1.addRelationship(rel1To2);
+ dbEntity2.addAttribute(e2col2);
+
+ // try do use the merger to remove the relationship in the model
+ tokens = createMergeTokens();
+ assertTokens(tokens, 2, 0);
+ // TODO: reversing the following two tokens should also reverse the order
+ MergerToken token0 = tokens.get(0).createReverse(mergerFactory());
+ MergerToken token1 = tokens.get(1).createReverse(mergerFactory());
+ if (!(token0 instanceof DropRelationshipToModel && token1 instanceof DropColumnToModel
+ || token1 instanceof DropRelationshipToModel && token0 instanceof DropColumnToModel)) {
+ fail();
+ }
+ execute(token0);
+ execute(token1);
+
+ // check after merging
+ assertNull(dbEntity2.getAttribute(e2col2.getName()));
+ assertEquals(0, dbEntity1.getRelationships().size());
+ assertEquals(0, dbEntity2.getRelationships().size());
+ assertEquals(0, objEntity1.getRelationships().size());
+ assertEquals(0, objEntity2.getRelationships().size());
+
+ // clear up
+ dbEntity1.removeRelationship(rel1To2.getName());
+ dbEntity2.removeRelationship(rel2To1.getName());
+ map.removeObjEntity(objEntity1.getName(), true);
+ map.removeDbEntity(dbEntity1.getName(), true);
+ map.removeObjEntity(objEntity2.getName(), true);
+ map.removeDbEntity(dbEntity2.getName(), true);
+ resolver.refreshMappingCache();
+ assertNull(map.getObjEntity(objEntity1.getName()));
+ assertNull(map.getDbEntity(dbEntity1.getName()));
+ assertNull(map.getObjEntity(objEntity2.getName()));
+ assertNull(map.getDbEntity(dbEntity2.getName()));
+ assertFalse(map.getDbEntities().contains(dbEntity1));
+ assertFalse(map.getDbEntities().contains(dbEntity2));
+
+ assertTokensAndExecute(2, 0);
+ assertTokensAndExecute(0, 0);
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/merge/DropRelationshipToModelTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/merge/DropRelationshipToModelTest.java b/cayenne-server/src/test/java/org/apache/cayenne/merge/DropRelationshipToModelTest.java
deleted file mode 100644
index 4e0dfb4..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/merge/DropRelationshipToModelTest.java
+++ /dev/null
@@ -1,177 +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.merge;
-
-import java.sql.Types;
-import java.util.List;
-
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.DbJoin;
-import org.apache.cayenne.map.DbRelationship;
-import org.apache.cayenne.map.ObjAttribute;
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.map.ObjRelationship;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class DropRelationshipToModelTest extends MergeCase {
-
- public void testForeignKey() throws Exception {
- dropTableIfPresent("NEW_TABLE");
- dropTableIfPresent("NEW_TABLE2");
-
- assertTokensAndExecute(0, 0);
-
- DbEntity dbEntity1 = new DbEntity("NEW_TABLE");
-
- DbAttribute e1col1 = new DbAttribute("ID", Types.INTEGER, dbEntity1);
- e1col1.setMandatory(true);
- e1col1.setPrimaryKey(true);
- dbEntity1.addAttribute(e1col1);
-
- DbAttribute e1col2 = new DbAttribute("NAME", Types.VARCHAR, dbEntity1);
- e1col2.setMaxLength(10);
- e1col2.setMandatory(false);
- dbEntity1.addAttribute(e1col2);
-
- map.addDbEntity(dbEntity1);
-
- DbEntity dbEntity2 = new DbEntity("NEW_TABLE2");
- DbAttribute e2col1 = new DbAttribute("ID", Types.INTEGER, dbEntity2);
- e2col1.setMandatory(true);
- e2col1.setPrimaryKey(true);
- dbEntity2.addAttribute(e2col1);
- DbAttribute e2col2 = new DbAttribute("FK", Types.INTEGER, dbEntity2);
- dbEntity2.addAttribute(e2col2);
- DbAttribute e2col3 = new DbAttribute("NAME", Types.VARCHAR, dbEntity2);
- e2col3.setMaxLength(10);
- dbEntity2.addAttribute(e2col3);
-
- map.addDbEntity(dbEntity2);
-
- // create db relationships
- DbRelationship rel1To2 = new DbRelationship("rel1To2");
- rel1To2.setSourceEntity(dbEntity1);
- rel1To2.setTargetEntity(dbEntity2);
- rel1To2.setToMany(true);
- rel1To2.addJoin(new DbJoin(rel1To2, e1col1.getName(), e2col2.getName()));
- dbEntity1.addRelationship(rel1To2);
- DbRelationship rel2To1 = new DbRelationship("rel2To1");
- rel2To1.setSourceEntity(dbEntity2);
- rel2To1.setTargetEntity(dbEntity1);
- rel2To1.setToMany(false);
- rel2To1.addJoin(new DbJoin(rel2To1, e2col2.getName(), e1col1.getName()));
- dbEntity2.addRelationship(rel2To1);
- assertSame(rel1To2, rel2To1.getReverseRelationship());
- assertSame(rel2To1, rel1To2.getReverseRelationship());
-
- assertTokensAndExecute(4, 0);
- assertTokensAndExecute(0, 0);
-
- // create ObjEntities
- ObjEntity objEntity1 = new ObjEntity("NewTable");
- objEntity1.setDbEntity(dbEntity1);
- ObjAttribute oatr1 = new ObjAttribute("name");
- oatr1.setDbAttributePath(e1col2.getName());
- oatr1.setType("java.lang.String");
- objEntity1.addAttribute(oatr1);
- map.addObjEntity(objEntity1);
- ObjEntity objEntity2 = new ObjEntity("NewTable2");
- objEntity2.setDbEntity(dbEntity2);
- ObjAttribute o2a1 = new ObjAttribute("name");
- o2a1.setDbAttributePath(e2col3.getName());
- o2a1.setType("java.lang.String");
- objEntity2.addAttribute(o2a1);
- map.addObjEntity(objEntity2);
-
- // create ObjRelationships
- assertEquals(0, objEntity1.getRelationships().size());
- assertEquals(0, objEntity2.getRelationships().size());
- ObjRelationship objRel1To2 = new ObjRelationship("objRel1To2");
- objRel1To2.addDbRelationship(rel1To2);
- objRel1To2.setSourceEntity(objEntity1);
- objRel1To2.setTargetEntity(objEntity2);
- objEntity1.addRelationship(objRel1To2);
- ObjRelationship objRel2To1 = new ObjRelationship("objRel2To1");
- objRel2To1.addDbRelationship(rel2To1);
- objRel2To1.setSourceEntity(objEntity2);
- objRel2To1.setTargetEntity(objEntity1);
- objEntity2.addRelationship(objRel2To1);
- assertEquals(1, objEntity1.getRelationships().size());
- assertEquals(1, objEntity2.getRelationships().size());
- assertSame(objRel1To2, objRel2To1.getReverseRelationship());
- assertSame(objRel2To1, objRel1To2.getReverseRelationship());
-
- // remove relationship and fk from model, merge to db and read to model
- dbEntity2.removeRelationship(rel2To1.getName());
- dbEntity1.removeRelationship(rel1To2.getName());
- dbEntity2.removeAttribute(e2col2.getName());
- List<MergerToken> tokens = createMergeTokens();
- assertTokens(tokens, 2, 1);
- for (MergerToken token : tokens) {
- if (token.getDirection().isToDb()) {
- execute(token);
- }
- }
- assertTokensAndExecute(0, 0);
- dbEntity2.addRelationship(rel2To1);
- dbEntity1.addRelationship(rel1To2);
- dbEntity2.addAttribute(e2col2);
-
- // try do use the merger to remove the relationship in the model
- tokens = createMergeTokens();
- assertTokens(tokens, 2, 0);
- // TODO: reversing the following two tokens should also reverse the order
- MergerToken token0 = tokens.get(0).createReverse(mergerFactory());
- MergerToken token1 = tokens.get(1).createReverse(mergerFactory());
- if (!(token0 instanceof DropRelationshipToModel && token1 instanceof DropColumnToModel
- || token1 instanceof DropRelationshipToModel && token0 instanceof DropColumnToModel)) {
- fail();
- }
- execute(token0);
- execute(token1);
-
- // check after merging
- assertNull(dbEntity2.getAttribute(e2col2.getName()));
- assertEquals(0, dbEntity1.getRelationships().size());
- assertEquals(0, dbEntity2.getRelationships().size());
- assertEquals(0, objEntity1.getRelationships().size());
- assertEquals(0, objEntity2.getRelationships().size());
-
- // clear up
- dbEntity1.removeRelationship(rel1To2.getName());
- dbEntity2.removeRelationship(rel2To1.getName());
- map.removeObjEntity(objEntity1.getName(), true);
- map.removeDbEntity(dbEntity1.getName(), true);
- map.removeObjEntity(objEntity2.getName(), true);
- map.removeDbEntity(dbEntity2.getName(), true);
- resolver.refreshMappingCache();
- assertNull(map.getObjEntity(objEntity1.getName()));
- assertNull(map.getDbEntity(dbEntity1.getName()));
- assertNull(map.getObjEntity(objEntity2.getName()));
- assertNull(map.getDbEntity(dbEntity2.getName()));
- assertFalse(map.getDbEntities().contains(dbEntity1));
- assertFalse(map.getDbEntities().contains(dbEntity2));
-
- assertTokensAndExecute(2, 0);
- assertTokensAndExecute(0, 0);
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/merge/DropTableToModelIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/merge/DropTableToModelIT.java b/cayenne-server/src/test/java/org/apache/cayenne/merge/DropTableToModelIT.java
new file mode 100644
index 0000000..bec6005
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/merge/DropTableToModelIT.java
@@ -0,0 +1,90 @@
+/*****************************************************************
+ * 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.merge;
+
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.ObjAttribute;
+import org.apache.cayenne.map.ObjEntity;
+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 DropTableToModelIT extends MergeCase {
+
+ public void testDropTable() throws Exception {
+ dropTableIfPresent("NEW_TABLE");
+ assertTokensAndExecute(0, 0);
+
+ DbEntity dbEntity = new DbEntity("NEW_TABLE");
+
+ DbAttribute column1 = new DbAttribute("ID", Types.INTEGER, dbEntity);
+ column1.setMandatory(true);
+ column1.setPrimaryKey(true);
+ dbEntity.addAttribute(column1);
+
+ DbAttribute column2 = new DbAttribute("NAME", Types.VARCHAR, dbEntity);
+ column2.setMaxLength(10);
+ column2.setMandatory(false);
+ dbEntity.addAttribute(column2);
+
+ map.addDbEntity(dbEntity);
+
+ assertTokensAndExecute(1, 0);
+ assertTokensAndExecute(0, 0);
+
+ ObjEntity objEntity = new ObjEntity("NewTable");
+ objEntity.setDbEntity(dbEntity);
+ ObjAttribute oatr1 = new ObjAttribute("name");
+ oatr1.setDbAttributePath(column2.getName());
+ oatr1.setType("java.lang.String");
+ objEntity.addAttribute(oatr1);
+ map.addObjEntity(objEntity);
+
+ // force drop table in db
+ MergerToken token = mergerFactory().createDropTableToDb(dbEntity);
+ execute(token);
+
+ List<MergerToken> tokens = createMergeTokens();
+ assertEquals(1, tokens.size());
+ token = tokens.get(0);
+ if (token.getDirection().isToDb()) {
+ token = token.createReverse(mergerFactory());
+ }
+ assertTrue(token instanceof DropTableToModel);
+ execute(token);
+ resolver.refreshMappingCache();
+ assertNull(map.getDbEntity(dbEntity.getName()));
+ assertNull(map.getObjEntity(objEntity.getName()));
+
+ // clear up
+ map.removeObjEntity(objEntity.getName(), true);
+ map.removeDbEntity(dbEntity.getName(), true);
+ resolver.refreshMappingCache();
+ assertNull(map.getObjEntity(objEntity.getName()));
+ assertNull(map.getDbEntity(dbEntity.getName()));
+ assertFalse(map.getDbEntities().contains(dbEntity));
+
+ assertTokensAndExecute(0, 0);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/merge/DropTableToModelTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/merge/DropTableToModelTest.java b/cayenne-server/src/test/java/org/apache/cayenne/merge/DropTableToModelTest.java
deleted file mode 100644
index 45881a9..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/merge/DropTableToModelTest.java
+++ /dev/null
@@ -1,90 +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.merge;
-
-import java.sql.Types;
-import java.util.List;
-
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.ObjAttribute;
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class DropTableToModelTest extends MergeCase {
-
- public void testDropTable() throws Exception {
- dropTableIfPresent("NEW_TABLE");
- assertTokensAndExecute(0, 0);
-
- DbEntity dbEntity = new DbEntity("NEW_TABLE");
-
- DbAttribute column1 = new DbAttribute("ID", Types.INTEGER, dbEntity);
- column1.setMandatory(true);
- column1.setPrimaryKey(true);
- dbEntity.addAttribute(column1);
-
- DbAttribute column2 = new DbAttribute("NAME", Types.VARCHAR, dbEntity);
- column2.setMaxLength(10);
- column2.setMandatory(false);
- dbEntity.addAttribute(column2);
-
- map.addDbEntity(dbEntity);
-
- assertTokensAndExecute(1, 0);
- assertTokensAndExecute(0, 0);
-
- ObjEntity objEntity = new ObjEntity("NewTable");
- objEntity.setDbEntity(dbEntity);
- ObjAttribute oatr1 = new ObjAttribute("name");
- oatr1.setDbAttributePath(column2.getName());
- oatr1.setType("java.lang.String");
- objEntity.addAttribute(oatr1);
- map.addObjEntity(objEntity);
-
- // force drop table in db
- MergerToken token = mergerFactory().createDropTableToDb(dbEntity);
- execute(token);
-
- List<MergerToken> tokens = createMergeTokens();
- assertEquals(1, tokens.size());
- token = tokens.get(0);
- if (token.getDirection().isToDb()) {
- token = token.createReverse(mergerFactory());
- }
- assertTrue(token instanceof DropTableToModel);
- execute(token);
- resolver.refreshMappingCache();
- assertNull(map.getDbEntity(dbEntity.getName()));
- assertNull(map.getObjEntity(objEntity.getName()));
-
- // clear up
- map.removeObjEntity(objEntity.getName(), true);
- map.removeDbEntity(dbEntity.getName(), true);
- resolver.refreshMappingCache();
- assertNull(map.getObjEntity(objEntity.getName()));
- assertNull(map.getDbEntity(dbEntity.getName()));
- assertFalse(map.getDbEntities().contains(dbEntity));
-
- assertTokensAndExecute(0, 0);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/merge/MergerFactoryIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/merge/MergerFactoryIT.java b/cayenne-server/src/test/java/org/apache/cayenne/merge/MergerFactoryIT.java
new file mode 100644
index 0000000..298acec
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/merge/MergerFactoryIT.java
@@ -0,0 +1,306 @@
+/*****************************************************************
+ * 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.merge;
+
+import org.apache.cayenne.CayenneDataObject;
+import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.DbJoin;
+import org.apache.cayenne.map.DbRelationship;
+import org.apache.cayenne.map.ObjAttribute;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.sql.Types;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class MergerFactoryIT extends MergeCase {
+
+ @Inject
+ private DataContext context;
+
+ public void testAddAndDropColumnToDb() throws Exception {
+ DbEntity dbEntity = map.getDbEntity("PAINTING");
+ assertNotNull(dbEntity);
+
+ // create and add new column to model and db
+ DbAttribute column = new DbAttribute("NEWCOL1", Types.VARCHAR, dbEntity);
+
+ column.setMandatory(false);
+ column.setMaxLength(10);
+ dbEntity.addAttribute(column);
+ assertTokensAndExecute(1, 0);
+
+ // try merge once more to check that is was merged
+ assertTokensAndExecute(0, 0);
+
+ // remove it from model and db
+ dbEntity.removeAttribute(column.getName());
+ assertTokensAndExecute(1, 0);
+ assertTokensAndExecute(0, 0);
+ }
+
+ public void testChangeVarcharSizeToDb() throws Exception {
+ DbEntity dbEntity = map.getDbEntity("PAINTING");
+ assertNotNull(dbEntity);
+
+ // create and add new column to model and db
+ DbAttribute column = new DbAttribute("NEWCOL2", Types.VARCHAR, dbEntity);
+
+ column.setMandatory(false);
+ column.setMaxLength(10);
+ dbEntity.addAttribute(column);
+ assertTokensAndExecute(1, 0);
+
+ // check that is was merged
+ assertTokensAndExecute(0, 0);
+
+ // change size
+ column.setMaxLength(20);
+
+ // merge to db
+ assertTokensAndExecute(1, 0);
+
+ // check that is was merged
+ assertTokensAndExecute(0, 0);
+
+ // clean up
+ dbEntity.removeAttribute(column.getName());
+ assertTokensAndExecute(1, 0);
+ assertTokensAndExecute(0, 0);
+ }
+
+ public void testMultipleTokensToDb() throws Exception {
+ DbEntity dbEntity = map.getDbEntity("PAINTING");
+ assertNotNull(dbEntity);
+
+ DbAttribute column1 = new DbAttribute("NEWCOL3", Types.VARCHAR, dbEntity);
+ column1.setMandatory(false);
+ column1.setMaxLength(10);
+ dbEntity.addAttribute(column1);
+ DbAttribute column2 = new DbAttribute("NEWCOL4", Types.VARCHAR, dbEntity);
+ column2.setMandatory(false);
+ column2.setMaxLength(10);
+ dbEntity.addAttribute(column2);
+
+ assertTokensAndExecute(2, 0);
+
+ // check that is was merged
+ assertTokensAndExecute(0, 0);
+
+ // change size
+ column1.setMaxLength(20);
+ column2.setMaxLength(30);
+
+ // merge to db
+ assertTokensAndExecute(2, 0);
+
+ // check that is was merged
+ assertTokensAndExecute(0, 0);
+
+ // clean up
+ dbEntity.removeAttribute(column1.getName());
+ dbEntity.removeAttribute(column2.getName());
+ assertTokensAndExecute(2, 0);
+ assertTokensAndExecute(0, 0);
+ }
+
+ public void testAddTableToDb() throws Exception {
+ dropTableIfPresent("NEW_TABLE");
+
+ assertTokensAndExecute(0, 0);
+
+ DbEntity dbEntity = new DbEntity("NEW_TABLE");
+
+ DbAttribute column1 = new DbAttribute("ID", Types.INTEGER, dbEntity);
+ column1.setMandatory(true);
+ column1.setPrimaryKey(true);
+ dbEntity.addAttribute(column1);
+
+ DbAttribute column2 = new DbAttribute("NAME", Types.VARCHAR, dbEntity);
+ column2.setMaxLength(10);
+ column2.setMandatory(false);
+ dbEntity.addAttribute(column2);
+
+ map.addDbEntity(dbEntity);
+
+ assertTokensAndExecute(1, 0);
+ assertTokensAndExecute(0, 0);
+
+ ObjEntity objEntity = new ObjEntity("NewTable");
+ objEntity.setDbEntity(dbEntity);
+ ObjAttribute oatr1 = new ObjAttribute("name");
+ oatr1.setDbAttributePath(column2.getName());
+ oatr1.setType("java.lang.String");
+ objEntity.addAttribute(oatr1);
+ map.addObjEntity(objEntity);
+
+ for (int i = 0; i < 5; i++) {
+ CayenneDataObject dao = (CayenneDataObject) context.newObject(objEntity
+ .getName());
+ dao.writeProperty(oatr1.getName(), "test " + i);
+ }
+ context.commitChanges();
+
+ // clear up
+ map.removeObjEntity(objEntity.getName(), true);
+ map.removeDbEntity(dbEntity.getName(), true);
+ resolver.refreshMappingCache();
+ assertNull(map.getObjEntity(objEntity.getName()));
+ assertNull(map.getDbEntity(dbEntity.getName()));
+ assertFalse(map.getDbEntities().contains(dbEntity));
+
+ assertTokensAndExecute(1, 0);
+ assertTokensAndExecute(0, 0);
+ }
+
+ public void testAddForeignKeyWithTable() throws Exception {
+ dropTableIfPresent("NEW_TABLE");
+
+ assertTokensAndExecute(0, 0);
+
+ DbEntity dbEntity = new DbEntity("NEW_TABLE");
+
+ DbAttribute column1 = new DbAttribute("ID", Types.INTEGER, dbEntity);
+ column1.setMandatory(true);
+ column1.setPrimaryKey(true);
+ dbEntity.addAttribute(column1);
+
+ DbAttribute column2 = new DbAttribute("NAME", Types.VARCHAR, dbEntity);
+ column2.setMaxLength(10);
+ column2.setMandatory(false);
+ dbEntity.addAttribute(column2);
+
+ DbAttribute column3 = new DbAttribute("ARTIST_ID", Types.BIGINT, dbEntity);
+ column3.setMandatory(false);
+ dbEntity.addAttribute(column3);
+
+ map.addDbEntity(dbEntity);
+
+ DbEntity artistDbEntity = map.getDbEntity("ARTIST");
+ assertNotNull(artistDbEntity);
+
+ // relation from new_table to artist
+ DbRelationship r1 = new DbRelationship("toArtistR1");
+ r1.setSourceEntity(dbEntity);
+ r1.setTargetEntity(artistDbEntity);
+ r1.setToMany(false);
+ r1.addJoin(new DbJoin(r1, "ARTIST_ID", "ARTIST_ID"));
+ dbEntity.addRelationship(r1);
+
+ // relation from artist to new_table
+ DbRelationship r2 = new DbRelationship("toNewTableR2");
+ r2.setSourceEntity(artistDbEntity);
+ r2.setTargetEntity(dbEntity);
+ r2.setToMany(true);
+ r2.addJoin(new DbJoin(r2, "ARTIST_ID", "ARTIST_ID"));
+ artistDbEntity.addRelationship(r2);
+
+ assertTokensAndExecute(2, 0);
+ assertTokensAndExecute(0, 0);
+
+ // remove relationships
+ dbEntity.removeRelationship(r1.getName());
+ artistDbEntity.removeRelationship(r2.getName());
+ resolver.refreshMappingCache();
+ assertTokensAndExecute(1, 1);
+ assertTokensAndExecute(0, 0);
+
+ // clear up
+ // map.removeObjEntity(objEntity.getName(), true);
+ map.removeDbEntity(dbEntity.getName(), true);
+ resolver.refreshMappingCache();
+ // assertNull(map.getObjEntity(objEntity.getName()));
+ assertNull(map.getDbEntity(dbEntity.getName()));
+ assertFalse(map.getDbEntities().contains(dbEntity));
+
+ assertTokensAndExecute(1, 0);
+ assertTokensAndExecute(0, 0);
+ }
+
+ public void testAddForeignKeyAfterTable() throws Exception {
+ dropTableIfPresent("NEW_TABLE");
+
+ assertTokensAndExecute(0, 0);
+
+ DbEntity dbEntity = new DbEntity("NEW_TABLE");
+
+ DbAttribute column1 = new DbAttribute("ID", Types.INTEGER, dbEntity);
+ column1.setMandatory(true);
+ column1.setPrimaryKey(true);
+ dbEntity.addAttribute(column1);
+
+ DbAttribute column2 = new DbAttribute("NAME", Types.VARCHAR, dbEntity);
+ column2.setMaxLength(10);
+ column2.setMandatory(false);
+ dbEntity.addAttribute(column2);
+
+ DbAttribute column3 = new DbAttribute("ARTIST_ID", Types.BIGINT, dbEntity);
+ column3.setMandatory(false);
+ dbEntity.addAttribute(column3);
+
+ map.addDbEntity(dbEntity);
+
+ DbEntity artistDbEntity = map.getDbEntity("ARTIST");
+ assertNotNull(artistDbEntity);
+
+ assertTokensAndExecute(1, 0);
+ assertTokensAndExecute(0, 0);
+
+ // relation from new_table to artist
+ DbRelationship r1 = new DbRelationship("toArtistR1");
+ r1.setSourceEntity(dbEntity);
+ r1.setTargetEntity(artistDbEntity);
+ r1.setToMany(false);
+ r1.addJoin(new DbJoin(r1, "ARTIST_ID", "ARTIST_ID"));
+ dbEntity.addRelationship(r1);
+
+ // relation from artist to new_table
+ DbRelationship r2 = new DbRelationship("toNewTableR2");
+ r2.setSourceEntity(artistDbEntity);
+ r2.setTargetEntity(dbEntity);
+ r2.setToMany(true);
+ r2.addJoin(new DbJoin(r2, "ARTIST_ID", "ARTIST_ID"));
+ artistDbEntity.addRelationship(r2);
+
+ assertTokensAndExecute(1, 0);
+ assertTokensAndExecute(0, 0);
+
+ // remove relationships
+ dbEntity.removeRelationship(r1.getName());
+ artistDbEntity.removeRelationship(r2.getName());
+ resolver.refreshMappingCache();
+ assertTokensAndExecute(1, 1);
+ assertTokensAndExecute(0, 0);
+
+ // clear up
+ // map.removeObjEntity(objEntity.getName(), true);
+ map.removeDbEntity(dbEntity.getName(), true);
+ resolver.refreshMappingCache();
+ // assertNull(map.getObjEntity(objEntity.getName()));
+ assertNull(map.getDbEntity(dbEntity.getName()));
+ assertFalse(map.getDbEntities().contains(dbEntity));
+
+ assertTokensAndExecute(1, 0);
+ assertTokensAndExecute(0, 0);
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/merge/MergerFactoryTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/merge/MergerFactoryTest.java b/cayenne-server/src/test/java/org/apache/cayenne/merge/MergerFactoryTest.java
deleted file mode 100644
index 0799c7c..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/merge/MergerFactoryTest.java
+++ /dev/null
@@ -1,306 +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.merge;
-
-import java.sql.Types;
-
-import org.apache.cayenne.CayenneDataObject;
-import org.apache.cayenne.access.DataContext;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.DbJoin;
-import org.apache.cayenne.map.DbRelationship;
-import org.apache.cayenne.map.ObjAttribute;
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class MergerFactoryTest extends MergeCase {
-
- @Inject
- private DataContext context;
-
- public void testAddAndDropColumnToDb() throws Exception {
- DbEntity dbEntity = map.getDbEntity("PAINTING");
- assertNotNull(dbEntity);
-
- // create and add new column to model and db
- DbAttribute column = new DbAttribute("NEWCOL1", Types.VARCHAR, dbEntity);
-
- column.setMandatory(false);
- column.setMaxLength(10);
- dbEntity.addAttribute(column);
- assertTokensAndExecute(1, 0);
-
- // try merge once more to check that is was merged
- assertTokensAndExecute(0, 0);
-
- // remove it from model and db
- dbEntity.removeAttribute(column.getName());
- assertTokensAndExecute(1, 0);
- assertTokensAndExecute(0, 0);
- }
-
- public void testChangeVarcharSizeToDb() throws Exception {
- DbEntity dbEntity = map.getDbEntity("PAINTING");
- assertNotNull(dbEntity);
-
- // create and add new column to model and db
- DbAttribute column = new DbAttribute("NEWCOL2", Types.VARCHAR, dbEntity);
-
- column.setMandatory(false);
- column.setMaxLength(10);
- dbEntity.addAttribute(column);
- assertTokensAndExecute(1, 0);
-
- // check that is was merged
- assertTokensAndExecute(0, 0);
-
- // change size
- column.setMaxLength(20);
-
- // merge to db
- assertTokensAndExecute(1, 0);
-
- // check that is was merged
- assertTokensAndExecute(0, 0);
-
- // clean up
- dbEntity.removeAttribute(column.getName());
- assertTokensAndExecute(1, 0);
- assertTokensAndExecute(0, 0);
- }
-
- public void testMultipleTokensToDb() throws Exception {
- DbEntity dbEntity = map.getDbEntity("PAINTING");
- assertNotNull(dbEntity);
-
- DbAttribute column1 = new DbAttribute("NEWCOL3", Types.VARCHAR, dbEntity);
- column1.setMandatory(false);
- column1.setMaxLength(10);
- dbEntity.addAttribute(column1);
- DbAttribute column2 = new DbAttribute("NEWCOL4", Types.VARCHAR, dbEntity);
- column2.setMandatory(false);
- column2.setMaxLength(10);
- dbEntity.addAttribute(column2);
-
- assertTokensAndExecute(2, 0);
-
- // check that is was merged
- assertTokensAndExecute(0, 0);
-
- // change size
- column1.setMaxLength(20);
- column2.setMaxLength(30);
-
- // merge to db
- assertTokensAndExecute(2, 0);
-
- // check that is was merged
- assertTokensAndExecute(0, 0);
-
- // clean up
- dbEntity.removeAttribute(column1.getName());
- dbEntity.removeAttribute(column2.getName());
- assertTokensAndExecute(2, 0);
- assertTokensAndExecute(0, 0);
- }
-
- public void testAddTableToDb() throws Exception {
- dropTableIfPresent("NEW_TABLE");
-
- assertTokensAndExecute(0, 0);
-
- DbEntity dbEntity = new DbEntity("NEW_TABLE");
-
- DbAttribute column1 = new DbAttribute("ID", Types.INTEGER, dbEntity);
- column1.setMandatory(true);
- column1.setPrimaryKey(true);
- dbEntity.addAttribute(column1);
-
- DbAttribute column2 = new DbAttribute("NAME", Types.VARCHAR, dbEntity);
- column2.setMaxLength(10);
- column2.setMandatory(false);
- dbEntity.addAttribute(column2);
-
- map.addDbEntity(dbEntity);
-
- assertTokensAndExecute(1, 0);
- assertTokensAndExecute(0, 0);
-
- ObjEntity objEntity = new ObjEntity("NewTable");
- objEntity.setDbEntity(dbEntity);
- ObjAttribute oatr1 = new ObjAttribute("name");
- oatr1.setDbAttributePath(column2.getName());
- oatr1.setType("java.lang.String");
- objEntity.addAttribute(oatr1);
- map.addObjEntity(objEntity);
-
- for (int i = 0; i < 5; i++) {
- CayenneDataObject dao = (CayenneDataObject) context.newObject(objEntity
- .getName());
- dao.writeProperty(oatr1.getName(), "test " + i);
- }
- context.commitChanges();
-
- // clear up
- map.removeObjEntity(objEntity.getName(), true);
- map.removeDbEntity(dbEntity.getName(), true);
- resolver.refreshMappingCache();
- assertNull(map.getObjEntity(objEntity.getName()));
- assertNull(map.getDbEntity(dbEntity.getName()));
- assertFalse(map.getDbEntities().contains(dbEntity));
-
- assertTokensAndExecute(1, 0);
- assertTokensAndExecute(0, 0);
- }
-
- public void testAddForeignKeyWithTable() throws Exception {
- dropTableIfPresent("NEW_TABLE");
-
- assertTokensAndExecute(0, 0);
-
- DbEntity dbEntity = new DbEntity("NEW_TABLE");
-
- DbAttribute column1 = new DbAttribute("ID", Types.INTEGER, dbEntity);
- column1.setMandatory(true);
- column1.setPrimaryKey(true);
- dbEntity.addAttribute(column1);
-
- DbAttribute column2 = new DbAttribute("NAME", Types.VARCHAR, dbEntity);
- column2.setMaxLength(10);
- column2.setMandatory(false);
- dbEntity.addAttribute(column2);
-
- DbAttribute column3 = new DbAttribute("ARTIST_ID", Types.BIGINT, dbEntity);
- column3.setMandatory(false);
- dbEntity.addAttribute(column3);
-
- map.addDbEntity(dbEntity);
-
- DbEntity artistDbEntity = map.getDbEntity("ARTIST");
- assertNotNull(artistDbEntity);
-
- // relation from new_table to artist
- DbRelationship r1 = new DbRelationship("toArtistR1");
- r1.setSourceEntity(dbEntity);
- r1.setTargetEntity(artistDbEntity);
- r1.setToMany(false);
- r1.addJoin(new DbJoin(r1, "ARTIST_ID", "ARTIST_ID"));
- dbEntity.addRelationship(r1);
-
- // relation from artist to new_table
- DbRelationship r2 = new DbRelationship("toNewTableR2");
- r2.setSourceEntity(artistDbEntity);
- r2.setTargetEntity(dbEntity);
- r2.setToMany(true);
- r2.addJoin(new DbJoin(r2, "ARTIST_ID", "ARTIST_ID"));
- artistDbEntity.addRelationship(r2);
-
- assertTokensAndExecute(2, 0);
- assertTokensAndExecute(0, 0);
-
- // remove relationships
- dbEntity.removeRelationship(r1.getName());
- artistDbEntity.removeRelationship(r2.getName());
- resolver.refreshMappingCache();
- assertTokensAndExecute(1, 1);
- assertTokensAndExecute(0, 0);
-
- // clear up
- // map.removeObjEntity(objEntity.getName(), true);
- map.removeDbEntity(dbEntity.getName(), true);
- resolver.refreshMappingCache();
- // assertNull(map.getObjEntity(objEntity.getName()));
- assertNull(map.getDbEntity(dbEntity.getName()));
- assertFalse(map.getDbEntities().contains(dbEntity));
-
- assertTokensAndExecute(1, 0);
- assertTokensAndExecute(0, 0);
- }
-
- public void testAddForeignKeyAfterTable() throws Exception {
- dropTableIfPresent("NEW_TABLE");
-
- assertTokensAndExecute(0, 0);
-
- DbEntity dbEntity = new DbEntity("NEW_TABLE");
-
- DbAttribute column1 = new DbAttribute("ID", Types.INTEGER, dbEntity);
- column1.setMandatory(true);
- column1.setPrimaryKey(true);
- dbEntity.addAttribute(column1);
-
- DbAttribute column2 = new DbAttribute("NAME", Types.VARCHAR, dbEntity);
- column2.setMaxLength(10);
- column2.setMandatory(false);
- dbEntity.addAttribute(column2);
-
- DbAttribute column3 = new DbAttribute("ARTIST_ID", Types.BIGINT, dbEntity);
- column3.setMandatory(false);
- dbEntity.addAttribute(column3);
-
- map.addDbEntity(dbEntity);
-
- DbEntity artistDbEntity = map.getDbEntity("ARTIST");
- assertNotNull(artistDbEntity);
-
- assertTokensAndExecute(1, 0);
- assertTokensAndExecute(0, 0);
-
- // relation from new_table to artist
- DbRelationship r1 = new DbRelationship("toArtistR1");
- r1.setSourceEntity(dbEntity);
- r1.setTargetEntity(artistDbEntity);
- r1.setToMany(false);
- r1.addJoin(new DbJoin(r1, "ARTIST_ID", "ARTIST_ID"));
- dbEntity.addRelationship(r1);
-
- // relation from artist to new_table
- DbRelationship r2 = new DbRelationship("toNewTableR2");
- r2.setSourceEntity(artistDbEntity);
- r2.setTargetEntity(dbEntity);
- r2.setToMany(true);
- r2.addJoin(new DbJoin(r2, "ARTIST_ID", "ARTIST_ID"));
- artistDbEntity.addRelationship(r2);
-
- assertTokensAndExecute(1, 0);
- assertTokensAndExecute(0, 0);
-
- // remove relationships
- dbEntity.removeRelationship(r1.getName());
- artistDbEntity.removeRelationship(r2.getName());
- resolver.refreshMappingCache();
- assertTokensAndExecute(1, 1);
- assertTokensAndExecute(0, 0);
-
- // clear up
- // map.removeObjEntity(objEntity.getName(), true);
- map.removeDbEntity(dbEntity.getName(), true);
- resolver.refreshMappingCache();
- // assertNull(map.getObjEntity(objEntity.getName()));
- assertNull(map.getDbEntity(dbEntity.getName()));
- assertFalse(map.getDbEntities().contains(dbEntity));
-
- assertTokensAndExecute(1, 0);
- assertTokensAndExecute(0, 0);
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/merge/SetAllowNullToDbIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/merge/SetAllowNullToDbIT.java b/cayenne-server/src/test/java/org/apache/cayenne/merge/SetAllowNullToDbIT.java
new file mode 100644
index 0000000..067303b
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/merge/SetAllowNullToDbIT.java
@@ -0,0 +1,66 @@
+/*****************************************************************
+ * 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.merge;
+
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.sql.Types;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class SetAllowNullToDbIT extends MergeCase {
+
+ public void test() throws Exception {
+ DbEntity dbEntity = map.getDbEntity("PAINTING");
+ assertNotNull(dbEntity);
+
+ // create and add new column to model and db
+ DbAttribute column = new DbAttribute("NEWCOL2", Types.VARCHAR, dbEntity);
+
+ try {
+
+ column.setMandatory(true);
+ column.setMaxLength(10);
+ dbEntity.addAttribute(column);
+ assertTokensAndExecute(2, 0);
+
+ // check that is was merged
+ assertTokensAndExecute(0, 0);
+
+ // set null
+ column.setMandatory(false);
+
+ // merge to db
+ assertTokensAndExecute(1, 0);
+
+ // check that is was merged
+ assertTokensAndExecute(0, 0);
+
+ // clean up
+ }
+ finally {
+ dbEntity.removeAttribute(column.getName());
+ assertTokensAndExecute(1, 0);
+ assertTokensAndExecute(0, 0);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/merge/SetAllowNullToDbTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/merge/SetAllowNullToDbTest.java b/cayenne-server/src/test/java/org/apache/cayenne/merge/SetAllowNullToDbTest.java
deleted file mode 100644
index 61fc793..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/merge/SetAllowNullToDbTest.java
+++ /dev/null
@@ -1,66 +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.merge;
-
-import java.sql.Types;
-
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class SetAllowNullToDbTest extends MergeCase {
-
- public void test() throws Exception {
- DbEntity dbEntity = map.getDbEntity("PAINTING");
- assertNotNull(dbEntity);
-
- // create and add new column to model and db
- DbAttribute column = new DbAttribute("NEWCOL2", Types.VARCHAR, dbEntity);
-
- try {
-
- column.setMandatory(true);
- column.setMaxLength(10);
- dbEntity.addAttribute(column);
- assertTokensAndExecute(2, 0);
-
- // check that is was merged
- assertTokensAndExecute(0, 0);
-
- // set null
- column.setMandatory(false);
-
- // merge to db
- assertTokensAndExecute(1, 0);
-
- // check that is was merged
- assertTokensAndExecute(0, 0);
-
- // clean up
- }
- finally {
- dbEntity.removeAttribute(column.getName());
- assertTokensAndExecute(1, 0);
- assertTokensAndExecute(0, 0);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/merge/SetNotNullToDbIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/merge/SetNotNullToDbIT.java b/cayenne-server/src/test/java/org/apache/cayenne/merge/SetNotNullToDbIT.java
new file mode 100644
index 0000000..28b134c
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/merge/SetNotNullToDbIT.java
@@ -0,0 +1,76 @@
+/*****************************************************************
+ * 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.merge;
+
+import java.sql.Types;
+
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class SetNotNullToDbIT extends MergeCase {
+
+ @Inject
+ private DBHelper dbHelper;
+
+ @Override
+ protected void setUpAfterInjection() throws Exception {
+ super.setUpAfterInjection();
+
+ // must cleanup the tables as changing NULL column to NOT NULL may require that no
+ // nullable data is stored in the column
+ dbHelper.deleteAll("PAINTING_INFO");
+ dbHelper.deleteAll("PAINTING");
+ }
+
+ public void test() throws Exception {
+ DbEntity dbEntity = map.getDbEntity("PAINTING");
+ assertNotNull(dbEntity);
+
+ // create and add new column to model and db
+ DbAttribute column = new DbAttribute("NEWCOL2", Types.VARCHAR, dbEntity);
+
+ column.setMandatory(false);
+ column.setMaxLength(10);
+ dbEntity.addAttribute(column);
+ assertTokensAndExecute(1, 0);
+
+ // check that is was merged
+ assertTokensAndExecute(0, 0);
+
+ // set not null
+ column.setMandatory(true);
+
+ // merge to db
+ assertTokensAndExecute(1, 0);
+
+ // check that is was merged
+ assertTokensAndExecute(0, 0);
+
+ // clean up
+ dbEntity.removeAttribute(column.getName());
+ assertTokensAndExecute(1, 0);
+ assertTokensAndExecute(0, 0);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/merge/SetNotNullToDbTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/merge/SetNotNullToDbTest.java b/cayenne-server/src/test/java/org/apache/cayenne/merge/SetNotNullToDbTest.java
deleted file mode 100644
index 04a086f..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/merge/SetNotNullToDbTest.java
+++ /dev/null
@@ -1,76 +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.merge;
-
-import java.sql.Types;
-
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.test.jdbc.DBHelper;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class SetNotNullToDbTest extends MergeCase {
-
- @Inject
- private DBHelper dbHelper;
-
- @Override
- protected void setUpAfterInjection() throws Exception {
- super.setUpAfterInjection();
-
- // must cleanup the tables as changing NULL column to NOT NULL may require that no
- // nullable data is stored in the column
- dbHelper.deleteAll("PAINTING_INFO");
- dbHelper.deleteAll("PAINTING");
- }
-
- public void test() throws Exception {
- DbEntity dbEntity = map.getDbEntity("PAINTING");
- assertNotNull(dbEntity);
-
- // create and add new column to model and db
- DbAttribute column = new DbAttribute("NEWCOL2", Types.VARCHAR, dbEntity);
-
- column.setMandatory(false);
- column.setMaxLength(10);
- dbEntity.addAttribute(column);
- assertTokensAndExecute(1, 0);
-
- // check that is was merged
- assertTokensAndExecute(0, 0);
-
- // set not null
- column.setMandatory(true);
-
- // merge to db
- assertTokensAndExecute(1, 0);
-
- // check that is was merged
- assertTokensAndExecute(0, 0);
-
- // clean up
- dbEntity.removeAttribute(column.getName());
- assertTokensAndExecute(1, 0);
- assertTokensAndExecute(0, 0);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/merge/SetPrimaryKeyToDbIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/merge/SetPrimaryKeyToDbIT.java b/cayenne-server/src/test/java/org/apache/cayenne/merge/SetPrimaryKeyToDbIT.java
new file mode 100644
index 0000000..9654046
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/merge/SetPrimaryKeyToDbIT.java
@@ -0,0 +1,59 @@
+/*****************************************************************
+ * 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.merge;
+
+import java.sql.Types;
+
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class SetPrimaryKeyToDbIT extends MergeCase {
+
+ public void test() throws Exception {
+ dropTableIfPresent("NEW_TABLE");
+ assertTokensAndExecute(0, 0);
+
+ DbEntity dbEntity1 = new DbEntity("NEW_TABLE");
+
+ DbAttribute e1col1 = new DbAttribute("ID1", Types.INTEGER, dbEntity1);
+ e1col1.setMandatory(true);
+ e1col1.setPrimaryKey(true);
+ dbEntity1.addAttribute(e1col1);
+ map.addDbEntity(dbEntity1);
+
+ assertTokensAndExecute(1, 0);
+ assertTokensAndExecute(0, 0);
+
+ DbAttribute e1col2 = new DbAttribute("ID2", Types.INTEGER, dbEntity1);
+ e1col2.setMandatory(true);
+ dbEntity1.addAttribute(e1col2);
+
+ assertTokensAndExecute(2, 0);
+ assertTokensAndExecute(0, 0);
+
+ e1col1.setPrimaryKey(false);
+ e1col2.setPrimaryKey(true);
+
+ assertTokensAndExecute(1, 0);
+ assertTokensAndExecute(0, 0);
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/merge/SetPrimaryKeyToDbTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/merge/SetPrimaryKeyToDbTest.java b/cayenne-server/src/test/java/org/apache/cayenne/merge/SetPrimaryKeyToDbTest.java
deleted file mode 100644
index b9a4ac4..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/merge/SetPrimaryKeyToDbTest.java
+++ /dev/null
@@ -1,59 +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.merge;
-
-import java.sql.Types;
-
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class SetPrimaryKeyToDbTest extends MergeCase {
-
- public void test() throws Exception {
- dropTableIfPresent("NEW_TABLE");
- assertTokensAndExecute(0, 0);
-
- DbEntity dbEntity1 = new DbEntity("NEW_TABLE");
-
- DbAttribute e1col1 = new DbAttribute("ID1", Types.INTEGER, dbEntity1);
- e1col1.setMandatory(true);
- e1col1.setPrimaryKey(true);
- dbEntity1.addAttribute(e1col1);
- map.addDbEntity(dbEntity1);
-
- assertTokensAndExecute(1, 0);
- assertTokensAndExecute(0, 0);
-
- DbAttribute e1col2 = new DbAttribute("ID2", Types.INTEGER, dbEntity1);
- e1col2.setMandatory(true);
- dbEntity1.addAttribute(e1col2);
-
- assertTokensAndExecute(2, 0);
- assertTokensAndExecute(0, 0);
-
- e1col1.setPrimaryKey(false);
- e1col2.setPrimaryKey(true);
-
- assertTokensAndExecute(1, 0);
- assertTokensAndExecute(0, 0);
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/merge/ValueForNullIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/merge/ValueForNullIT.java b/cayenne-server/src/test/java/org/apache/cayenne/merge/ValueForNullIT.java
new file mode 100644
index 0000000..abcef98
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/merge/ValueForNullIT.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.merge;
+
+import junit.framework.AssertionFailedError;
+import org.apache.cayenne.DataObject;
+import org.apache.cayenne.Persistent;
+import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.access.jdbc.ParameterBinding;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.ExpressionFactory;
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.ObjAttribute;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.query.SelectQuery;
+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 ValueForNullIT extends MergeCase {
+
+ private static final String DEFAULT_VALUE_STRING = "DEFSTRING";
+
+ @Inject
+ private DataContext context;
+
+ public void test() throws Exception {
+ DbEntity dbEntity = map.getDbEntity("PAINTING");
+ assertNotNull(dbEntity);
+ ObjEntity objEntity = map.getObjEntity("Painting");
+ assertNotNull(objEntity);
+
+ // insert some rows before adding "not null" column
+ final int nrows = 10;
+ for (int i = 0; i < nrows; i++) {
+ DataObject o = (DataObject) context.newObject("Painting");
+ o.writeProperty("paintingTitle", "ptitle" + i);
+ }
+ context.commitChanges();
+
+ // create and add new column to model and db
+ DbAttribute column = new DbAttribute("NEWCOL2", Types.VARCHAR, dbEntity);
+
+ column.setMandatory(false);
+ column.setMaxLength(10);
+ dbEntity.addAttribute(column);
+ assertTrue(dbEntity.getAttributes().contains(column));
+ assertEquals(column, dbEntity.getAttribute(column.getName()));
+ assertTokensAndExecute(1, 0);
+
+ // need obj attr to be able to query
+ ObjAttribute objAttr = new ObjAttribute("newcol2");
+ objAttr.setDbAttributePath(column.getName());
+ objEntity.addAttribute(objAttr);
+
+ // check that is was merged
+ assertTokensAndExecute(0, 0);
+
+ // set not null
+ column.setMandatory(true);
+
+ // merge to db
+ assertTokensAndExecute(2, 0);
+
+ // check that is was merged
+ assertTokensAndExecute(0, 0);
+
+ // check values for null
+ Expression qual = ExpressionFactory.matchExp(
+ objAttr.getName(),
+ DEFAULT_VALUE_STRING);
+ SelectQuery query = new SelectQuery("Painting", qual);
+ List<Persistent> rows = context.performQuery(query);
+ assertEquals(nrows, rows.size());
+
+ // clean up
+ dbEntity.removeAttribute(column.getName());
+ assertTokensAndExecute(1, 0);
+ assertTokensAndExecute(0, 0);
+ }
+
+ @Override
+ protected DbMerger createMerger(MergerFactory mergerFactory, final ValueForNullProvider valueForNullProvider) {
+ return super.createMerger(mergerFactory, new DefaultValueForNullProvider() {
+
+ @Override
+ protected ParameterBinding get(DbEntity entity, DbAttribute column) {
+ int type = column.getType();
+ switch (type) {
+ case Types.VARCHAR:
+ return new ParameterBinding(DEFAULT_VALUE_STRING, type, -1);
+ default:
+ throw new AssertionFailedError("should not get here");
+ }
+ }
+
+ @Override
+ public boolean hasValueFor(DbEntity entity, DbAttribute column) {
+ return true;
+ }
+
+ });
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/merge/ValueForNullTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/merge/ValueForNullTest.java b/cayenne-server/src/test/java/org/apache/cayenne/merge/ValueForNullTest.java
deleted file mode 100644
index db6009a..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/merge/ValueForNullTest.java
+++ /dev/null
@@ -1,127 +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.merge;
-
-import java.sql.Types;
-import java.util.List;
-
-import junit.framework.AssertionFailedError;
-
-import org.apache.cayenne.DataObject;
-import org.apache.cayenne.Persistent;
-import org.apache.cayenne.access.DataContext;
-import org.apache.cayenne.access.jdbc.ParameterBinding;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.exp.Expression;
-import org.apache.cayenne.exp.ExpressionFactory;
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.ObjAttribute;
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class ValueForNullTest extends MergeCase {
-
- private static final String DEFAULT_VALUE_STRING = "DEFSTRING";
-
- @Inject
- private DataContext context;
-
- public void test() throws Exception {
- DbEntity dbEntity = map.getDbEntity("PAINTING");
- assertNotNull(dbEntity);
- ObjEntity objEntity = map.getObjEntity("Painting");
- assertNotNull(objEntity);
-
- // insert some rows before adding "not null" column
- final int nrows = 10;
- for (int i = 0; i < nrows; i++) {
- DataObject o = (DataObject) context.newObject("Painting");
- o.writeProperty("paintingTitle", "ptitle" + i);
- }
- context.commitChanges();
-
- // create and add new column to model and db
- DbAttribute column = new DbAttribute("NEWCOL2", Types.VARCHAR, dbEntity);
-
- column.setMandatory(false);
- column.setMaxLength(10);
- dbEntity.addAttribute(column);
- assertTrue(dbEntity.getAttributes().contains(column));
- assertEquals(column, dbEntity.getAttribute(column.getName()));
- assertTokensAndExecute(1, 0);
-
- // need obj attr to be able to query
- ObjAttribute objAttr = new ObjAttribute("newcol2");
- objAttr.setDbAttributePath(column.getName());
- objEntity.addAttribute(objAttr);
-
- // check that is was merged
- assertTokensAndExecute(0, 0);
-
- // set not null
- column.setMandatory(true);
-
- // merge to db
- assertTokensAndExecute(2, 0);
-
- // check that is was merged
- assertTokensAndExecute(0, 0);
-
- // check values for null
- Expression qual = ExpressionFactory.matchExp(
- objAttr.getName(),
- DEFAULT_VALUE_STRING);
- SelectQuery query = new SelectQuery("Painting", qual);
- List<Persistent> rows = context.performQuery(query);
- assertEquals(nrows, rows.size());
-
- // clean up
- dbEntity.removeAttribute(column.getName());
- assertTokensAndExecute(1, 0);
- assertTokensAndExecute(0, 0);
- }
-
- @Override
- protected DbMerger createMerger(MergerFactory mergerFactory, final ValueForNullProvider valueForNullProvider) {
- return super.createMerger(mergerFactory, new DefaultValueForNullProvider() {
-
- @Override
- protected ParameterBinding get(DbEntity entity, DbAttribute column) {
- int type = column.getType();
- switch (type) {
- case Types.VARCHAR:
- return new ParameterBinding(DEFAULT_VALUE_STRING, type, -1);
- default:
- throw new AssertionFailedError("should not get here");
- }
- }
-
- @Override
- public boolean hasValueFor(DbEntity entity, DbAttribute column) {
- return true;
- }
-
- });
- }
-
-}