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

Allow database assertion to be defined as a bean #117

Open mikebl71 opened 8 years ago

mikebl71 commented 8 years ago

Problem to solve: I would like to implement a custom logic for validating actual vs expected datasets. Spring-dbunit uses DatabaseAssertion objects for such validations. However, at present, the ExpectedDatabase annotation only accepts DatabaseAssertionMode. But DatabaseAssertionMode is an enum, which means that I cannot extend it in my project.

Proposed solution: Similar to how you have "dataSetLoader" and "dataSetLoaderBean" elements in DbUnitConfiguration, I've added an "assertionBean" element to ExpectedDatabase. So now I can define any database assertion I like as a bean and refer to it in the annotation.

Example:

@Bean
public DatabaseAssertion dbAssertion() {
    return new CustomDatabaseAssertion();
}

@Test
@ExpectedDatabase(value = "classpath:/datasets/Expected.xml",
        assertionBean = "dbAssertion")
public void test() throws Exception {
    ....

Toilal commented 8 years ago

It would be great to also define the default assertion bean.

Toilal commented 8 years ago

Thanks for your pull request. I've create another one, more complete because it also allow to defined default assertion bean and/or class.

https://github.com/springtestdbunit/spring-test-dbunit/pull/120