db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r398681 [3/3] - in /db/ddlutils/trunk/src: java/org/apache/ddlutils/alteration/ java/org/apache/ddlutils/model/ java/org/apache/ddlutils/platform/ java/org/apache/ddlutils/util/ test/org/apache/ddlutils/ test/org/apache/ddlutils/alteration/...
Date Mon, 01 May 2006 20:39:30 GMT
Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestModelComparator.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestModelComparator.java?rev=398681&r1=398680&r2=398681&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestModelComparator.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestModelComparator.java Mon
May  1 13:39:28 2006
@@ -16,39 +16,20 @@
  * limitations under the License.
  */
 
-import java.io.StringReader;
 import java.sql.Types;
 import java.util.List;
 
-import org.apache.ddlutils.io.DatabaseIO;
+import org.apache.ddlutils.TestBase;
 import org.apache.ddlutils.model.Database;
 
-import junit.framework.TestCase;
-
 /**
  * Tests the model comparison.
  * 
  * @version $Revision: $
  */
-public class TestModelComparator extends TestCase
+public class TestModelComparator extends TestBase
 {
     /**
-     * Parses the database defined in the given XML definition.
-     * 
-     * @param dbDef
-     *            The database XML definition
-     * @return The database model
-     */
-    private Database parseDatabaseFromString(String dbDef)
-    {
-        DatabaseIO dbIO = new DatabaseIO();
-        
-        dbIO.setUseInternalDtd(true);
-        dbIO.setValidateXml(false);
-        return dbIO.read(new StringReader(dbDef));
-    }
-
-    /**
      * Tests the addition of a table.
      */
     public void testAddTable()
@@ -198,6 +179,60 @@
 
         assertEquals("TESTFK",
                      change.getNewForeignKey().getName());
+    }
+
+    /**
+     * Tests the addition of two tables with foreign keys to each other .
+     */
+    public void testAddTablesWithForeignKeys()
+    {
+        final String MODEL1 = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+            "<database name='test'>\n" +
+            "</database>";
+        final String MODEL2 = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+            "<database name='test'>\n" +
+            "  <table name='TABLEA'>\n" +
+            "    <column name='COLPK' type='INTEGER' primaryKey='true' required='true'/>\n"
+
+            "    <column name='COLFK' type='INTEGER'/>\n" +
+            "    <foreign-key name='TESTFKB' foreignTable='TABLEB'>\n" +
+            "      <reference local='COLFK' foreign='COLPK'/>\n" +
+            "    </foreign-key>\n" +
+            "  </table>\n" +
+            "  <table name='TABLEB'>\n" +
+            "    <column name='COLPK' type='INTEGER' primaryKey='true' required='true'/>\n"
+
+            "    <column name='COLFK' type='INTEGER'/>\n" +
+            "    <foreign-key name='TESTFKA' foreignTable='TABLEA'>\n" +
+            "      <reference local='COLFK' foreign='COLPK'/>\n" +
+            "    </foreign-key>\n" +
+            "  </table>\n" +
+            "</database>";
+
+        Database model1  = parseDatabaseFromString(MODEL1);
+        Database model2  = parseDatabaseFromString(MODEL2);
+        List     changes = new ModelComparator(false).compare(model1, model2);
+
+        assertEquals(4,
+                     changes.size());
+
+        AddTableChange      tableChange1 = (AddTableChange)changes.get(0);
+        AddForeignKeyChange fkChange1    = (AddForeignKeyChange)changes.get(1);
+        AddTableChange      tableChange2 = (AddTableChange)changes.get(2);
+        AddForeignKeyChange fkChange2    = (AddForeignKeyChange)changes.get(3);
+
+        assertEquals("TABLEA",
+                     tableChange1.getNewTable().getName());
+        assertEquals("TABLEB",
+                     tableChange2.getNewTable().getName());
+        assertEquals("TESTFKB",
+                     fkChange1.getNewForeignKey().getName());
+        assertEquals("TABLEA",
+                     fkChange1.getChangedTable().getName());
+        assertEquals("TESTFKA",
+                     fkChange2.getNewForeignKey().getName());
+        assertEquals("TABLEB",
+                     fkChange2.getChangedTable().getName());
     }
 
     /**

Added: db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestPlatform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestPlatform.java?rev=398681&view=auto
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestPlatform.java (added)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestPlatform.java Mon May  1 13:39:28
2006
@@ -0,0 +1,42 @@
+package org.apache.ddlutils.platform;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed 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.
+ */
+
+
+/**
+ * Platform implementation that makes the base functionality available without
+ * overriding anything.
+ * 
+ * @version $Revision: $
+ */
+public class TestPlatform extends PlatformImplBase
+{
+    /**
+     * Creates a new test platform instance.
+     */
+    public TestPlatform()
+    {
+        setSqlBuilder(new SqlBuilder(this) {});
+    }
+    /**
+     * {@inheritDoc}
+     */
+    public String getName()
+    {
+        return "TestPlatform";
+    }
+}

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestPlatformImplBase.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestPlatformImplBase.java?rev=398681&r1=398680&r2=398681&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestPlatformImplBase.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestPlatformImplBase.java Mon
May  1 13:39:28 2006
@@ -56,7 +56,7 @@
     public void testToColumnValues()
     {
         Database         database = parseDatabaseFromString(TESTED_MODEL);
-        PlatformImplBase platform = new PlatformBase();
+        PlatformImplBase platform = new TestPlatform();
         Table            table    = database.getTable(0);
         SqlDynaClass     clz      = SqlDynaClass.newInstance(table);
         DynaBean         db       = new SqlDynaBean(SqlDynaClass.newInstance(table));
@@ -68,20 +68,6 @@
         assertEquals("name",
                      map.get("name"));
         assertTrue(map.containsKey("id"));
-    }
-    
-    /**
-     * The tested platform.
-     */
-    public class PlatformBase extends PlatformImplBase 
-    {
-        /**
-         * {@inheritDoc}
-         */
-        public String getName() 
-        {
-            return null;
-        }
     }
 
     /**



Mime
View raw message