Monday, February 26, 2007

DBUnit and RDMS with special types

If you are using DBUnit for testing your data access layer, and your scheme uses some unusual data types, you need to use data type factories but it won't work if you are about to use at the same time FlatXmlDataSet.
You are going to get errors like:
WARNING - table_name.column_name data type (1111, ëbití) not recognized and will be ignored. See FAQ for more information.
Here is solution that I haven't found on google:
Override default implementation of protected IDatabaseTester newDatabaseTester() throws Exception from DBTestCase to something like this:

protected IDatabaseTester newDatabaseTester() throws Exception {
return new PropertiesBasedJdbcDatabaseTester() {
public IDatabaseConnection getConnection() throws Exception {
IDatabaseConnection databaseConnection = super.getConnection();
DatabaseConfig databaseConfig = databaseConnection.getConfig();
databaseConfig.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new MySqlDataTypeFactory());
return databaseConnection;
}
};
}



Where you should use suitable for your database DataTypeFactory.