You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ddlutils-dev@db.apache.org by to...@apache.org on 2005/12/25 13:24:40 UTC
svn commit: r358971 - in /db/ddlutils/trunk/src/test/org/apache/ddlutils/io:
RoundtripTestBase.java TestRoundtripDerby.java
Author: tomdz
Date: Sun Dec 25 04:24:35 2005
New Revision: 358971
URL: http://svn.apache.org/viewcvs?rev=358971&view=rev
Log:
Simplified 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=358971&r1=358970&r2=358971&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 04:24:35 2005
@@ -21,9 +21,11 @@
import org.apache.commons.beanutils.DynaBean;
import org.apache.ddlutils.TestDatabaseWriterBase;
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.UniqueIndex;
+import org.apache.ddlutils.platform.DefaultValueHelper;
/**
* Base class for database roundtrip (creation & reconstruction from the database).
@@ -248,7 +250,61 @@
table.addIndex(index);
}
}
+
+ /**
+ * Specifies whether the platform has unique indices for pks in the model
+ * read back from the database.
+ *
+ * @return <code>true</code> if there will be unique indices for pks in read-back models
+ */
+ protected abstract boolean hasPkUniqueIndices();
+ /**
+ * Returns the original model adjusted for type changes because of the native type mappings
+ * which when read back from the database will map to different types.
+ *
+ * @return The adjusted model
+ */
+ protected Database getAdjustedModel()
+ {
+ try
+ {
+ Database model = (Database)getModel().clone();
+
+ for (int tableIdx = 0; tableIdx < model.getTableCount(); tableIdx++)
+ {
+ Table table = model.getTable(tableIdx);
+
+ for (int columnIdx = 0; columnIdx < table.getColumnCount(); columnIdx++)
+ {
+ Column column = table.getColumn(columnIdx);
+ int origType = column.getTypeCode();
+ int targetType = getPlatformInfo().getTargetJdbcType(origType);
+
+ if (targetType != origType)
+ {
+ column.setTypeCode(targetType);
+ if (column.getDefaultValue() != null)
+ {
+ DefaultValueHelper helper = getPlatform().getSqlBuilder().getDefaultValueHelper();
+
+ column.setDefaultValue(helper.convert(column.getDefaultValue(), origType, targetType));
+ }
+ }
+ }
+ }
+ if (hasPkUniqueIndices())
+ {
+ addPrimaryKeyUniqueIndicesToModel();
+ }
+ return model;
+ }
+ catch (CloneNotSupportedException ex)
+ {
+ throw new RuntimeException(ex);
+ }
+ }
+
/**
* Compares the attribute value of the given bean to the expected object.
*
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=358971&r1=358970&r2=358971&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 04:24:35 2005
@@ -2,8 +2,6 @@
import java.util.List;
-import org.apache.ddlutils.model.Database;
-
/**
* Performs the roundtrip test against a derby database.
*
@@ -13,6 +11,14 @@
public class TestRoundtripDerby extends RoundtripTestBase
{
/**
+ * {@inheritDoc}
+ */
+ protected boolean hasPkUniqueIndices()
+ {
+ return true;
+ }
+
+ /**
* Tests a simple BIT column.
*/
public void testBit()
@@ -26,18 +32,8 @@
assertEquals(Boolean.TRUE, beans.get(0), "VALUE");
assertEquals(Boolean.FALSE, 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");
-
- // Also we get a unique index for the PK
- addPrimaryKeyUniqueIndicesToModel();
-
- assertEquals(getModel(), db);
+ assertEquals(getAdjustedModel(),
+ getPlatform().readModelFromDatabase("roundtriptest"));
}
/**
@@ -54,19 +50,8 @@
assertEquals(Boolean.FALSE, 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("0");
-
- // Also we get a unique index for the PK
- addPrimaryKeyUniqueIndicesToModel();
-
- assertEquals(getModel(), db);
+ assertEquals(getAdjustedModel(),
+ getPlatform().readModelFromDatabase("roundtriptest"));
}
/**
@@ -83,18 +68,8 @@
assertEquals(Boolean.FALSE, 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");
-
- // Also we get a unique index for the PK
- addPrimaryKeyUniqueIndicesToModel();
-
- assertEquals(getModel(), db);
+ assertEquals(getAdjustedModel(),
+ getPlatform().readModelFromDatabase("roundtriptest"));
}
/**
@@ -111,19 +86,8 @@
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();
-
- assertEquals(getModel(), db);
+ assertEquals(getAdjustedModel(),
+ getPlatform().readModelFromDatabase("roundtriptest"));
}
/**
@@ -143,18 +107,8 @@
assertEquals(new Integer(254), beans.get(0), "VALUE");
assertEquals(new Integer(-254), beans.get(1), "VALUE");
- Database db = getPlatform().readModelFromDatabase();
-
- db.setName("roundtriptest");
-
- // Derby does not have a TINYINT 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);
+ assertEquals(getAdjustedModel(),
+ getPlatform().readModelFromDatabase("roundtriptest"));
}
/**
@@ -171,18 +125,8 @@
assertEquals(new Integer(128), beans.get(0), "VALUE");
assertEquals(new Integer(-200), beans.get(1), "VALUE");
- Database db = getPlatform().readModelFromDatabase();
-
- db.setName("roundtriptest");
-
- // Derby does not have a TINYINT 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);
+ assertEquals(getAdjustedModel(),
+ getPlatform().readModelFromDatabase("roundtriptest"));
}
/**
@@ -200,14 +144,8 @@
assertEquals(new Integer(-32768), beans.get(0), "VALUE");
assertEquals(new Integer(32767), beans.get(1), "VALUE");
- Database db = getPlatform().readModelFromDatabase();
-
- db.setName("roundtriptest");
-
- // Also we get a unique index for the PK
- addPrimaryKeyUniqueIndicesToModel();
-
- assertEquals(getModel(), db);
+ assertEquals(getAdjustedModel(),
+ getPlatform().readModelFromDatabase("roundtriptest"));
}
/**
@@ -224,14 +162,8 @@
assertEquals(new Integer(256), beans.get(0), "VALUE");
assertEquals(new Integer(-32768), beans.get(1), "VALUE");
- Database db = getPlatform().readModelFromDatabase();
-
- db.setName("roundtriptest");
-
- // Also we get a unique index for the PK
- addPrimaryKeyUniqueIndicesToModel();
-
- assertEquals(getModel(), db);
+ assertEquals(getAdjustedModel(),
+ getPlatform().readModelFromDatabase("roundtriptest"));
}
/**
@@ -249,14 +181,8 @@
assertEquals(new Integer(0), beans.get(0), "VALUE");
assertEquals(new Integer(-2147483648), beans.get(1), "VALUE");
- Database db = getPlatform().readModelFromDatabase();
-
- db.setName("roundtriptest");
-
- // Also we get a unique index for the PK
- addPrimaryKeyUniqueIndicesToModel();
-
- assertEquals(getModel(), db);
+ assertEquals(getAdjustedModel(),
+ getPlatform().readModelFromDatabase("roundtriptest"));
}
/**
@@ -273,14 +199,8 @@
assertEquals(new Integer(2147483647), beans.get(0), "VALUE");
assertEquals(new Integer(2147483646), beans.get(1), "VALUE");
- Database db = getPlatform().readModelFromDatabase();
-
- db.setName("roundtriptest");
-
- // Also we get a unique index for the PK
- addPrimaryKeyUniqueIndicesToModel();
-
- assertEquals(getModel(), db);
+ assertEquals(getAdjustedModel(),
+ getPlatform().readModelFromDatabase("roundtriptest"));
}
/**
@@ -298,14 +218,8 @@
assertEquals(new Long(9223372036854775807l), beans.get(0), "VALUE");
assertEquals(new Long(0l), beans.get(1), "VALUE");
- Database db = getPlatform().readModelFromDatabase();
-
- db.setName("roundtriptest");
-
- // Also we get a unique index for the PK
- addPrimaryKeyUniqueIndicesToModel();
-
- assertEquals(getModel(), db);
+ assertEquals(getAdjustedModel(),
+ getPlatform().readModelFromDatabase("roundtriptest"));
}
/**
@@ -322,14 +236,8 @@
assertEquals(new Long(-9223372036854775808l), beans.get(0), "VALUE");
assertEquals(new Long(-1l), beans.get(1), "VALUE");
- Database db = getPlatform().readModelFromDatabase();
-
- db.setName("roundtriptest");
-
- // Also we get a unique index for the PK
- addPrimaryKeyUniqueIndicesToModel();
-
- assertEquals(getModel(), db);
+ assertEquals(getAdjustedModel(),
+ getPlatform().readModelFromDatabase("roundtriptest"));
}
/**
@@ -347,14 +255,8 @@
assertEquals(new Float(123456789.98765f), beans.get(0), "VALUE");
assertEquals(new Float(0.0f), beans.get(1), "VALUE");
- Database db = getPlatform().readModelFromDatabase();
-
- db.setName("roundtriptest");
-
- // Also we get a unique index for the PK
- addPrimaryKeyUniqueIndicesToModel();
-
- assertEquals(getModel(), db);
+ assertEquals(getAdjustedModel(),
+ getPlatform().readModelFromDatabase("roundtriptest"));
}
/**
@@ -371,14 +273,8 @@
assertEquals(new Float(1e+20f), beans.get(0), "VALUE");
assertEquals(new Float(-1.0123456f), beans.get(1), "VALUE");
- Database db = getPlatform().readModelFromDatabase();
-
- db.setName("roundtriptest");
-
- // Also we get a unique index for the PK
- addPrimaryKeyUniqueIndicesToModel();
-
- assertEquals(getModel(), db);
+ assertEquals(getAdjustedModel(),
+ getPlatform().readModelFromDatabase("roundtriptest"));
}
/**
@@ -396,17 +292,8 @@
assertEquals(new Double(-1.0), beans.get(0), "VALUE");
assertEquals(new Double(Float.MIN_VALUE), beans.get(1), "VALUE");
- Database db = getPlatform().readModelFromDatabase();
-
- db.setName("roundtriptest");
-
- // DOUBLE PRECISION gets mapped back to DOUBLE (which is the same type really)
- getModel().getTable(0).getColumn(1).setType("DOUBLE");
-
- // Also we get a unique index for the PK
- addPrimaryKeyUniqueIndicesToModel();
-
- assertEquals(getModel(), db);
+ assertEquals(getAdjustedModel(),
+ getPlatform().readModelFromDatabase("roundtriptest"));
}
/**
@@ -423,17 +310,8 @@
assertEquals(new Double(1234567890.012345678901234), beans.get(0), "VALUE");
assertEquals(new Double(1e+150), beans.get(1), "VALUE");
- Database db = getPlatform().readModelFromDatabase();
-
- db.setName("roundtriptest");
-
- // DOUBLE PRECISION gets mapped back to DOUBLE (which is the same type really)
- getModel().getTable(0).getColumn(1).setType("DOUBLE");
-
- // Also we get a unique index for the PK
- addPrimaryKeyUniqueIndicesToModel();
-
- assertEquals(getModel(), db);
+ assertEquals(getAdjustedModel(),
+ getPlatform().readModelFromDatabase("roundtriptest"));
}
/**
@@ -451,14 +329,8 @@
assertEquals(new Double(Float.MAX_VALUE), beans.get(0), "VALUE");
assertEquals(new Double(1.01), beans.get(1), "VALUE");
- Database db = getPlatform().readModelFromDatabase();
-
- db.setName("roundtriptest");
-
- // Also we get a unique index for the PK
- addPrimaryKeyUniqueIndicesToModel();
-
- assertEquals(getModel(), db);
+ assertEquals(getAdjustedModel(),
+ getPlatform().readModelFromDatabase("roundtriptest"));
}
/**
@@ -475,13 +347,7 @@
assertEquals(new Double(-1e+150), beans.get(0), "VALUE");
assertEquals(new Double(-9876543210.987654321098765), beans.get(1), "VALUE");
- Database db = getPlatform().readModelFromDatabase();
-
- db.setName("roundtriptest");
-
- // Also we get a unique index for the PK
- addPrimaryKeyUniqueIndicesToModel();
-
- assertEquals(getModel(), db);
+ assertEquals(getAdjustedModel(),
+ getPlatform().readModelFromDatabase("roundtriptest"));
}
}