db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r602807 [10/15] - in /db/ddlutils/trunk: ./ src/java/org/apache/ddlutils/ src/java/org/apache/ddlutils/alteration/ src/java/org/apache/ddlutils/model/ src/java/org/apache/ddlutils/platform/ src/java/org/apache/ddlutils/platform/axion/ src/j...
Date Mon, 10 Dec 2007 08:21:39 GMT
Copied: db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestModelComparison.java (from r581500, db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestModelComparator.java)
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestModelComparison.java?p2=db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestModelComparison.java&p1=db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestModelComparator.java&r1=581500&r2=602807&rev=602807&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestModelComparator.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestModelComparison.java Mon Dec 10 00:20:47 2007
@@ -22,36 +22,16 @@
 import java.sql.Types;
 import java.util.List;
 
-import org.apache.ddlutils.PlatformInfo;
-import org.apache.ddlutils.TestBase;
 import org.apache.ddlutils.model.Database;
-import org.apache.ddlutils.model.Table;
 
 /**
- * Tests the model comparison.
+ * Tests the comparison on the model level.
  * 
  * @version $Revision: $
  */
-public class TestModelComparator extends TestBase
+public class TestModelComparison extends TestComparisonBase
 {
     /**
-     * Creates a new model comparator.
-     *
-     * @param caseSensitive Whether the comparison is case sensitive 
-     * @return The model comparator
-     */
-    protected ModelComparator createModelComparator(boolean caseSensitive)
-    {
-        PlatformInfo platformInfo = new PlatformInfo();
-
-        platformInfo.setHasSize(Types.DECIMAL, true);
-        platformInfo.setHasSize(Types.NUMERIC, true);
-        platformInfo.setHasSize(Types.CHAR, true);
-        platformInfo.setHasSize(Types.VARCHAR, true);
-        return new ModelComparator(platformInfo, caseSensitive);
-    }
-
-    /**
      * Tests the addition of a table.
      */
     public void testAddTable()
@@ -76,21 +56,23 @@
 
         Database model1  = parseDatabaseFromString(MODEL1);
         Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(false).compare(model1, model2);
+        List     changes = getPlatform(false).getChanges(model1, model2);
 
         assertEquals(1,
                      changes.size());
 
         AddTableChange change = (AddTableChange)changes.get(0);
 
-        assertEquals("TABLEB",
-                     change.getNewTable().getName());
+        assertTable("TABLEB", null, 1, 0, 0,
+                    change.getNewTable());
+        assertColumn("COLPK", Types.INTEGER, null, null, true, true, false,
+                     change.getNewTable().getColumn(0));
     }
 
     /**
-     * Tests the removal of a table.
+     * Tests the addition of a table with an index.
      */
-    public void testRemoveTable()
+    public void testAddTableWithIndex()
     {
         final String MODEL1 = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
@@ -98,81 +80,52 @@
             "  <table name='TableA'>\n" +
             "    <column name='ColPK' type='INTEGER' primaryKey='true' required='true'/>\n" +
             "  </table>\n" +
-            "  <table name='TableB'>\n" +
-            "    <column name='COLPK' type='INTEGER' primaryKey='true' required='true'/>\n" +
-            "  </table>\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" +
+            "  </table>\n" +
             "  <table name='TABLEB'>\n" +
             "    <column name='COLPK' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='COLA' type='DOUBLE'/>\n" +
+            "    <index name='TestIndex'>\n" +
+            "      <index-column name='COLA'/>\n" +
+            "    </index>\n" +
             "  </table>\n" +
             "</database>";
 
         Database model1  = parseDatabaseFromString(MODEL1);
         Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(false).compare(model1, model2);
+        List     changes = getPlatform(false).getChanges(model1, model2);
 
         assertEquals(1,
                      changes.size());
 
-        RemoveTableChange change = (RemoveTableChange)changes.get(0);
+        AddTableChange change = (AddTableChange)changes.get(0);
 
-        assertEquals("TableA",
-                     change.getChangedTable().getName());
+        assertTable("TABLEB", null, 2, 0, 1, 
+                     change.getNewTable());
+        assertColumn("COLPK", Types.INTEGER, null, null, true, true, false,
+                     change.getNewTable().getColumn(0));
+        assertColumn("COLA", Types.DOUBLE, null, null, false, false, false,
+                     change.getNewTable().getColumn(1));
+        assertIndex("TestIndex", false, new String[] { "COLA" },
+                     change.getNewTable().getIndex(0));
     }
 
     /**
-     * Tests the addition and removal of a table.
+     * Tests the addition of a table and a foreign key to it.
      */
