springtestdbunit / spring-test-dbunit

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

Again the rolling back issue #85

Open rpvilao opened 8 years ago

rpvilao commented 8 years ago

Hi,

I'm pretty sure that this topic has been debated a lot of times and believe me I already reached the last google page searching for an anwser so I really have no other place to turn to.

Basically, the same old - run the whole test in a single transation and rollback everything in the end. For some reason I cannot make this happen. I believe it has to do either with configuration or me using something that it's causing the setup to fail so here it goes.

My datasource is a ComboPooledDataSource configured in a bean as usual.

My base database class (the actual ones extend from this one) has the following annotations:

@ContextConfiguration(classes = {
        SpringJpaConfig.class,
        DBUnitITConfig.class,
        DatabaseITConfig.class
},
        initializers = TestInitializer.class)
@TestExecutionListeners({
        DirtiesContextTestExecutionListener.class,
        TransactionDbUnitTestExecutionListener.class
})
@Transactional
@TransactionConfiguration(defaultRollback = true)
public abstract class BaseDatabaseIT extends BaseIT {
}

Then the BaseIT has the common configuration like:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(initializers = TestInitializer.class)
@TestExecutionListeners({
        DependencyInjectionTestExecutionListener.class
})

The DBUnitITConfig basically configures factory bean like the following:

    @Configuration
    public class DBUnitITConfig {

    @Autowired
    private DataSource dataSource;

    @Bean(name = "dbUnitDatabaseConnection")
    public DatabaseDataSourceConnectionFactoryBean getDatabaseDataSourceConnectionFactoryBean() {
        DatabaseDataSourceConnectionFactoryBean databaseDataSourceConnectionFactoryBean = new DatabaseDataSourceConnectionFactoryBean();
        databaseDataSourceConnectionFactoryBean.setDataSource(dataSource);

        IDataTypeFactory iDataTypeFactory = new MySqlDataTypeFactory();
        DatabaseConfigBean databaseConfigBean = new DatabaseConfigBean();
        databaseConfigBean.setEscapePattern("`?`");
        databaseConfigBean.setDatatypeFactory(iDataTypeFactory);

        databaseDataSourceConnectionFactoryBean.setDatabaseConfig(databaseConfigBean);

        return databaseDataSourceConnectionFactoryBean;

    }
}

It seems very straightforward so why on earth is this not working?! If anyone has a clue please point me in the right direction.

Thanks in advance, Rui