Author: tomdz
Date: Tue Dec 20 15:47:37 2005
New Revision: 358149
URL: http://svn.apache.org/viewcvs?rev=358149&view=rev
Log:
More/fixed 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=358149&r1=358148&r2=358149&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
Tue Dec 20 15:47:37 2005
@@ -20,6 +20,7 @@
import org.apache.commons.beanutils.DynaBean;
import org.apache.ddlutils.TestDatabaseWriterBase;
+import org.apache.ddlutils.model.Column;
import org.apache.ddlutils.model.IndexColumn;
import org.apache.ddlutils.model.Table;
import org.apache.ddlutils.model.UniqueIndex;
@@ -47,7 +48,7 @@
"<database name='roundtriptest'>\n"+
" <table name='ROUNDTRIP'>\n"+
" <column name='PK' type='INTEGER' primaryKey='true'
required='true'/>\n"+
- " <column name='VALUE' type='BIT' default='FALSE'/>\n"+
+ " <column name='VALUE' type='BIT' required='true'
default='FALSE'/>\n"+
" </table>\n"+
"</database>";
/** Test model with a simple BOOLEAN column. */
@@ -59,6 +60,15 @@
" <column name='VALUE' type='BOOLEAN'/>\n"+
" </table>\n"+
"</database>";
+ /** Test model with a BOOLEAN column with a default value. */
+ protected static final String TEST_BOOLEAN_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='BOOLEAN' required='true'
default='TRUE'/>\n"+
+ " </table>\n"+
+ "</database>";
/**
* Inserts a row into the designated table.
@@ -73,7 +83,9 @@
for (int idx = 0; (idx < table.getColumnCount()) && (idx <
columnValues.length); idx++)
{
- bean.set(table.getColumn(idx).getName(), columnValues[idx]);
+ Column column = table.getColumn(idx);
+
+ bean.set(column.getName(), columnValues[idx]);
}
getPlatform().insert(getModel(), bean);
}
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=358149&r1=358148&r2=358149&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
Tue Dec 20 15:47:37 2005
@@ -6,6 +6,9 @@
/**
* Performs the roundtrip test against a derby database.
+ *
+ * @author Thomas Dudziak
+ * @version $Revision: 289996 $
*/
public class TestRoundtripDerby extends RoundtripTestBase
{
@@ -58,6 +61,7 @@
// Derby does not have a boolean type, so it gets mapped to SMALLINT
// we therefore adjust the original model according to our expectations
getModel().getTable(0).getColumn(1).setType("SMALLINT");
+ getModel().getTable(0).getColumn(1).setDefaultValue("0");
// Also we get a unique index for the PK
addPrimaryKeyUniqueIndicesToModel();
@@ -86,6 +90,35 @@
// Derby does not have a boolean type, so it gets mapped to SMALLINT
// we therefore adjust the original model according to our expectations
getModel().getTable(0).getColumn(1).setType("SMALLINT");
+
+ // Also we get a unique index for the PK
+ addPrimaryKeyUniqueIndicesToModel();
+
+ assertEquals(getModel(), db);
+ }
+
+ /**
+ * Tests a BOOLEAN column with a default value.
+ */
+ public void testBooleanWithDefault()
+ {
+ createDatabase(TEST_BOOLEAN_MODEL_WITH_DEFAULT);
+ insertRow("ROUNDTRIP", new Object[] { new Integer(1), Boolean.TRUE });
+ insertRow("ROUNDTRIP", new Object[] { new Integer(2) });
+
+ List beans = getRows("ROUNDTRIP");
+
+ assertEquals(Boolean.TRUE, beans.get(0), "VALUE");
+ assertEquals(Boolean.TRUE, beans.get(1), "VALUE");
+
+ Database db = getPlatform().readModelFromDatabase();
+
+ db.setName("roundtriptest");
+
+ // Derby does not have a boolean type, so it gets mapped to SMALLINT
+ // we therefore adjust the original model according to our expectations
+ getModel().getTable(0).getColumn(1).setType("SMALLINT");
+ getModel().getTable(0).getColumn(1).setDefaultValue("1");
// Also we get a unique index for the PK
addPrimaryKeyUniqueIndicesToModel();