-    public void testAddAndRemoveTable()
+    public void testAddTableAndForeignKeyToIt()
     {
         final String MODEL1 = 
             "<?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" +
-            "  </table>\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" +
-            "  </table>\n" +
-            "</database>";
-
-        Database model1  = parseDatabaseFromString(MODEL1);
-        Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(true).compare(model1, model2);
-
-        assertEquals(2,
-                     changes.size());
-
-        AddTableChange    change1 = (AddTableChange)changes.get(0);
-        RemoveTableChange change2 = (RemoveTableChange)changes.get(1);
-
-        assertEquals("TABLEA",
-                     change1.getNewTable().getName());
-        assertEquals("TableA",
-                     change2.getChangedTable().getName());
-    }
-
-    /**
-     * Tests the addition of a foreign key.
-     */
-    public void testAddForeignKey()
-    {
-        final String MODEL1 = 
-            "<?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" +
-            "  </table>\n" +
-            "  <table name='TableB'>\n" +
-            "    <column name='ColPK' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='COLFK' type='INTEGER'/>\n" +
             "  </table>\n" +
             "</database>";
         final String MODEL2 = 
@@ -181,7 +134,7 @@
             "  <table name='TABLEA'>\n" +
             "    <column name='COLPK' type='INTEGER' primaryKey='true' required='true'/>\n" +
             "    <column name='COLFK' type='INTEGER'/>\n" +
-            "    <foreign-key name='TESTFK' foreignTable='TABLEB'>\n" +
+            "    <foreign-key name='TESTFKB' foreignTable='TABLEB'>\n" +
             "      <reference local='COLFK' foreign='COLPK'/>\n" +
             "    </foreign-key>\n" +
             "  </table>\n" +
@@ -192,15 +145,23 @@
 
         Database model1  = parseDatabaseFromString(MODEL1);
         Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(false).compare(model1, model2);
+        List     changes = getPlatform(false).getChanges(model1, model2);
 
-        assertEquals(1,
+        assertEquals(2,
                      changes.size());
 
-        AddForeignKeyChange change = (AddForeignKeyChange)changes.get(0);
+        AddTableChange      tableChange = (AddTableChange)changes.get(0);
+        AddForeignKeyChange fkChange    = (AddForeignKeyChange)changes.get(1);
 
-        assertEquals("TESTFK",
-                     change.getNewForeignKey().getName());
+        assertTable("TABLEB", null, 1, 0, 0, 
+                    tableChange.getNewTable());
+        assertColumn("COLPK", Types.INTEGER, null, null, true, true, false,
+                     tableChange.getNewTable().getColumn(0));
+
+        assertEquals("TABLEA",
+                     fkChange.getChangedTable());
+        assertForeignKey("TESTFKB", "TABLEB", new String[] { "COLFK" }, new String[] { "COLPK" }, 
+                         fkChange.getNewForeignKey());
     }
 
     /**
@@ -233,34 +194,45 @@
 
         Database model1  = parseDatabaseFromString(MODEL1);
         Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(false).compare(model1, model2);
+        List     changes = getPlatform(false).getChanges(model1, model2);
 
         assertEquals(4,
                      changes.size());
 
         AddTableChange      tableChange1 = (AddTableChange)changes.get(0);
-        AddForeignKeyChange fkChange1    = (AddForeignKeyChange)changes.get(1);
-        AddTableChange      tableChange2 = (AddTableChange)changes.get(2);
+        AddTableChange      tableChange2 = (AddTableChange)changes.get(1);
+        AddForeignKeyChange fkChange1    = (AddForeignKeyChange)changes.get(2);
         AddForeignKeyChange fkChange2    = (AddForeignKeyChange)changes.get(3);
 
+        assertTable("TABLEA", null, 2, 0, 0, 
+                    tableChange1.getNewTable());
+        assertColumn("COLPK", Types.INTEGER, null, null, true, true, false,
+                     tableChange1.getNewTable().getColumn(0));
+        assertColumn("COLFK", Types.INTEGER, null, null, false, false, false,
+                     tableChange1.getNewTable().getColumn(1));
+
+        assertTable("TABLEB", null, 2, 0, 0, 
+                    tableChange2.getNewTable());
+        assertColumn("COLPK", Types.INTEGER, null, null, true, true, false,
+                     tableChange2.getNewTable().getColumn(0));
+        assertColumn("COLFK", Types.INTEGER, null, null, false, false, false,
+                     tableChange2.getNewTable().getColumn(1));
+
         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());
+                     fkChange1.getChangedTable());
+        assertForeignKey("TESTFKB", "TABLEB", new String[] { "COLFK" }, new String[] { "COLPK" }, 
+                         fkChange1.getNewForeignKey());
+
         assertEquals("TABLEB",
-                     fkChange2.getChangedTable().getName());
+                     fkChange2.getChangedTable());
+        assertForeignKey("TESTFKA", "TABLEA", new String[] { "COLFK" }, new String[] { "COLPK" }, 
+                         fkChange2.getNewForeignKey());
     }
 
     /**
-     * Tests the removal of a foreign key.
+     * Tests the removal of a table.
      */
-    public void testRemoveForeignKey()
+    public void testDropTable()
     {
         final String MODEL1 = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
@@ -269,1043 +241,199 @@
             "    <column name='ColPK' type='INTEGER' primaryKey='true' required='true'/>\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='TestFK' foreignTable='TableA'>\n" +
-            "      <reference local='ColFK' foreign='ColPK'/>\n" +
-            "    </foreign-key>\n" +
+            "    <column name='COLPK' type='INTEGER' primaryKey='true' required='true'/>\n" +
             "  </table>\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" +
-            "  </table>\n" +
             "  <table name='TABLEB'>\n" +
             "    <column name='COLPK' type='INTEGER' primaryKey='true' required='true'/>\n" +
-            "    <column name='COLFK' type='INTEGER'/>\n" +
             "  </table>\n" +
             "</database>";
 
         Database model1  = parseDatabaseFromString(MODEL1);
         Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(false).compare(model1, model2);
+        List     changes = getPlatform(false).getChanges(model1, model2);
 
         assertEquals(1,
                      changes.size());
 
-        RemoveForeignKeyChange change = (RemoveForeignKeyChange)changes.get(0);
+        RemoveTableChange change = (RemoveTableChange)changes.get(0);
 
-        assertEquals("TestFK",
-                     change.getChangedForeignKey().getName());
+        assertEquals("TableA",
+                     change.getChangedTable());
     }
 
     /**
-     * Tests the addition and removal of a foreign key.
+     * Tests the removal of a table with an index.
      */
-    public void testAddAndRemoveForeignKey1()
+    public void testDropTableWithIndex()
     {
         final String MODEL1 = 
             "<?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='ColA' type='INTEGER'/>\n" +
+            "    <index name='TestIndex'>\n" +
+            "      <index-column name='ColA'/>\n" +
+            "    </index>\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='TestFK' foreignTable='TableA'>\n" +
-            "      <reference local='ColFK' foreign='ColPK'/>\n" +
-            "    </foreign-key>\n" +
+            "    <column name='COLPK' type='INTEGER' primaryKey='true' required='true'/>\n" +
             "  </table>\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" +
-            "  </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='TESTFK' foreignTable='TableA'>\n" +
-            "      <reference local='ColFK' foreign='ColPK'/>\n" +
-            "    </foreign-key>\n" +
+            "  <table name='TABLEB'>\n" +
+            "    <column name='COLPK' type='INTEGER' primaryKey='true' required='true'/>\n" +
             "  </table>\n" +
             "</database>";
 
         Database model1  = parseDatabaseFromString(MODEL1);
         Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(true).compare(model1, model2);
+        List     changes = getPlatform(false).getChanges(model1, model2);
 
-        assertEquals(2,
+        assertEquals(1,
                      changes.size());
 
-        RemoveForeignKeyChange change1 = (RemoveForeignKeyChange)changes.get(0);
-        AddForeignKeyChange    change2 = (AddForeignKeyChange)changes.get(1);
+        RemoveTableChange change = (RemoveTableChange)changes.get(0);
 
-        assertEquals("TestFK",
-                     change1.getChangedForeignKey().getName());
-        assertEquals("TESTFK",
-                     change2.getNewForeignKey().getName());
+        assertEquals("TableA",
+                     change.getChangedTable());
     }
 
     /**
-     * Tests the addition and removal of a foreign key because of a change of the references.
+     * Tests the removal of a table with a foreign key.
      */
-    public void testAddAndRemoveForeignKey2()
+    public void testDropTableWithForeignKey()
     {
         final String MODEL1 = 
             "<?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='ColFK1' type='INTEGER'/>\n" +
-            "    <column name='ColFK2' type='INTEGER'/>\n" +
-            "    <foreign-key name='TestFK' foreignTable='TableB'>\n" +
-            "      <reference local='ColFK1' foreign='ColPK1'/>\n" +
-            "      <reference local='ColFK2' foreign='ColPK2'/>\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='ColPK1' type='INTEGER' primaryKey='true' required='true'/>\n" +
-            "    <column name='ColPK2' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='COLPK' type='INTEGER' primaryKey='true' required='true'/>\n" +
             "  </table>\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='ColFK1' type='INTEGER'/>\n" +
-            "    <column name='ColFK2' type='INTEGER'/>\n" +
-            "    <foreign-key name='TestFK' foreignTable='TableB'>\n" +
-            "      <reference local='ColFK1' foreign='ColPK2'/>\n" +
-            "      <reference local='ColFK2' foreign='ColPK1'/>\n" +
-            "    </foreign-key>\n" +
-            "  </table>\n" +
-            "  <table name='TableB'>\n" +
-            "    <column name='ColPK1' type='INTEGER' primaryKey='true' required='true'/>\n" +
-            "    <column name='ColPK2' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "  <table name='TABLEB'>\n" +
+            "    <column name='COLPK' type='INTEGER' primaryKey='true' required='true'/>\n" +
             "  </table>\n" +
             "</database>";
 
         Database model1  = parseDatabaseFromString(MODEL1);
         Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(true).compare(model1, model2);
+        List     changes = getPlatform(false).getChanges(model1, model2);
 
         assertEquals(2,
                      changes.size());
 
-        RemoveForeignKeyChange change1 = (RemoveForeignKeyChange)changes.get(0);
-        AddForeignKeyChange    change2 = (AddForeignKeyChange)changes.get(1);
+        RemoveForeignKeyChange fkChange    = (RemoveForeignKeyChange)changes.get(0);
+        RemoveTableChange      tableChange = (RemoveTableChange)changes.get(1);
 
-        assertEquals("TestFK",
-                     change1.getChangedForeignKey().getName());
-        assertEquals("TestFK",
-                     change2.getNewForeignKey().getName());
-    }
+        assertEquals("TableA",
+                     fkChange.getChangedTable());
+        assertEquals(model1.findTable("TableA").getForeignKey(0),
+                     fkChange.findChangedForeignKey(model1, false));
 
+        assertEquals("TableA",
+                     tableChange.getChangedTable());
+    }
 
     /**
-     * Tests that the order of the references in a foreign key is not important.
+     * Tests the removal of a table and a foreign key to it.
      */
-    public void testForeignKeyReferenceOrder()
+    public void testDropTableAndForeignKeyToIt()
     {
         final String MODEL1 = 
             "<?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='ColFK1' type='INTEGER'/>\n" +
-            "    <column name='ColFK2' type='INTEGER'/>\n" +
-            "    <foreign-key name='TestFK' foreignTable='TableB'>\n" +
-            "      <reference local='ColFK1' foreign='ColPK1'/>\n" +
-            "      <reference local='ColFK2' foreign='ColPK2'/>\n" +
-            "    </foreign-key>\n" +
             "  </table>\n" +
             "  <table name='TableB'>\n" +
-            "    <column name='ColPK1' type='INTEGER' primaryKey='true' required='true'/>\n" +
-            "    <column name='ColPK2' type='INTEGER' primaryKey='true' required='true'/>\n" +
-            "  </table>\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='ColFK1' type='INTEGER'/>\n" +
-            "    <column name='ColFK2' type='INTEGER'/>\n" +
-            "    <foreign-key name='TestFK' foreignTable='TableB'>\n" +
-            "      <reference local='ColFK2' foreign='ColPK2'/>\n" +
-            "      <reference local='ColFK1' foreign='ColPK1'/>\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" +
-            "  <table name='TableB'>\n" +
-            "    <column name='ColPK1' type='INTEGER' primaryKey='true' required='true'/>\n" +
-            "    <column name='ColPK2' type='INTEGER' primaryKey='true' required='true'/>\n" +
-            "  </table>\n" +
-            "</database>";
-
-        Database model1  = parseDatabaseFromString(MODEL1);
-        Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(true).compare(model1, model2);
-
-        assertTrue(changes.isEmpty());
-    }
-
-    /**
-     * Tests the addition of an index.
-     */
-    public void testAddIndex()
-    {
-        final String MODEL1 = 
-            "<?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='Col' type='INTEGER'/>\n" +
-            "  </table>\n" +
             "</database>";
         final String MODEL2 = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
             "<database name='test'>\n" +
-            "  <table name='TABLEA'>\n" +
+            "  <table name='TABLEB'>\n" +
             "    <column name='COLPK' type='INTEGER' primaryKey='true' required='true'/>\n" +
-            "    <column name='COL' type='INTEGER'/>\n" +
-            "    <index name='TESTINDEX'>\n" +
-            "      <index-column name='COL'/>\n" +
-            "    </index>\n" +
-            "  </table>\n" +
-            "</database>";
-
-        Database model1  = parseDatabaseFromString(MODEL1);
-        Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(false).compare(model1, model2);
-
-        assertEquals(1,
-                     changes.size());
-
-        AddIndexChange change = (AddIndexChange)changes.get(0);
-
-        assertEquals("TESTINDEX",
-                     change.getNewIndex().getName());
-    }
-
-    /**
-     * Tests the removal of an index.
-     */
-    public void testRemoveIndex()
-    {
-        final String MODEL1 = 
-            "<?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='Col' type='INTEGER'/>\n" +
-            "    <unique name='TestIndex'>\n" +
-            "      <unique-column name='Col'/>\n" +
-            "    </unique>\n" +
-            "  </table>\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='Col' type='INTEGER'/>\n" +
-            "  </table>\n" +
-            "</database>";
-
-        Database model1  = parseDatabaseFromString(MODEL1);
-        Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(true).compare(model1, model2);
-
-        assertEquals(1,
-                     changes.size());
-
-        RemoveIndexChange change = (RemoveIndexChange)changes.get(0);
-
-        assertEquals("TestIndex",
-                     change.getChangedIndex().getName());
-    }
-
-    /**
-     * Tests the addition and removal of an index because of the change of type of the index.
-     */
-    public void testAddAndRemoveIndex()
-    {
-        final String MODEL1 = 
-            "<?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='Col' type='INTEGER'/>\n" +
-            "    <unique name='TestIndex'>\n" +
-            "      <unique-column name='Col'/>\n" +
-            "    </unique>\n" +
-            "  </table>\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='Col' type='INTEGER'/>\n" +
-            "    <index name='TestIndex'>\n" +
-            "      <index-column name='Col'/>\n" +
-            "    </index>\n" +
+            "    <column name='COLFK' type='INTEGER'/>\n" +
             "  </table>\n" +
             "</database>";
 
         Database model1  = parseDatabaseFromString(MODEL1);
         Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(true).compare(model1, model2);
+        List     changes = getPlatform(false).getChanges(model1, model2);
 
         assertEquals(2,
                      changes.size());
 
-        RemoveIndexChange change1 = (RemoveIndexChange)changes.get(0);
-        AddIndexChange    change2 = (AddIndexChange)changes.get(1);
-
-        assertEquals("TestIndex",
-                     change1.getChangedIndex().getName());
-        assertEquals("TestIndex",
-                     change2.getNewIndex().getName());
-    }
-
-    /**
-     * Tests the addition and removal of an index because of the change of column order.
-     */
-    public void testChangeIndexColumnOrder()
-    {
-        final String MODEL1 = 
-            "<?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='Col1' type='INTEGER'/>\n" +
-            "    <column name='Col2' type='DOUBLE'/>\n" +
-            "    <index name='TestIndex'>\n" +
-            "      <index-column name='Col1'/>\n" +
-            "      <index-column name='Col2'/>\n" +
-            "    </index>\n" +
-            "  </table>\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='Col1' type='INTEGER'/>\n" +
-            "    <column name='Col2' type='DOUBLE'/>\n" +
-            "    <index name='TestIndex'>\n" +
-            "      <index-column name='Col2'/>\n" +
-            "      <index-column name='Col1'/>\n" +
-            "    </index>\n" +
-            "  </table>\n" +
-            "</database>";
-
-        Database model1  = parseDatabaseFromString(MODEL1);
-        Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(false).compare(model1, model2);
-
-        assertEquals(2,
-                     changes.size());
+        RemoveForeignKeyChange fkChange    = (RemoveForeignKeyChange)changes.get(0);
+        RemoveTableChange      tableChange = (RemoveTableChange)changes.get(1);
 
-        RemoveIndexChange change1 = (RemoveIndexChange)changes.get(0);
-        AddIndexChange    change2 = (AddIndexChange)changes.get(1);
+        assertEquals("TableB",
+                     fkChange.getChangedTable());
+        assertEquals(model1.findTable("TableB").getForeignKey(0),
+                     fkChange.findChangedForeignKey(model1, false));
 
-        assertEquals("TestIndex",
-                     change1.getChangedIndex().getName());
-        assertEquals("TestIndex",
-                     change2.getNewIndex().getName());
+        assertEquals("TableA",
+                     tableChange.getChangedTable());
     }
 
     /**
-     * Tests the addition and removal of an index because of the addition of an index column.
+     * Tests the addition and removal of a table.
      */
-    public void testAddIndexColumn()
+    public void testAddAndDropTable()
     {
         final String MODEL1 = 
             "<?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='Col1' type='INTEGER'/>\n" +
-            "    <column name='Col2' type='DOUBLE'/>\n" +
-            "    <index name='TestIndex'>\n" +
-            "      <index-column name='Col1'/>\n" +
-            "    </index>\n" +
             "  </table>\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='Col1' type='INTEGER'/>\n" +
-            "    <column name='Col2' type='DOUBLE'/>\n" +
-            "    <index name='TestIndex'>\n" +
-            "      <index-column name='Col1'/>\n" +
-            "      <index-column name='Col2'/>\n" +
-            "    </index>\n" +
+            "  <table name='TABLEA'>\n" +
+            "    <column name='COLPK' type='INTEGER' primaryKey='true' required='true'/>\n" +
             "  </table>\n" +
             "</database>";
 
         Database model1  = parseDatabaseFromString(MODEL1);
         Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(false).compare(model1, model2);
+        List     changes = getPlatform(true).getChanges(model1, model2);
 
         assertEquals(2,
                      changes.size());
 
-        RemoveIndexChange change1 = (RemoveIndexChange)changes.get(0);
-        AddIndexChange    change2 = (AddIndexChange)changes.get(1);
-
-        assertEquals("TestIndex",
-                     change1.getChangedIndex().getName());
-        assertEquals("TestIndex",
-                     change2.getNewIndex().getName());
-    }
-
-    /**
-     * Tests the addition and removal of an index because of the removal of an index column.
-     */
-    public void testRemoveIndexColumn()
-    {
-        final String MODEL1 = 
-            "<?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='Col1' type='INTEGER'/>\n" +
-            "    <column name='Col2' type='DOUBLE'/>\n" +
-            "    <index name='TestIndex'>\n" +
-            "      <index-column name='Col1'/>\n" +
-            "      <index-column name='Col2'/>\n" +
-            "    </index>\n" +
-            "  </table>\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='Col1' type='INTEGER'/>\n" +
-            "    <column name='Col2' type='DOUBLE'/>\n" +
-            "    <index name='TestIndex'>\n" +
-            "      <index-column name='Col1'/>\n" +
-            "    </index>\n" +
-            "  </table>\n" +
-            "</database>";
+        RemoveTableChange change1 = (RemoveTableChange)changes.get(0);
+        AddTableChange    change2 = (AddTableChange)changes.get(1);
 
-        Database model1  = parseDatabaseFromString(MODEL1);
-        Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(false).compare(model1, model2);
-
-        assertEquals(2,
-                     changes.size());
-
-        RemoveIndexChange change1 = (RemoveIndexChange)changes.get(0);
-        AddIndexChange    change2 = (AddIndexChange)changes.get(1);
-
-        assertEquals("TestIndex",
-                     change1.getChangedIndex().getName());
-        assertEquals("TestIndex",
-                     change2.getNewIndex().getName());
-    }
-
-    /**
-     * Tests the addition of a primary key.
-     */
-    public void testAddPrimaryKey()
-    {
-        final String MODEL1 = 
-            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
-            "<database name='test'>\n" +
-            "  <table name='TableA'>\n" +
-            "    <column name='ColPK' type='INTEGER' required='true'/>\n" +
-            "  </table>\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" +
-            "  </table>\n" +
-            "</database>";
-
-        Database model1  = parseDatabaseFromString(MODEL1);
-        Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(false).compare(model1, model2);
-
-        assertEquals(1,
-                     changes.size());
-
-        AddPrimaryKeyChange change = (AddPrimaryKeyChange)changes.get(0);
-
-        assertEquals(1,
-                     change.getPrimaryKeyColumns().length);
-        assertEquals("ColPK",
-                     change.getPrimaryKeyColumns()[0].getName());
-    }
-
-    /**
-     * Tests the removal of a primary key.
-     */
-    public void testRemovePrimaryKey()
-    {
-        final String MODEL1 = 
-            "<?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" +
-            "  </table>\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' required='true'/>\n" +
-            "  </table>\n" +
-            "</database>";
-
-        Database model1  = parseDatabaseFromString(MODEL1);
-        Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(false).compare(model1, model2);
-
-        assertEquals(1,
-                     changes.size());
-
-        RemovePrimaryKeyChange change = (RemovePrimaryKeyChange)changes.get(0);
-
-        assertEquals(1,
-                     change.getPrimaryKeyColumns().length);
-        assertEquals("ColPK",
-                     change.getPrimaryKeyColumns()[0].getName());
-    }
-
-    /**
-     * Tests the addition of a column to the primary key.
-     */
-    public void testAddPrimaryKeyColumn()
-    {
-        final String MODEL1 = 
-            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
-            "<database name='test'>\n" +
-            "  <table name='TableA'>\n" +
-            "    <column name='ColPK1' type='INTEGER' primaryKey='true' required='true'/>\n" +
-            "    <column name='ColPK2' type='INTEGER' required='true'/>\n" +
-            "  </table>\n" +
-            "</database>";
-        final String MODEL2 = 
-            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
-            "<database name='test'>\n" +
-            "  <table name='TableA'>\n" +
-            "    <column name='ColPK1' type='INTEGER' primaryKey='true' required='true'/>\n" +
-            "    <column name='ColPK2' type='INTEGER' primaryKey='true' required='true'/>\n" +
-            "  </table>\n" +
-            "</database>";
-
-        Database model1  = parseDatabaseFromString(MODEL1);
-        Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(true).compare(model1, model2);
-
-        assertEquals(1,
-                     changes.size());
-
-        PrimaryKeyChange change = (PrimaryKeyChange)changes.get(0);
-
-        assertEquals(1,
-                     change.getOldPrimaryKeyColumns().length);
-        assertEquals(2,
-                     change.getNewPrimaryKeyColumns().length);
-        assertEquals("ColPK1",
-                     change.getOldPrimaryKeyColumns()[0].getName());
-        assertEquals("ColPK1",
-                     change.getNewPrimaryKeyColumns()[0].getName());
-        assertEquals("ColPK2",
-                     change.getNewPrimaryKeyColumns()[1].getName());
-    }
-
-    /**
-     * Tests the removal of a column from the primary key.
-     */
-    public void testRemovePrimaryKeyColumn()
-    {
-        final String MODEL1 = 
-            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
-            "<database name='test'>\n" +
-            "  <table name='TableA'>\n" +
-            "    <column name='ColPK1' type='INTEGER' primaryKey='true' required='true'/>\n" +
-            "    <column name='ColPK2' type='INTEGER' primaryKey='true' required='true'/>\n" +
-            "  </table>\n" +
-            "</database>";
-        final String MODEL2 = 
-            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
-            "<database name='test'>\n" +
-            "  <table name='TableA'>\n" +
-            "    <column name='ColPK1' type='INTEGER' required='true'/>\n" +
-            "    <column name='ColPK2' type='INTEGER' primaryKey='true' required='true'/>\n" +
-            "  </table>\n" +
-            "</database>";
-
-        Database model1  = parseDatabaseFromString(MODEL1);
-        Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(false).compare(model1, model2);
-
-        assertEquals(1,
-                     changes.size());
-
-        PrimaryKeyChange change = (PrimaryKeyChange)changes.get(0);
-
-        assertEquals(2,
-                     change.getOldPrimaryKeyColumns().length);
-        assertEquals(1,
-                     change.getNewPrimaryKeyColumns().length);
-        assertEquals("ColPK1",
-                     change.getOldPrimaryKeyColumns()[0].getName());
-        assertEquals("ColPK2",
-                     change.getOldPrimaryKeyColumns()[1].getName());
-        assertEquals("ColPK2",
-                     change.getNewPrimaryKeyColumns()[0].getName());
-    }
-
-    /**
-     * Tests the addition a column.
-     */
-    public void testAddColumn()
-    {
-        final String MODEL1 = 
-            "<?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" +
-            "  </table>\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='Col1' type='DOUBLE'/>\n" +
-            "  </table>\n" +
-            "</database>";
-
-        Database model1  = parseDatabaseFromString(MODEL1);
-        Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(false).compare(model1, model2);
-
-        assertEquals(1,
-                     changes.size());
-
-        AddColumnChange change = (AddColumnChange)changes.get(0);
-
-        assertEquals("Col1",
-                     change.getNewColumn().getName());
-    }
-
-    /**
-     * Tests the removal of a column.
-     */
-    public void testChangeColumnOrder()
-    {
-        final String MODEL1 = 
-            "<?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='Col1' type='DOUBLE'/>\n" +
-            "    <column name='Col2' type='INTEGER' required='true'/>\n" +
-            "    <column name='Col3' type='VARCHAR' size='32'/>\n" +
-            "  </table>\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='Col3' type='VARCHAR' size='32'/>\n" +
-            "    <column name='Col2' type='INTEGER' required='true'/>\n" +
-            "    <column name='Col1' type='DOUBLE'/>\n" +
-            "  </table>\n" +
-            "</database>";
-
-        Database model1  = parseDatabaseFromString(MODEL1);
-        Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(false).compare(model1, model2);
-
-        assertEquals(1,
-                     changes.size());
-
-        ColumnOrderChange change      = (ColumnOrderChange)changes.get(0);
-        Table             sourceTable = change.getChangedTable();
-
-        assertEquals(3,
-                     change.getNewPosition(sourceTable.getColumn(1)));
-        assertEquals(-1,
-                     change.getNewPosition(sourceTable.getColumn(2)));
-        assertEquals(1,
-                     change.getNewPosition(sourceTable.getColumn(3)));
-    }
-
-    /**
-     * Tests the removal of a column.
-     */
-    public void testRemoveColumn()
-    {
-        final String MODEL1 = 
-            "<?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='Col1' type='DOUBLE'/>\n" +
-            "  </table>\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" +
-            "  </table>\n" +
-            "</database>";
-
-        Database model1  = parseDatabaseFromString(MODEL1);
-        Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(false).compare(model1, model2);
-
-        assertEquals(1,
-                     changes.size());
-
-        RemoveColumnChange change = (RemoveColumnChange)changes.get(0);
-
-        assertEquals("Col1",
-                     change.getChangedColumn().getName());
-    }
-
-    /**
-     * Tests changing the data type of a column.
-     */
-    public void testChangeColumnDataType()
-    {
-        final String MODEL1 = 
-            "<?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='Col' type='DOUBLE'/>\n" +
-            "  </table>\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='Col' type='INTEGER'/>\n" +
-            "  </table>\n" +
-            "</database>";
-
-        Database model1  = parseDatabaseFromString(MODEL1);
-        Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(true).compare(model1, model2);
-
-        assertEquals(1,
-                     changes.size());
-
-        ColumnDataTypeChange change = (ColumnDataTypeChange)changes.get(0);
-
-        assertEquals("Col",
-                     change.getChangedColumn().getName());
-        assertEquals(Types.INTEGER,
-                     change.getNewTypeCode());
-    }
-
-    /**
-     * Tests changing the size of a column.
-     */
-    public void testChangeColumnSize()
-    {
-        // note that we also have a size for the INTEGER column, but we don't
-        // expect a change for it because the size is not relevant for this type
-        final String MODEL1 = 
-            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
-            "<database name='test'>\n" +
-            "  <table name='TableA'>\n" +
-            "    <column name='ColPK' type='INTEGER' size='8' primaryKey='true' required='true'/>\n" +
-            "    <column name='Col' type='VARCHAR' size='16'/>\n" +
-            "  </table>\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='COL' type='VARCHAR' size='32'/>\n" +
-            "  </table>\n" +
-            "</database>";
-
-        Database model1  = parseDatabaseFromString(MODEL1);
-        Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(false).compare(model1, model2);
-
-        assertEquals(1,
-                     changes.size());
-
-        ColumnSizeChange change = (ColumnSizeChange)changes.get(0);
-
-        assertEquals("Col",
-                     change.getChangedColumn().getName());
-        assertEquals(32,
-                     change.getNewSize());
-        assertEquals(0,
-                     change.getNewScale());
-    }
-
-    /**
-     * Tests changing the scale of a column.
-     */
-    public void testChangeColumnScale()
-    {
-        final String MODEL1 = 
-            "<?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='Col' type='NUMERIC' size='32,0'/>\n" +
-            "  </table>\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='Col' type='NUMERIC' size='32,5'/>\n" +
-            "  </table>\n" +
-            "</database>";
-
-        Database model1  = parseDatabaseFromString(MODEL1);
-        Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(true).compare(model1, model2);
-
-        assertEquals(1,
-                     changes.size());
-
-        ColumnSizeChange change = (ColumnSizeChange)changes.get(0);
-
-        assertEquals("Col",
-                     change.getChangedColumn().getName());
-        assertEquals(32,
-                     change.getNewSize());
-        assertEquals(5,
-                     change.getNewScale());
-    }
-
-    /**
-     * Tests removing the size of a column. This test shows how the comparator
-     * reacts in the common case of comparing a model read from a live database
-     * (which usually returns sizes for every column) and a model from XML.
-     * The model comparator will filter out these changes depending on the
-     * platform info with which the comparator was created. 
-     */
-    public void testRemoveColumnSize()
-    {
-        final String MODEL1 = 
-            "<?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='Col' type='INTEGER' size='8'/>\n" +
-            "  </table>\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='COL' type='INTEGER'/>\n" +
-            "  </table>\n" +
-            "</database>";
-
-        Database model1  = parseDatabaseFromString(MODEL1);
-        Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(false).compare(model1, model2);
-
-        assertTrue(changes.isEmpty());
-    }
-
-    /**
-     * Tests changing the default value of a column.
-     */
-    public void testChangeDefaultValue()
-    {
-        final String MODEL1 = 
-            "<?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='Col' type='INTEGER' default='1'/>\n" +
-            "  </table>\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='Col' type='INTEGER' default='2'/>\n" +
-            "  </table>\n" +
-            "</database>";
-
-        Database model1  = parseDatabaseFromString(MODEL1);
-        Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(true).compare(model1, model2);
-
-        assertEquals(1,
-                     changes.size());
-
-        ColumnDefaultValueChange change = (ColumnDefaultValueChange)changes.get(0);
-
-        assertEquals("Col",
-                     change.getChangedColumn().getName());
-        assertEquals("2",
-                     change.getNewDefaultValue());
-    }
-
-    /**
-     * Tests that shows that the same default value expressed differently does not
-     * result in a change.
-     */
-    public void testSameDefaultValueExpressedDifferently()
-    {
-        final String MODEL1 = 
-            "<?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='Col' type='DOUBLE' default='10'/>\n" +
-            "  </table>\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='COL' type='DOUBLE' default='1e+1'/>\n" +
-            "  </table>\n" +
-            "</database>";
-
-        Database model1  = parseDatabaseFromString(MODEL1);
-        Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(false).compare(model1, model2);
-
-        assertTrue(changes.isEmpty());
-    }
-
-    /**
-     * Tests adding a default value to a column.
-     */
-    public void testAddDefaultValue()
-    {
-        final String MODEL1 = 
-            "<?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='Col' type='INTEGER'/>\n" +
-            "  </table>\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='Col' type='INTEGER' default='0'/>\n" +
-            "  </table>\n" +
-            "</database>";
-
-        Database model1  = parseDatabaseFromString(MODEL1);
-        Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(true).compare(model1, model2);
-
-        assertEquals(1,
-                     changes.size());
-
-        ColumnDefaultValueChange change = (ColumnDefaultValueChange)changes.get(0);
-
-        assertEquals("Col",
-                     change.getChangedColumn().getName());
-        assertEquals("0",
-                     change.getNewDefaultValue());
-    }
-
-    /**
-     * Tests chainging the required-constraint of a column.
-     */
-    public void testChangeColumnRequired()
-    {
-        final String MODEL1 = 
-            "<?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='Col' type='INTEGER' required='false'/>\n" +
-            "  </table>\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='COL' type='INTEGER' required='true'/>\n" +
-            "  </table>\n" +
-            "</database>";
-
-        Database model1  = parseDatabaseFromString(MODEL1);
-        Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(false).compare(model1, model2);
-
-        assertEquals(1,
-                     changes.size());
-
-        ColumnRequiredChange change = (ColumnRequiredChange)changes.get(0);
-
-        assertEquals("Col",
-                     change.getChangedColumn().getName());
-    }
-
-    /**
-     * Tests chainging the auto-increment-constraint of a column.
-     */
-    public void testChangeColumnAutoIncrement()
-    {
-        final String MODEL1 = 
-            "<?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='Col' type='INTEGER' autoIncrement='true'/>\n" +
-            "  </table>\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='COL' type='INTEGER' autoIncrement='false'/>\n" +
-            "  </table>\n" +
-            "</database>";
-
-        Database model1  = parseDatabaseFromString(MODEL1);
-        Database model2  = parseDatabaseFromString(MODEL2);
-        List     changes = createModelComparator(false).compare(model1, model2);
-
-        assertEquals(1,
-                     changes.size());
-
-        ColumnAutoIncrementChange change = (ColumnAutoIncrementChange)changes.get(0);
+        assertEquals("TableA",
+                     change1.getChangedTable());
 
-        assertEquals("Col",
-                     change.getChangedColumn().getName());
+        assertTable("TABLEA", null, 1, 0, 0, 
+                    change2.getNewTable());
+        assertColumn("COLPK", Types.INTEGER, null, null, true, true, false,
+                     change2.getNewTable().getColumn(0));
     }
 }

