Closed jceloi closed 8 years ago
I made a comment regarding this issue on link https://github.com/springtestdbunit/spring-test-dbunit/issues/63. @philwebb could you please tell us if my comment was right, or if there actually is a way to configure it. If not please tell me so that I can push a pull-request with a fix. Thanks.
@jceloi I finally managed to get it work as following :
Spring configuration :
@Bean(name = "dbUnitDatabaseConfig")
public DatabaseConfigBean getDatabaseConfigBean() {
DatabaseConfigBean databaseConfigBean = new DatabaseConfigBean();
databaseConfigBean.setFetchSize(1000);
// HSQL
final HsqldbDataTypeFactory dataTypeFactory = new HsqldbDataTypeFactory();
databaseConfigBean.setDatatypeFactory(dataTypeFactory);
return databaseConfigBean;
}
// Bean name to reference in your <@DbUnitConfiguration>
@Bean(name = "dbUnitDatabaseConnection")
public DatabaseDataSourceConnectionFactoryBean getDatabaseDataSourceConnectionFactoryBean() throws IOException, URISyntaxException {
DatabaseDataSourceConnectionFactoryBean databaseConfigBean = new DatabaseDataSourceConnectionFactoryBean();
databaseConfigBean.setDatabaseConfig(getDatabaseConfigBean());
databaseConfigBean.setDataSource(getMyDataSource());
// databaseConfigBean.setSchema("my_schema");
return databaseConfigBean;
}
Unit test class : (key-words are : databaseConnection = "dbUnitDatabaseConnection")
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class, DbUnitTestExecutionListener.class})
@DbUnitConfiguration(databaseConnection = "dbUnitDatabaseConnection")
public class MyDaoRepositoryTest {
}
Thank you @Macadoshis , I'll have a look to your proposal.
On my side, I did a very quick and dirty fix, with a specific PostgresDBUnitTestExecutionListener that as a redo of the original DBUnitTestExecutionListener with a specific addition to the prepareDatabaseConnection method, specifying a DatabaseDataSourceConnectionFactoryBean with a custom DatabaseConfigBean where a custom DatatypeFactory is registered.
What you propose is basically the same, via a clean dependency injection (and that looks much better, I did not see how to achieve that :)
Hi there,
I was trying to use a specific DatabaseConfigBean in order to use a custom dataTypeFactory but according to the code I'm wondering how to have that config read and used.
From my understanding , It seems that the DbUnitTestExecutionListener doesn't support as is such a custom configuration and that I have to extend / rewrite it so as to setup the DatabaseDataSourceConnectionFactoryBean with a DatabaseConfigBean.
Am I missing something ?
Thank you !