db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r359072 - in /db/ddlutils/trunk/src/test/org/apache/ddlutils/io: RoundtripTestBase.java TestRoundtripDerby.java
Date Mon, 26 Dec 2005 15:54:43 GMT
Author: tomdz
Date: Mon Dec 26 07:54:38 2005
New Revision: 359072

URL: http://svn.apache.org/viewcvs?rev=359072&view=rev
Log:
Added more roundtrip tests

Modified:
    db/ddlutils/trunk/src/test/org/apache/ddlutils/io/RoundtripTestBase.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestRoundtripDerby.java

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/RoundtripTestBase.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/RoundtripTestBase.java?rev=359072&r1=359071&r2=359072&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/RoundtripTestBase.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/RoundtripTestBase.java Mon Dec 26 07:54:38
2005
@@ -16,14 +16,19 @@
  * limitations under the License.
  */
 
+import java.io.StringWriter;
 import java.util.List;
 
 import org.apache.commons.beanutils.DynaBean;
 import org.apache.ddlutils.TestDatabaseWriterBase;
+import org.apache.ddlutils.dynabean.SqlDynaBean;
+import org.apache.ddlutils.dynabean.SqlDynaClass;
+import org.apache.ddlutils.dynabean.SqlDynaProperty;
 import org.apache.ddlutils.model.Column;
 import org.apache.ddlutils.model.Database;
 import org.apache.ddlutils.model.IndexColumn;
 import org.apache.ddlutils.model.Table;
+import org.apache.ddlutils.model.TypeMap;
 import org.apache.ddlutils.model.UniqueIndex;
 import org.apache.ddlutils.platform.DefaultValueHelper;
 
@@ -305,6 +310,123 @@
         "    <column name='VALUE' type='VARCHAR' required='true' default='some value'/>\n"+
         "  </table>\n"+
         "</database>";
