cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r657413 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/merge: MergeCase.java MergerFactoryTest.java
Date Sat, 17 May 2008 18:17:50 GMT
Author: aadamchik
Date: Sat May 17 11:17:50 2008
New Revision: 657413

URL: http://svn.apache.org/viewvc?rev=657413&view=rev
Log:
another shot at preventing failing merge cases from affecting the downstream tests... this
time using a clone of the main DataMap to modify the schema

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/merge/MergeCase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/merge/MergerFactoryTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/merge/MergeCase.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/merge/MergeCase.java?rev=657413&r1=657412&r2=657413&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/merge/MergeCase.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/merge/MergeCase.java
Sat May 17 11:17:50 2008
@@ -18,6 +18,9 @@
  ****************************************************************/
 package org.apache.cayenne.merge;
 
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.sql.Statement;
@@ -32,9 +35,12 @@
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.map.MapLoader;
 import org.apache.cayenne.unit.CayenneCase;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.xml.sax.InputSource;
 
 public class MergeCase extends CayenneCase {
 
@@ -58,22 +64,36 @@
             }
         };
     }
-    
+
     protected List<MergerToken> createMergeTokens() {
         return createMerger().createMergeTokens(node, map);
     }
 
+    protected DataMap createDataMap() {
+        // clone DataMap by saving and loading from XML as to avoid modifying shared test
+        // DataMap
+        DataMap originalMap = getDomain().getMap("testmap");
+        StringWriter out = new StringWriter();
+        PrintWriter outWriter = new PrintWriter(out);
+        originalMap.encodeAsXML(outWriter);
+        outWriter.flush();
+        StringReader in = new StringReader(out.toString());
+        DataMap map = new MapLoader().loadDataMap(new InputSource(in));
+
+        // map must operate in an EntityResolve namespace...
+        EntityResolver testResolver = new EntityResolver();
+        testResolver.addDataMap(map);
+        return map;
+    }
+
     @Override
     protected void setUp() throws Exception {
         super.setUp();
 
-        // getAccessStack().dropSchema();
-        // getAccessStack().dropPKSupport();
-
         deleteTestData();
         createTestData("testArtists");
         node = getDomain().getDataNodes().iterator().next();
-        map = getDomain().getMap("testmap");
+        map = createDataMap();
 
         filterDataMap(node, map);
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/merge/MergerFactoryTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/merge/MergerFactoryTest.java?rev=657413&r1=657412&r2=657413&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/merge/MergerFactoryTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/merge/MergerFactoryTest.java
Sat May 17 11:17:50 2008
@@ -22,6 +22,7 @@
 
 import org.apache.cayenne.CayenneDataObject;
 import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbJoin;
@@ -38,23 +39,18 @@
         // create and add new column to model and db
         DbAttribute column = new DbAttribute("NEWCOL1", Types.VARCHAR, dbEntity);
 
-        try {
-            column.setMandatory(false);
-            column.setMaxLength(10);
-            dbEntity.addAttribute(column);
-            assertTokensAndExecute(node, map, 1, 0);
+        column.setMandatory(false);
+        column.setMaxLength(10);
+        dbEntity.addAttribute(column);
+        assertTokensAndExecute(node, map, 1, 0);
 
-            // try merge once more to check that is was merged
-            assertTokensAndExecute(node, map, 0, 0);
+        // try merge once more to check that is was merged
+        assertTokensAndExecute(node, map, 0, 0);
 
-            // remove it from model and db
-            dbEntity.removeAttribute(column.getName());
-            assertTokensAndExecute(node, map, 1, 0);
-            assertTokensAndExecute(node, map, 0, 0);
-        }
-        finally {
-            dbEntity.removeAttribute(column.getName());
-        }
+        // remove it from model and db
+        dbEntity.removeAttribute(column.getName());
+        assertTokensAndExecute(node, map, 1, 0);
+        assertTokensAndExecute(node, map, 0, 0);
     }
 
     public void testChangeVarcharSizeToDb() throws Exception {
@@ -64,32 +60,27 @@
         // create and add new column to model and db
         DbAttribute column = new DbAttribute("NEWCOL2", Types.VARCHAR, dbEntity);
 
-        try {
-            column.setMandatory(false);
-            column.setMaxLength(10);
-            dbEntity.addAttribute(column);
-            assertTokensAndExecute(node, map, 1, 0);
+        column.setMandatory(false);
+        column.setMaxLength(10);
+        dbEntity.addAttribute(column);
+        assertTokensAndExecute(node, map, 1, 0);
 
-            // check that is was merged
-            assertTokensAndExecute(node, map, 0, 0);
+        // check that is was merged
+        assertTokensAndExecute(node, map, 0, 0);
 
-            // change size
-            column.setMaxLength(20);
+        // change size
+        column.setMaxLength(20);
 
-            // merge to db
-            assertTokensAndExecute(node, map, 1, 0);
+        // merge to db
+        assertTokensAndExecute(node, map, 1, 0);
 
-            // check that is was merged
-            assertTokensAndExecute(node, map, 0, 0);
+        // check that is was merged
+        assertTokensAndExecute(node, map, 0, 0);
 
-            // clean up
-            dbEntity.removeAttribute(column.getName());
-            assertTokensAndExecute(node, map, 1, 0);
-            assertTokensAndExecute(node, map, 0, 0);
-        }
-        finally {
-            dbEntity.removeAttribute(column.getName());
-        }
+        // clean up
+        dbEntity.removeAttribute(column.getName());
+        assertTokensAndExecute(node, map, 1, 0);
+        assertTokensAndExecute(node, map, 0, 0);
     }
 
     public void testMultipleTokensToDb() throws Exception {
@@ -105,32 +96,26 @@
         column2.setMaxLength(10);
         dbEntity.addAttribute(column2);
 
-        try {
-            assertTokensAndExecute(node, map, 2, 0);
+        assertTokensAndExecute(node, map, 2, 0);
 
-            // check that is was merged
-            assertTokensAndExecute(node, map, 0, 0);
+        // check that is was merged
+        assertTokensAndExecute(node, map, 0, 0);
 
-            // change size
-            column1.setMaxLength(20);
-            column2.setMaxLength(30);
+        // change size
+        column1.setMaxLength(20);
+        column2.setMaxLength(30);
 
-            // merge to db
-            assertTokensAndExecute(node, map, 2, 0);
+        // merge to db
+        assertTokensAndExecute(node, map, 2, 0);
 
-            // check that is was merged
-            assertTokensAndExecute(node, map, 0, 0);
+        // check that is was merged
+        assertTokensAndExecute(node, map, 0, 0);
 
-            // clean up
-            dbEntity.removeAttribute(column1.getName());
-            dbEntity.removeAttribute(column2.getName());
-            assertTokensAndExecute(node, map, 2, 0);
-            assertTokensAndExecute(node, map, 0, 0);
-        }
-        finally {
-            dbEntity.removeAttribute(column1.getName());
-            dbEntity.removeAttribute(column2.getName());
-        }
+        // clean up
+        dbEntity.removeAttribute(column1.getName());
+        dbEntity.removeAttribute(column2.getName());
+        assertTokensAndExecute(node, map, 2, 0);
+        assertTokensAndExecute(node, map, 0, 0);
     }
 
     public void testAddTableToDb() throws Exception {
@@ -152,43 +137,47 @@
 
         map.addDbEntity(dbEntity);
 
-        try {
+        assertTokensAndExecute(node, map, 1, 0);
+        assertTokensAndExecute(node, map, 0, 0);
 
-            assertTokensAndExecute(node, map, 1, 0);
-            assertTokensAndExecute(node, map, 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);
+
+        // try to insert some rows to check that pk stuff is working
+        DataContext ctxt = createDataContext();
+        DataMap sourceMap = ctxt.getEntityResolver().getDataMap("testmap");
 
-            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);
+        try {
+            sourceMap.addDbEntity(dbEntity);
+            sourceMap.addObjEntity(objEntity);
 
-            // try to insert some rows to check that pk stuff is working
-            DataContext ctxt = createDataContext();
             for (int i = 0; i < 5; i++) {
                 CayenneDataObject dao = (CayenneDataObject) ctxt.newObject(objEntity
                         .getName());
                 dao.writeProperty(oatr1.getName(), "test " + i);
             }
             ctxt.commitChanges();
-
-            // clear up
-            map.removeObjEntity(objEntity.getName(), true);
-            map.removeDbEntity(dbEntity.getName(), true);
-            ctxt.getEntityResolver().clearCache();
-            assertNull(map.getObjEntity(objEntity.getName()));
-            assertNull(map.getDbEntity(dbEntity.getName()));
-            assertFalse(map.getDbEntities().contains(dbEntity));
-
-            assertTokensAndExecute(node, map, 1, 0);
-            assertTokensAndExecute(node, map, 0, 0);
         }
         finally {
-            map.removeObjEntity("NewTable", true);
-            map.removeDbEntity(dbEntity.getName(), true);
+            sourceMap.removeObjEntity(objEntity.getName(), true);
+            sourceMap.removeDbEntity(dbEntity.getName(), true);
         }
+
+        // clear up
+        map.removeObjEntity(objEntity.getName(), true);
+        map.removeDbEntity(dbEntity.getName(), true);
+        ctxt.getEntityResolver().clearCache();
+        assertNull(map.getObjEntity(objEntity.getName()));
+        assertNull(map.getDbEntity(dbEntity.getName()));
+        assertFalse(map.getDbEntities().contains(dbEntity));
+
+        assertTokensAndExecute(node, map, 1, 0);
+        assertTokensAndExecute(node, map, 0, 0);
     }
 
     public void testAddForeignKeyWithTable() throws Exception {
@@ -260,6 +249,7 @@
         }
         finally {
             artistDbEntity.removeRelationship("toNewTableR2");
+            map.removeDbEntity(dbEntity.getName(), true);
         }
     }
 
@@ -335,6 +325,7 @@
         finally {
             artistDbEntity.removeRelationship("toArtistR1");
             artistDbEntity.removeRelationship("toNewTableR2");
+            map.removeDbEntity(dbEntity.getName(), true);
         }
     }
 



Mime
View raw message