db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r358998 - in /db/ddlutils/trunk/src/test/org/apache/ddlutils/io: RoundtripTestBase.java TestRoundtripDerby.java
Date Sun, 25 Dec 2005 18:30:47 GMT
Author: tomdz
Date: Sun Dec 25 10:30:44 2005
New Revision: 358998

URL: http://svn.apache.org/viewcvs?rev=358998&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=358998&r1=358997&r2=358998&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 Sun Dec 25 10:30:44
2005
@@ -197,6 +197,114 @@
         "    <column name='VALUE' type='DOUBLE' required='true' default='-9876543210.987654321098765'/>\n"+
         "  </table>\n"+
         "</database>";
+    /** Test model with a simple DECIMAL column. */
+    protected static final String TEST_DECIMAL_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='DECIMAL' size='15'/>\n"+
+        "  </table>\n"+
+        "</database>";
+    /** Test model with a DECIMAL column with a default value. */
+    protected static final String TEST_DECIMAL_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='DECIMAL' size='15' required='true' default='123456789012345'/>\n"+
+        "  </table>\n"+
+        "</database>";
+    /** Test model with a simple DECIMAL column with a scale. */
+    protected static final String TEST_DECIMAL_MODEL_WITH_SCALE = 
+        "<?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='DECIMAL' size='15,7'/>\n"+
+        "  </table>\n"+
+        "</database>";
+    /** Test model with a DECIMAL column with a scale and default value. */
+    protected static final String TEST_DECIMAL_MODEL_WITH_SCALE_AND_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='DECIMAL' size='15,7' required='true' default='12345678.7654321'/>\n"+
+        "  </table>\n"+
+        "</database>";
+    /** Test model with a simple NUMERIC column. */
+    protected static final String TEST_NUMERIC_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='NUMERIC' size='15'/>\n"+
+        "  </table>\n"+
+        "</database>";
+    /** Test model with a NUMERIC column with a default value. */
+    protected static final String TEST_NUMERIC_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='NUMERIC' size='15' required='true' default='-123456789012345'/>\n"+
+        "  </table>\n"+
+        "</database>";
+    /** Test model with a simple NUMERIC column with a scale. */
+    protected static final String TEST_NUMERIC_MODEL_WITH_SCALE = 
+        "<?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='NUMERIC' size='15,8'/>\n"+
+        "  </table>\n"+
+        "</database>";
+    /** Test model with a NUMERIC column with a scale and default value. */
+    protected static final String TEST_NUMERIC_MODEL_WITH_SCALE_AND_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='NUMERIC' size='15,8' required='true' default='-1234567.87654321'/>\n"+
+        "  </table>\n"+
+        "</database>";
+    /** Test model with a simple CHAR column. */
+    protected static final String TEST_CHAR_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='CHAR' size='10'/>\n"+
+        "  </table>\n"+
+        "</database>";
+    /** Test model with a CHAR column with a default value. */
+    protected static final String TEST_CHAR_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='CHAR' size='15' required='true' default='some
value'/>\n"+
+        "  </table>\n"+
+        "</database>";
+    /** Test model with a simple VARCHAR column. */
+    protected static final String TEST_VARCHAR_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='VARCHAR' size='20'/>\n"+
+        "  </table>\n"+
+        "</database>";
+    /** Test model with a VARCHAR column with a default value. */
+    protected static final String TEST_VARCHAR_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='VARCHAR' required='true' default='some value'/>\n"+
+        "  </table>\n"+
+        "</database>";
 
     /**
      * Inserts a row into the designated table.
@@ -281,9 +389,12 @@
                     int    origType   = column.getTypeCode();
                     int    targetType = getPlatformInfo().getTargetJdbcType(origType);
 
+                    // we adjust the column types if the native type would back-map to a
+                    // different jdbc type
                     if (targetType != origType)
                     {
                         column.setTypeCode(targetType);
+                        // we should also adapt the default value
                         if (column.getDefaultValue() != null)
                         {
                             DefaultValueHelper helper = getPlatform().getSqlBuilder().getDefaultValueHelper();
@@ -320,13 +431,6 @@
                      dynaBean.get(attrName));
     }
 
-    // simple boolean
-    // boolean with default value
-    // simple bit
-    // bit with default value
-    
-    // numerical columns
-    // numeric/decimal incl. precision/scale
     // char/varchar columns incl. different sizes
     // time columns
     // binary/varbinary & java_object etc. columns

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=358998&r1=358997&r2=358998&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 Sun Dec 25 10:30:44
2005
@@ -1,5 +1,6 @@
 package org.apache.ddlutils.io;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 /**
@@ -346,6 +347,232 @@
 
         assertEquals(new Double(-1e+150),                     beans.get(0), "VALUE");
         assertEquals(new Double(-9876543210.987654321098765), beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a simple DECIMAL column.
+     */
+    public void testDecimal()
+    {
+        createDatabase(TEST_DECIMAL_MODEL);
+
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1), new BigDecimal("0") });
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2), new BigDecimal("-123456789012345")
});
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals(new BigDecimal("0"),                beans.get(0), "VALUE");
+        assertEquals(new BigDecimal("-123456789012345"), beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a DECIMAL column with a default value.
+     */
+    public void testDecimalWithDefault()
+    {
+        createDatabase(TEST_DECIMAL_MODEL_WITH_DEFAULT);
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1) });
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2), new BigDecimal("-1") });
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals(new BigDecimal("123456789012345"), beans.get(0), "VALUE");
+        assertEquals(new BigDecimal("-1"),              beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a simple DECIMAL column with a scale.
+     */
+    public void testDecimalWithScale()
+    {
+        createDatabase(TEST_DECIMAL_MODEL_WITH_SCALE);
+
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1), new BigDecimal("0.0100000")
});
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2), new BigDecimal("-87654321.1234567")
});
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals(new BigDecimal("0.0100000"),         beans.get(0), "VALUE");
+        assertEquals(new BigDecimal("-87654321.1234567"), beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a DECIMAL column with a scale and default value.
+     */
+    public void testDecimalWithScaleAndDefault()
+    {
+        createDatabase(TEST_DECIMAL_MODEL_WITH_SCALE_AND_DEFAULT);
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1), new BigDecimal("1.0000000")
});
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2) });
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals(new BigDecimal("1.0000000"),        beans.get(0), "VALUE");
+        assertEquals(new BigDecimal("12345678.7654321"), beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a simple NUMERIC column.
+     */
+    public void testNumeric()
+    {
+        createDatabase(TEST_NUMERIC_MODEL);
+
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1), new BigDecimal("543210987654321")
});
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2), new BigDecimal("-2") });
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals(new BigDecimal("543210987654321"), beans.get(0), "VALUE");
+        assertEquals(new BigDecimal("-2"),              beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a NUMERIC column with a default value.
+     */
+    public void testNumericWithDefault()
+    {
+        createDatabase(TEST_NUMERIC_MODEL_WITH_DEFAULT);
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1) });
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2), new BigDecimal("100") });
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals(new BigDecimal("-123456789012345"), beans.get(0), "VALUE");
+        assertEquals(new BigDecimal("100"),              beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a simple NUMERIC column with a scale.
+     */
+    public void testNumericWithScale()
+    {
+        createDatabase(TEST_NUMERIC_MODEL_WITH_SCALE);
+
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1), new BigDecimal("1234567.89012345")
});
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2), new BigDecimal("1.00000000")
});
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals(new BigDecimal("1234567.89012345"), beans.get(0), "VALUE");
+        assertEquals(new BigDecimal("1.00000000"),       beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a NUMERIC column with a scale and default value.
+     */
+    public void testNumericWithScaleAndDefault()
+    {
+        createDatabase(TEST_NUMERIC_MODEL_WITH_SCALE_AND_DEFAULT);
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1) });
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2), new BigDecimal("1e-8") });
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals(new BigDecimal("-1234567.87654321"), beans.get(0), "VALUE");
+        assertEquals(new BigDecimal("1e-8"),              beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a simple CHAR column.
+     */
+    public void testChar()
+    {
+        createDatabase(TEST_CHAR_MODEL);
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1), null });
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2), "1234567890" });
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals((Object)null,         beans.get(0), "VALUE");
+        assertEquals((Object)"1234567890", beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a CHAR column with a default value.
+     */
+    public void testCharWithDefault()
+    {
+        createDatabase(TEST_CHAR_MODEL_WITH_DEFAULT);
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1) });
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2), "12345" });
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals((Object)"some value     ", beans.get(0), "VALUE");
+        assertEquals((Object)"12345          ", beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a simple VARCHAR column.
+     */
+    public void testVarChar()
+    {
+        createDatabase(TEST_VARCHAR_MODEL);
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1), "123456789012345678" });
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2), null });
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals((Object)"123456789012345678", beans.get(0), "VALUE");
+        assertEquals((Object)null,                 beans.get(1), "VALUE");
+
+        assertEquals(getAdjustedModel(),
+                     getPlatform().readModelFromDatabase("roundtriptest"));
+    }
+
+    /**
+     * Tests a VARCHAR column with a default value.
+     */
+    public void testVarCharWithDefault()
+    {
+        createDatabase(TEST_VARCHAR_MODEL_WITH_DEFAULT);
+        insertRow("ROUNDTRIP", new Object[] { new Integer(1) });
+        insertRow("ROUNDTRIP", new Object[] { new Integer(2), "1234567890123456789012345678901234567890123456789012345678901234"+
+                                                              "1234567890123456789012345678901234567890123456789012345678901234"+
+                                                              "1234567890123456789012345678901234567890123456789012345678901234"+
+                                                              "12345678901234567890123456789012345678901234567890123456789012"});
+
+        List beans = getRows("ROUNDTRIP");
+
+        assertEquals((Object)"some value", beans.get(0), "VALUE");
+        assertEquals((Object)("1234567890123456789012345678901234567890123456789012345678901234"+
+                              "1234567890123456789012345678901234567890123456789012345678901234"+
+                              "1234567890123456789012345678901234567890123456789012345678901234"+
+                              "12345678901234567890123456789012345678901234567890123456789012"),
beans.get(1), "VALUE");
 
         assertEquals(getAdjustedModel(),
                      getPlatform().readModelFromDatabase("roundtriptest"));



Mime
View raw message