Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DbUnit - Warning: AbstractTableMetaData

I am using DbUnit in the latest version 2.4.8 and I get many warnings in my Unit tests with this message:

WARN : org.dbunit.dataset.AbstractTableMetaData - 
Potential problem found: The configured data type factory 
    'class org.dbunit.dataset.datatype.DefaultDataTypeFactory' 
     might cause problems with the current database 'MySQL' (e.g. some datatypes may 
     not be supported properly). In rare cases you might see this message because the 
     list of supported database products is incomplete (list=[derby]). If so please 
     request a java-class update via the forums.If you are using your own 
     IDataTypeFactory extending DefaultDataTypeFactory, ensure that you override 
     getValidDbProducts() to specify the supported database products.

So I thought I add this (I use a MySQL database):

protected void setUpDatabaseConfig(DatabaseConfig config) {
    config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new MySqlDataTypeFactory());
}

But this does not help to avoid these warnings. What's wrong here?

Thank you in advance & Best Regards Tim.

like image 901
Tim Avatar asked Oct 15 '10 14:10

Tim


2 Answers

I solved this with info from the dbunit faq. Just setting the data type factory property made the warning go away.

    Connection dbConn = template.getDataSource().getConnection();

    IDatabaseConnection connection = new DatabaseConnection(dbConn, "UTEST", false);

    DatabaseConfig dbConfig = connection.getConfig();

    // added this line to get rid of the warning
    dbConfig.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new OracleDataTypeFactory());
like image 106
reassembler Avatar answered Oct 08 '22 18:10

reassembler


With Spring-Boot you can use such configuration bean

@Configuration
public class DbUnitConfiguration {

@Autowired
private DataSource dataSource;

@Bean
public DatabaseDataSourceConnectionFactoryBean dbUnitDatabaseConnection() {
    DatabaseConfigBean bean = new DatabaseConfigBean();
    bean.setDatatypeFactory(new MySqlDataTypeFactory());

    DatabaseDataSourceConnectionFactoryBean dbConnectionFactory = new DatabaseDataSourceConnectionFactoryBean(dataSource);
    dbConnectionFactory.setDatabaseConfig(bean);
    return dbConnectionFactory;
    }
}
like image 37
panser Avatar answered Oct 08 '22 18:10

panser