Added: db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestPrimaryKeyComparison.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestPrimaryKeyComparison.java?rev=602807&view=auto
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestPrimaryKeyComparison.java (added)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/alteration/TestPrimaryKeyComparison.java Mon Dec 10 00:20:47 2007
@@ -0,0 +1,576 @@
+package org.apache.ddlutils.alteration;
+
+/*
+ * 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.
+ */
+
+import java.sql.Types;
+import java.util.List;
+
+import org.apache.ddlutils.model.Database;
+
+/**
+ * Tests the model comparison of primary keys.
+ * 
+ * @version $Revision: $
+ */
+public class TestPrimaryKeyComparison extends TestComparisonBase
+{
+    /**
+     * Tests the addition of a column that is the primary key.
+     */
+    public void testAddPrimaryKeyColumn()
+    {
+        final String MODEL1 = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+            "<database name='test'>\n" +
+            "  <table name='TableA'>\n" +
+            "    <column name='ColPK2' type='INTEGER' required='true'/>\n" +
+            "  </table>\n" +
+            "</database>";
+        final String MODEL2 = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+            "<database name='test'>\n" +
+            "  <table name='TableA'>\n" +
+            "    <column name='ColPK1' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='ColPK2' type='INTEGER' required='true'/>\n" +
+            "  </table>\n" +
+            "</database>";
+
+        Database model1  = parseDatabaseFromString(MODEL1);
+        Database model2  = parseDatabaseFromString(MODEL2);
+        List     changes = getPlatform(true).getChanges(model1, model2);
+
+        assertEquals(2,
+                     changes.size());
+
+        AddColumnChange     colChange = (AddColumnChange)changes.get(0);
+        AddPrimaryKeyChange pkChange  = (AddPrimaryKeyChange)changes.get(1);
+
+        assertEquals("TableA",
+                     colChange.getChangedTable());
+        assertColumn("ColPK1", Types.INTEGER, null, null, false, true, false,
+                     colChange.getNewColumn());
+        assertNull(colChange.getPreviousColumn());
+        assertEquals("ColPK2",
+                     colChange.getNextColumn());
+
+        assertEquals("TableA",
+                     pkChange.getChangedTable());
+        assertEquals(1,
+                     pkChange.getPrimaryKeyColumns().length);
+        assertEquals("ColPK1",
+                     pkChange.getPrimaryKeyColumns()[0]);
+    }
+
+    /**
+     * Tests the addition of a single-column primary key.
+     */
+    public void testMakeColumnPrimaryKey()
+    {
+        final String MODEL1 = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+            "<database name='test'>\n" +
+            "  <table name='TableA'>\n" +
+            "    <column name='ColPK' type='INTEGER' required='true'/>\n" +
+            "  </table>\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" +
+            "  </table>\n" +
+            "</database>";
+
+        Database model1  = parseDatabaseFromString(MODEL1);
+        Database model2  = parseDatabaseFromString(MODEL2);
+        List     changes = getPlatform(false).getChanges(model1, model2);
+
+        assertEquals(1,
+                     changes.size());
+
+        AddPrimaryKeyChange change = (AddPrimaryKeyChange)changes.get(0);
+
+        assertEquals("TableA",
+                     change.getChangedTable());
+        assertEquals(1,
+                     change.getPrimaryKeyColumns().length);
+        assertEquals("ColPK",
+                     change.getPrimaryKeyColumns()[0]);
+    }
+
+    /**
+     * Tests the addition of a column to the primary key.
+     */
+    public void testAddColumnToPrimaryKey()
+    {
+        final String MODEL1 = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+            "<database name='test'>\n" +
+            "  <table name='TableA'>\n" +
+            "    <column name='ColPK1' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='ColPK2' type='INTEGER' required='true'/>\n" +
+            "  </table>\n" +
+            "</database>";
+        final String MODEL2 = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+            "<database name='test'>\n" +
+            "  <table name='TableA'>\n" +
+            "    <column name='ColPK1' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='ColPK2' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "  </table>\n" +
+            "</database>";
+
+        Database model1  = parseDatabaseFromString(MODEL1);
+        Database model2  = parseDatabaseFromString(MODEL2);
+        List     changes = getPlatform(true).getChanges(model1, model2);
+
+        assertEquals(1,
+                     changes.size());
+
+        PrimaryKeyChange change = (PrimaryKeyChange)changes.get(0);
+
+        assertEquals("TableA",
+                     change.getChangedTable());
+        assertEquals(2,
+                     change.getNewPrimaryKeyColumns().length);
+        assertEquals("ColPK1",
+                     change.getNewPrimaryKeyColumns()[0]);
+        assertEquals("ColPK2",
+                     change.getNewPrimaryKeyColumns()[1]);
+    }
+
+    /**
+     * Tests changing the order of columns in the primary key.
+     */
+    public void testChangeColumnOrderInPrimaryKey()
+    {
+        final String MODEL1 = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+            "<database name='test'>\n" +
+            "  <table name='TableA'>\n" +
+            "    <column name='ColPK1' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='ColPK2' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='ColPK3' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "  </table>\n" +
+            "</database>";
+        final String MODEL2 = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+            "<database name='test'>\n" +
+            "  <table name='TableA'>\n" +
+            "    <column name='ColPK2' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='ColPK3' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='ColPK1' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "  </table>\n" +
+            "</database>";
+
+        Database model1  = parseDatabaseFromString(MODEL1);
+        Database model2  = parseDatabaseFromString(MODEL2);
+        List     changes = getPlatform(true).getChanges(model1, model2);
+
+        assertEquals(2,
+                     changes.size());
+
+        PrimaryKeyChange  pkChange  = (PrimaryKeyChange)changes.get(0);
+        ColumnOrderChange colChange = (ColumnOrderChange)changes.get(1);
+
+        assertEquals("TableA",
+                     pkChange.getChangedTable());
+        assertEquals(3,
+                     pkChange.getNewPrimaryKeyColumns().length);
+        assertEquals("ColPK2",
+                     pkChange.getNewPrimaryKeyColumns()[0]);
+        assertEquals("ColPK3",
+                     pkChange.getNewPrimaryKeyColumns()[1]);
+        assertEquals("ColPK1",
+                     pkChange.getNewPrimaryKeyColumns()[2]);
+        
+        assertEquals("TableA",
+                     colChange.getChangedTable());
+        assertEquals(2,
+                     colChange.getNewPosition("ColPK1", true));
+        assertEquals(0,
+                     colChange.getNewPosition("ColPK2", true));
+        assertEquals(1,
+                     colChange.getNewPosition("ColPK3", true));
+    }
+
+    /**
+     * Tests adding a column to and changing the order of columns in the primary key.
+     */
+    public void testAddColumnAndChangeColumnOrderInPrimaryKey()
+    {
+        final String MODEL1 = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+            "<database name='test'>\n" +
+            "  <table name='TableA'>\n" +
+            "    <column name='ColPK1' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='ColPK3' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "  </table>\n" +
+            "</database>";
+        final String MODEL2 = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+            "<database name='test'>\n" +
+            "  <table name='TableA'>\n" +
+            "    <column name='ColPK2' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='ColPK3' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='ColPK1' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "  </table>\n" +
+            "</database>";
+
+        Database model1  = parseDatabaseFromString(MODEL1);
+        Database model2  = parseDatabaseFromString(MODEL2);
+        List     changes = getPlatform(true).getChanges(model1, model2);
+
+        assertEquals(4,
+                     changes.size());
+
+        PrimaryKeyChange  pkChange1  = (PrimaryKeyChange)changes.get(0);
+        ColumnOrderChange colChange1 = (ColumnOrderChange)changes.get(1);
+        AddColumnChange   colChange2 = (AddColumnChange)changes.get(2);
+        PrimaryKeyChange  pkChange2  = (PrimaryKeyChange)changes.get(3);
+        
+        assertEquals("TableA",
+                     pkChange1.getChangedTable());
+        assertEquals(2,
+                     pkChange1.getNewPrimaryKeyColumns().length);
+        assertEquals("ColPK3",
+                     pkChange1.getNewPrimaryKeyColumns()[0]);
+        assertEquals("ColPK1",
+                     pkChange1.getNewPrimaryKeyColumns()[1]);
+
+        assertEquals("TableA",
+                     colChange1.getChangedTable());
+        assertEquals(1,
+                     colChange1.getNewPosition("ColPK1", true));
+        assertEquals(-1,
+                     colChange1.getNewPosition("ColPK2", true));
+        assertEquals(0,
+                     colChange1.getNewPosition("ColPK3", true));
+
+        assertEquals("TableA",
+                     colChange2.getChangedTable());
+        assertColumn("ColPK2", Types.INTEGER, null, null, false, true, false,
+                     colChange2.getNewColumn());
+        assertNull(colChange2.getPreviousColumn());
+        assertEquals("ColPK3",
+                     colChange2.getNextColumn());
+
+        assertEquals("TableA",
+                     pkChange2.getChangedTable());
+        assertEquals(3,
+                     pkChange2.getNewPrimaryKeyColumns().length);
+        assertEquals("ColPK2",
+                     pkChange2.getNewPrimaryKeyColumns()[0]);
+        assertEquals("ColPK3",
+                     pkChange2.getNewPrimaryKeyColumns()[1]);
+        assertEquals("ColPK1",
+                     pkChange2.getNewPrimaryKeyColumns()[2]);
+    }
+
+    /**
+     * Tests removing a column from and changing the order of columns in the primary key.
+     */
+    public void testRemoveColumnAndChangeColumnOrderInPrimaryKey()
+    {
+        final String MODEL1 = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+            "<database name='test'>\n" +
+            "  <table name='TableA'>\n" +
+            "    <column name='ColPK1' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='ColPK2' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='ColPK3' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "  </table>\n" +
+            "</database>";
+        final String MODEL2 = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+            "<database name='test'>\n" +
+            "  <table name='TableA'>\n" +
+            "    <column name='ColPK3' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='ColPK1' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "  </table>\n" +
+            "</database>";
+
+        Database model1  = parseDatabaseFromString(MODEL1);
+        Database model2  = parseDatabaseFromString(MODEL2);
+        List     changes = getPlatform(true).getChanges(model1, model2);
+
+        assertEquals(3,
+                     changes.size());
+
+        RemoveColumnChange colChange1 = (RemoveColumnChange)changes.get(0);
+        PrimaryKeyChange   pkChange   = (PrimaryKeyChange)changes.get(1);
+        ColumnOrderChange  colChange2 = (ColumnOrderChange)changes.get(2);
+
+        assertEquals("TableA",
+                     colChange1.getChangedTable());
+        assertEquals("ColPK2",
+                     colChange1.getChangedColumn());
+
+        assertEquals("TableA",
+                     pkChange.getChangedTable());
+        assertEquals(2,
+                     pkChange.getNewPrimaryKeyColumns().length);
+        assertEquals("ColPK3",
+                     pkChange.getNewPrimaryKeyColumns()[0]);
+        assertEquals("ColPK1",
+                     pkChange.getNewPrimaryKeyColumns()[1]);
+        
+        assertEquals("TableA",
+                     colChange2.getChangedTable());
+        assertEquals(1,
+                     colChange2.getNewPosition("ColPK1", true));
+        assertEquals(-1,
+                     colChange2.getNewPosition("ColPK2", true));
+        assertEquals(0,
+                     colChange2.getNewPosition("ColPK3", true));
+    }
+
+    // TODO: remove, add & reorder PK columns
+    /**
+     * Tests the removal of a column from the primary key.
+     */
+    public void testMakeColumnNotPrimaryKey()
+    {
+        final String MODEL1 = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+            "<database name='test'>\n" +
+            "  <table name='TableA'>\n" +
+            "    <column name='ColPK1' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='ColPK2' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "  </table>\n" +
+            "</database>";
+        final String MODEL2 = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+            "<database name='test'>\n" +
+            "  <table name='TableA'>\n" +
+            "    <column name='ColPK1' type='INTEGER' required='true'/>\n" +
+            "    <column name='ColPK2' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "  </table>\n" +
+            "</database>";
+
+        Database model1  = parseDatabaseFromString(MODEL1);
+        Database model2  = parseDatabaseFromString(MODEL2);
+        List     changes = getPlatform(false).getChanges(model1, model2);
+
+        assertEquals(1,
+                     changes.size());
+
+        PrimaryKeyChange change = (PrimaryKeyChange)changes.get(0);
+
+        assertEquals("TableA",
+                     change.getChangedTable());
+        assertEquals(1,
+                     change.getNewPrimaryKeyColumns().length);
+        assertEquals("ColPK2",
+                     change.getNewPrimaryKeyColumns()[0]);
+    }
+
+
+    /**
+     * Tests removing the column that is the primary key.
+     */
+    public void testDropPrimaryKeyColumn1()
+    {
+        final String MODEL1 = 
+            "<?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='Col' type='INTEGER'/>\n" +
+            "  </table>\n" +
+            "</database>";
+        final String MODEL2 = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+            "<database name='test'>\n" +
+            "  <table name='TABLEA'>\n" +
+            "    <column name='COL' type='INTEGER'/>\n" +
+            "  </table>\n" +
+            "</database>";
+
+        Database model1  = parseDatabaseFromString(MODEL1);
+        Database model2  = parseDatabaseFromString(MODEL2);
+        List     changes = getPlatform(false).getChanges(model1, model2);
+
+        assertEquals(1,
+                     changes.size());
+
+        RemoveColumnChange colChange = (RemoveColumnChange)changes.get(0);
+
+        assertEquals("TableA",
+                     colChange.getChangedTable());
+        assertEquals("ColPK",
+                     colChange.getChangedColumn());
+    }
+
+    /**
+     * Tests dropping a column that is part of the primary key.
+     */
+    public void testDropPrimaryKeyColumn2()
+    {
+        final String MODEL1 = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+            "<database name='test'>\n" +
+            "  <table name='TableA'>\n" +
+            "    <column name='ColPK1' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='ColPK2' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='ColPK3' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "  </table>\n" +
+            "</database>";
+        final String MODEL2 = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+            "<database name='test'>\n" +
+            "  <table name='TableA'>\n" +
+            "    <column name='ColPK1' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='ColPK3' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "  </table>\n" +
+            "</database>";
+
+        Database model1  = parseDatabaseFromString(MODEL1);
+        Database model2  = parseDatabaseFromString(MODEL2);
+        List     changes = getPlatform(true).getChanges(model1, model2);
+
+        assertEquals(1,
+                     changes.size());
+
+        RemoveColumnChange colChange = (RemoveColumnChange)changes.get(0);
+
+        assertEquals("TableA",
+                     colChange.getChangedTable());
+        assertEquals("ColPK2",
+                     colChange.getChangedColumn());
+    }
+
+    /**
+     * Tests the removal of a primary key.
+     */
+    public void testRemovePrimaryKey1()
+    {
+        final String MODEL1 = 
+            "<?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" +
+            "  </table>\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' required='true'/>\n" +
+            "  </table>\n" +
+            "</database>";
+
+        Database model1  = parseDatabaseFromString(MODEL1);
+        Database model2  = parseDatabaseFromString(MODEL2);
+        List     changes = getPlatform(false).getChanges(model1, model2);
+
+        assertEquals(1,
+                     changes.size());
+
+        RemovePrimaryKeyChange change = (RemovePrimaryKeyChange)changes.get(0);
+
+        assertEquals("TableA",
+                     change.getChangedTable());
+    }
+
+    /**
+     * Tests removing a multi-column primary key.
+     */
+    public void testRemovePrimaryKey2()
+    {
+        final String MODEL1 = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+            "<database name='test'>\n" +
+            "  <table name='TableA'>\n" +
+            "    <column name='ColPK1' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='ColPK2' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='ColPK3' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "  </table>\n" +
+            "</database>";
+        final String MODEL2 = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+            "<database name='test'>\n" +
+            "  <table name='TABLEA'>\n" +
+            "    <column name='COLPK1' type='INTEGER' required='true'/>\n" +
+            "    <column name='COLPK2' type='INTEGER' required='true'/>\n" +
+            "    <column name='COLPK3' type='INTEGER' required='true'/>\n" +
+            "  </table>\n" +
+            "</database>";
+
+        Database model1  = parseDatabaseFromString(MODEL1);
+        Database model2  = parseDatabaseFromString(MODEL2);
+        List     changes = getPlatform(false).getChanges(model1, model2);
+
+        assertEquals(1,
+                     changes.size());
+
+        RemovePrimaryKeyChange pkChange = (RemovePrimaryKeyChange)changes.get(0);
+
+        assertEquals("TableA",
+                     pkChange.getChangedTable());
+    }
+
+    /**
+     * Tests changing the columns of a primary key.
+     */
+    public void testChangePrimaryKeyColumns()
+    {
+        final String MODEL1 = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+            "<database name='test'>\n" +
+            "  <table name='TableA'>\n" +
+            "    <column name='ColPK1' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='ColPK2' type='INTEGER' required='true'/>\n" +
+            "    <column name='ColPK3' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='ColPK4' type='INTEGER' required='true'/>\n" +
+            "    <column name='ColPK5' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "  </table>\n" +
+            "</database>";
+        final String MODEL2 = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+            "<database name='test'>\n" +
+            "  <table name='TABLEA'>\n" +
+            "    <column name='ColPK1' type='INTEGER' required='true'/>\n" +
+            "    <column name='ColPK2' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='ColPK3' type='INTEGER' required='true'/>\n" +
+            "    <column name='ColPK4' type='INTEGER' primaryKey='true' required='true'/>\n" +
+            "    <column name='ColPK5' type='INTEGER' required='true'/>\n" +
+            "  </table>\n" +
+            "</database>";
+
+        Database model1  = parseDatabaseFromString(MODEL1);
+        Database model2  = parseDatabaseFromString(MODEL2);
+        List     changes = getPlatform(false).getChanges(model1, model2);
+
+        assertEquals(1,
+                     changes.size());
+
+        PrimaryKeyChange pkChange = (PrimaryKeyChange)changes.get(0);
+
+        assertEquals("TableA",
+                     pkChange.getChangedTable());
+        assertEquals(2,
+                     pkChange.getNewPrimaryKeyColumns().length);
+        assertEquals("ColPK2",
+                     pkChange.getNewPrimaryKeyColumns()[0]);
+        assertEquals("ColPK4",
+                     pkChange.getNewPrimaryKeyColumns()[1]);
+    }
+}



Mime
View raw message