springtestdbunit / spring-test-dbunit

Integration between the Spring testing framework and DBUnit
http://springtestdbunit.github.com/spring-test-dbunit/
Apache License 2.0
476 stars 238 forks source link

Warn of The configured data type factory ‘class org.dbunit.dataset.datatype.DefaultDataTypeFactory’ might cause problems with the current database #63

Closed haocao closed 9 years ago

haocao commented 9 years ago

Hi Phillip, Mario. I'm trying to use spring-test-dbunit on most of my projects, it provides a lot of essential features, but it always alerts a warning in my Unit tests with this message:

Warning:
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.

I checked the source codes(using version 1.2.1), and found the warning might caused by:

DbUnitTestExecutionListener class

    private void prepareDatabaseConnection(DbUnitTestContextAdapter testContext, String[] connectionBeanNames)
            throws Exception {
        ...
        Object databaseConnection = testContext.getApplicationContext().getBean(connectionBeanNames[i]);
        if (databaseConnection instanceof DataSource) {
            databaseConnection = DatabaseDataSourceConnectionFactoryBean
                    .newConnection((DataSource) databaseConnection);
        }
        Assert.isInstanceOf(IDatabaseConnection.class, databaseConnection);
        ...
    }

So it means that the databaseConnection will be created from DatabaseDataSourceConnectionFactoryBean.newConnection, and so finally I found DatabaseDataSourceConnectionFactoryBean's getObject method:

    public DatabaseDataSourceConnection getObject() throws Exception {
        Assert.notNull(this.dataSource, "The dataSource is required");
        DatabaseDataSourceConnection dataSourceConntection = new DatabaseDataSourceConnection(
                makeTransactionAware(this.dataSource), this.schema, this.username, this.password);
        if (this.databaseConfig != null) {
            this.databaseConfig.apply(dataSourceConntection.getConfig());
        }
        return dataSourceConntection;
    }

I think the dataSourceConntection.getConfig() can't get any value, as it should be fetched from the spring's beans.

So could you help me to take a look at this issue? thanks.

haocao commented 9 years ago

Is there any response of this quesion?Thanks.

philwebb commented 9 years ago

It looks like this is related to #67. I think the warning is raised from AbstractTableMetaData because the MySql isn't explicitly supported by DefaultDataTypeFactory. I think if you configure the IDataTypeFactory as described in #67 the warning will go away.

Macadoshis commented 8 years ago
// com.github.springtestdbunit.DbUnitTestExecutionListener
private void prepareDatabaseConnection(DbUnitTestContextAdapter testContext, String[] connectionBeanNames) throws Exception {
...
  if (databaseConnection instanceof DataSource) {
    databaseConnection = DatabaseDataSourceConnectionFactoryBean
                        .newConnection((DataSource) databaseConnection);
  }
...
}

First : method prepareDatabaseConnection is private ! Second : DatabaseDataSourceConnectionFactoryBean.newConnection is static ! Third : I see no way we can tell spring-dbunit to use an overriden DatabaseDataSourceConnection. Correct design-pattern is use to fetch a custom Datasource :

testContext.getApplicationContext().getBean(connectionBeanNames[i]);
  if (databaseConnection instanceof DataSource) {
    ...
  }

but the pattern is broken to fetch a custom DatabaseDataSourceConnection. The same test should be done (look for any existant DatabaseDataSourceConnection.class bean in testContext), before instanciating the default one by calling DatabaseDataSourceConnectionFactoryBean.newConnection((DataSource) databaseConnection);.

I don't see how and where spring-dbunit use custom's beans as described in https://github.com/springtestdbunit/spring-test-dbunit/issues/67 (either xml or annotation declarations).