+    /** Test model with a simple LONGVARCHAR column. */
+    protected static final String TEST_LONGVARCHAR_MODEL = 
+        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+        "<database name='roundtriptest'>\n"+
+        "  <table name='ROUNDTRIP'>\n"+
+        "    <column name='PK' type='INTEGER' primaryKey='true' required='true'/>\n"+
+        "    <column name='VALUE' type='LONGVARCHAR'/>\n"+
+        "  </table>\n"+
+        "</database>";
+    /** Test model with a LONGVARCHAR column with a default value. */
+    protected static final String TEST_LONGVARCHAR_MODEL_WITH_DEFAULT = 
+        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+        "<database name='roundtriptest'>\n"+
+        "  <table name='ROUNDTRIP'>\n"+
+        "    <column name='PK' type='INTEGER' primaryKey='true' required='true'/>\n"+
+        "    <column name='VALUE' type='LONGVARCHAR' required='true' default='some value'/>\n"+
+        "  </table>\n"+
+        "</database>";
+    /** Test model with a simple DATE column. */
+    protected static final String TEST_DATE_MODEL = 
+        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+        "<database name='roundtriptest'>\n"+
+        "  <table name='ROUNDTRIP'>\n"+
+        "    <column name='PK' type='INTEGER' primaryKey='true' required='true'/>\n"+
+        "    <column name='VALUE' type='DATE'/>\n"+
+        "  </table>\n"+
+        "</database>";
+    /** Test model with a DATE column with a default value. */
+    protected static final String TEST_DATE_MODEL_WITH_DEFAULT = 
+        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+        "<database name='roundtriptest'>\n"+
+        "  <table name='ROUNDTRIP'>\n"+
+        "    <column name='PK' type='INTEGER' primaryKey='true' required='true'/>\n"+
+        "    <column name='VALUE' type='DATE' required='true' default='2000-01-01'/>\n"+
+        "  </table>\n"+
+        "</database>";
+    /** Test model with a simple TIME column. */
+    protected static final String TEST_TIME_MODEL = 
+        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+        "<database name='roundtriptest'>\n"+
+        "  <table name='ROUNDTRIP'>\n"+
+        "    <column name='PK' type='INTEGER' primaryKey='true' required='true'/>\n"+
+        "    <column name='VALUE' type='TIME'/>\n"+
+        "  </table>\n"+
+        "</database>";
+    /** Test model with a TIME column with a default value. */
+    protected static final String TEST_TIME_MODEL_WITH_DEFAULT = 
+        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+        "<database name='roundtriptest'>\n"+
+        "  <table name='ROUNDTRIP'>\n"+
+        "    <column name='PK' type='INTEGER' primaryKey='true' required='true'/>\n"+
+        "    <column name='VALUE' type='TIME' required='true' default='11:27:03'/>\n"+
+        "  </table>\n"+
+        "</database>";
+    /** Test model with a simple TIMESTAMP column. */
+    protected static final String TEST_TIMESTAMP_MODEL = 
+        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+        "<database name='roundtriptest'>\n"+
+        "  <table name='ROUNDTRIP'>\n"+
+        "    <column name='PK' type='INTEGER' primaryKey='true' required='true'/>\n"+
+        "    <column name='VALUE' type='TIMESTAMP'/>\n"+
+        "  </table>\n"+
+        "</database>";
+    /** Test model with a TIMESTAMP column with a default value. */
+    protected static final String TEST_TIMESTAMP_MODEL_WITH_DEFAULT = 
+        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+        "<database name='roundtriptest'>\n"+
+        "  <table name='ROUNDTRIP'>\n"+
+        "    <column name='PK' type='INTEGER' primaryKey='true' required='true'/>\n"+
+        "    <column name='VALUE' type='TIMESTAMP' required='true' default='1985-06-17
16:17:18.0'/>\n"+
+        "  </table>\n"+
+        "</database>";
+    /** Test model with a simple BINARY column. */
+    protected static final String TEST_BINARY_MODEL = 
+        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+        "<database name='roundtriptest'>\n"+
+        "  <table name='ROUNDTRIP'>\n"+
+        "    <column name='PK' type='INTEGER' primaryKey='true' required='true'/>\n"+
+        "    <column name='VALUE' type='BINARY'/>\n"+
+        "  </table>\n"+
+        "</database>";
+    /** Test model with a simple VARBINARY column. */
+    protected static final String TEST_VARBINARY_MODEL = 
+        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+        "<database name='roundtriptest'>\n"+
+        "  <table name='ROUNDTRIP'>\n"+
+        "    <column name='PK' type='INTEGER' primaryKey='true' required='true'/>\n"+
+        "    <column name='VALUE' type='VARBINARY'/>\n"+
+        "  </table>\n"+
+        "</database>";
+    /** Test model with a simple LONGVARBINARY column. */
+    protected static final String TEST_LONGVARBINARY_MODEL = 
+        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+        "<database name='roundtriptest'>\n"+
+        "  <table name='ROUNDTRIP'>\n"+
+        "    <column name='PK' type='INTEGER' primaryKey='true' required='true'/>\n"+
+        "    <column name='VALUE' type='LONGVARBINARY'/>\n"+
+        "  </table>\n"+
+        "</database>";
+    /** Test model with a simple BLOB column. */
+    protected static final String TEST_BLOB_MODEL = 
+        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+        "<database name='roundtriptest'>\n"+
+        "  <table name='ROUNDTRIP'>\n"+
+        "    <column name='PK' type='INTEGER' primaryKey='true' required='true'/>\n"+
+        "    <column name='VALUE' type='BLOB'/>\n"+
+        "  </table>\n"+
+        "</database>";
+    /** Test model with a simple CLOB column. */
+    protected static final String TEST_CLOB_MODEL = 
+        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+        "<database name='roundtriptest'>\n"+
+        "  <table name='ROUNDTRIP'>\n"+
+        "    <column name='PK' type='INTEGER' primaryKey='true' required='true'/>\n"+
+        "    <column name='VALUE' type='CLOB'/>\n"+
+        "  </table>\n"+
+        "</database>";
 
     /**
      * Inserts a row into the designated table.
@@ -402,6 +524,17 @@
                             column.setDefaultValue(helper.convert(column.getDefaultValue(),
origType, targetType));
                         }
                     }
+                    // we also promote the default size if the column has no size
+                    // spec of its own
+                    if ((column.getSize() == null) && getPlatformInfo().hasSize(targetType))
+                    {
+                        Integer defaultSize = getPlatformInfo().getDefaultSize(targetType);
+
+                        if (defaultSize != null)
+                        {
+                            column.setSize(defaultSize.toString());
+                        }
+                    }
                 }
             }
             if (hasPkUniqueIndices())
@@ -417,7 +550,7 @@
     }
 
     /**
-     * Compares the attribute value of the given bean to the expected object.
+     * Compares the attribute value of the given bean with the expected object.
      * 
      * @param expected The expected object
      * @param bean     The bean
@@ -426,15 +559,39 @@
     protected void assertEquals(Object expected, Object bean, String attrName)
     {
         DynaBean dynaBean = (DynaBean)bean;
+        Object   value    = dynaBean.get(attrName);
+
+        if ((value instanceof byte[]) && !(expected instanceof byte[]) &&
(dynaBean instanceof SqlDynaBean))
+        {
+            SqlDynaClass dynaClass = (SqlDynaClass)((SqlDynaBean)dynaBean).getDynaClass();
+            Column       column    = ((SqlDynaProperty)dynaClass.getDynaProperty(attrName)).getColumn();
+
+            if (TypeMap.isBinaryType(column.getTypeCode()))
+            {
+                value = new BinaryObjectsHelper().deserialize((byte[])value);
+            }
+        }
+        assertEquals(expected, value);
+    }
+
+    protected void assertEquals(Database expected, Database actual)
+    {
+        StringWriter writer = new StringWriter();
+        DatabaseIO   dbIo   = new DatabaseIO();
+
+        dbIo.write(expected, writer);
+
+        String expectedXml = writer.toString();
+        
+        writer = new StringWriter();
+        dbIo.write(actual, writer);
+
+        String actualXml = writer.toString();
 
-        assertEquals(expected,
-                     dynaBean.get(attrName));
+        assertEquals((Object)expected, (Object)actual);
     }
 
-    // char/varchar columns incl. different sizes
-    // time columns
-    // binary/varbinary & java_object etc. columns
-    // blob/clob columns
+    // special columns (java_object, array, distinct, ...)
 
     // auto-increment
     // default values

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestRoundtripDerby.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestRoundtripDerby.java?rev=359072&r1=359071&r2=359072&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestRoundtripDerby.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestRoundtripDerby.java Mon Dec 26 07:54:38
2005
@@ -1,7 +1,13 @@
 package org.apache.ddlutils.io;
 
 import java.math.BigDecimal;
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.TreeSet;
 
 /**
  * Performs the roundtrip test against a derby database.
@@ -573,6 +579,290 @@
                               "1234567890123456789012345678901234567890123456789012345678901234"+
                               "1234567890123456789012345678901234567890123456789012345678901234"+
                               "12345678901234567890123456789012345678901234567890123456789012"),
beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a simple LONGVARCHAR column.
+     */
+    public void testLongVarChar()
+    {
+        createDatabase(TEST_LONGVARCHAR_MODEL);
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1), null });
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2), "some not too long text" });
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals((Object)null,                     beans.get(0), "VALUE");
+        assertEquals((Object)"some not too long text", beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a LONGVARCHAR column with a default value.
+     */
+    public void testLongVarCharWithDefault()
+    {
+        createDatabase(TEST_LONGVARCHAR_MODEL_WITH_DEFAULT);
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1) });
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2), "1234567890123456789012345678901234567890123456789012345678901234"+
+                                                              "1234567890123456789012345678901234567890123456789012345678901234"+
+                                                              "1234567890123456789012345678901234567890123456789012345678901234"+
+                                                              "1234567890123456789012345678901234567890123456789012345678901234"});
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals((Object)"some value", beans.get(0), "VALUE");
+        assertEquals((Object)("1234567890123456789012345678901234567890123456789012345678901234"+
+                              "1234567890123456789012345678901234567890123456789012345678901234"+
+                              "1234567890123456789012345678901234567890123456789012345678901234"+
+                              "1234567890123456789012345678901234567890123456789012345678901234"),
beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a simple DATE column.
+     */
+    public void testDate()
+    {
+        // we would use Calendar but that might give Locale problems
+        createDatabase(TEST_DATE_MODEL);
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1), null });
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2), new Date(103, 12, 25) });
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals((Object)null,          beans.get(0), "VALUE");
+        assertEquals(new Date(103, 12, 25), beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a DATE column with a default value.
+     */
+    public void testDateWithDefault()
+    {
+        // we would use Calendar but that might give Locale problems
+        createDatabase(TEST_DATE_MODEL_WITH_DEFAULT);
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1), new Date(105, 0, 1) });
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2) });
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals(new Date(105, 0, 1), beans.get(0), "VALUE");
+        assertEquals(new Date(100, 0, 1), beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a simple TIME column.
+     */
+    public void testTime()
+    {
+        // we would use Calendar but that might give Locale problems
+        createDatabase(TEST_TIME_MODEL);
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1), new Time(03, 47, 15) });
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2), null });
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals(new Time(03, 47, 15), beans.get(0), "VALUE");
+        assertEquals((Object)null,         beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a TIME column with a default value.
+     */
+    public void testTimeWithDefault()
+    {
+        // we would use Calendar but that might give Locale problems
+        createDatabase(TEST_TIME_MODEL_WITH_DEFAULT);
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1), new Time(23, 59, 59) });
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2) });
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals(new Time(23, 59, 59), beans.get(0), "VALUE");
+        assertEquals(new Time(11, 27, 03), beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a simple TIMESTAMP column.
+     */
+    public void testTimestamp()
+    {
+        // we would use Calendar but that might give Locale problems
+        // also we leave out the fractional part because databases differe
+        // in their support here
+        createDatabase(TEST_TIMESTAMP_MODEL);
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1), new Timestamp(70, 0, 1, 0,
0, 0, 0) });
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2), new Timestamp(100, 10, 11,
10, 10, 10, 0)});
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals(new Timestamp(70, 0, 1, 0, 0, 0, 0),       beans.get(0), "VALUE");
+        assertEquals(new Timestamp(100, 10, 11, 10, 10, 10, 0), beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a TIMESTAMP column with a default value.
+     */
+    public void testTimestampWithDefault()
+    {
+        // we would use Calendar but that might give Locale problems
+        // also we leave out the fractional part because databases differe
+        // in their support here
+        createDatabase(TEST_TIMESTAMP_MODEL_WITH_DEFAULT);
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1), new Timestamp(90, 9, 21, 20,
25, 39, 0) });
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2) });
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals(new Timestamp(90, 9, 21, 20, 25, 39, 0), beans.get(0), "VALUE");
+        assertEquals(new Timestamp(85, 5, 17, 16, 17, 18, 0), beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a simple BINARY column.
+     */
+    public void testBinary()
+    {
+        HashMap   value1 = new HashMap();
+        ArrayList value2 = new ArrayList();
+
+        value1.put("test", "some value");
+        value2.add("some other value");
+
+        BinaryObjectsHelper helper = new BinaryObjectsHelper();
+
+        createDatabase(TEST_BINARY_MODEL);
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1), helper.serialize(value1) });
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2), helper.serialize(value2) });
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals(value1, beans.get(0), "VALUE");
+        assertEquals(value2, beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a simple VARBINARY column.
+     */
+    public void testVarBinary()
+    {
+        TreeSet value1 = new TreeSet();
+        String  value2 = "a value, nothing special";
+
+        value1.add("o look, a value !");
+
+        BinaryObjectsHelper helper = new BinaryObjectsHelper();
+
+        createDatabase(TEST_VARBINARY_MODEL);
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1), helper.serialize(value1) });
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2), helper.serialize(value2) });
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals(value1,         beans.get(0), "VALUE");
+        assertEquals((Object)value2, beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a simple LONGVARBINARY column.
+     */
+    public void testLongVarBinary()
+    {
+        HashMap value = new HashMap();
+
+        value.put("test1", "some value");
+        value.put(null, "some other value");
+
+        BinaryObjectsHelper helper = new BinaryObjectsHelper();
+
+        createDatabase(TEST_LONGVARBINARY_MODEL);
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1), helper.serialize(value) });
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2), null });
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals(value,        beans.get(0), "VALUE");
+        assertEquals((Object)null, beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a simple BLOB column.
+     */
+    public void testBlob()
+    {
+        HashMap value = new HashMap();
+
+        value.put("test1", "some value");
+        value.put(null, "some other value");
+
+        BinaryObjectsHelper helper = new BinaryObjectsHelper();
+
+        createDatabase(TEST_BLOB_MODEL);
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1), helper.serialize(value) });
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2), null });
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals(value,        beans.get(0), "VALUE");
+        assertEquals((Object)null, beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a simple CLOB column.
+     */
+    public void testClob()
+    {
+        String value = "1234567890123456789012345678901234567890123456789012345678901234"+
+                       "1234567890123456789012345678901234567890123456789012345678901234"+
+                       "1234567890123456789012345678901234567890123456789012345678901234"+
+                       "1234567890123456789012345678901234567890123456789012345678901234";
+
+        createDatabase(TEST_CLOB_MODEL);
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1), null });
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2), value });
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals((Object)null,  beans.get(0), "VALUE");
+        assertEquals((Object)value, beans.get(1), "VALUE");
 
         assertEquals(getAdjustedModel(),
                      getPlatform().readModelFromDatabase("roundtriptest"));



Mime
View raw message