Q:

How to set default properties in spring dataset DatabaseConfig

I am using springtestdbunit for writing test cases for my repository/dao.
I am populating data using db scripts and then matching with expected-sql-scripts.
I want to set escape character for my sample sql scripts.
My sample test class looks like this
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class,
DirtiesContextTestExecutionListener.class,
TransactionalTestExecutionListener.class,
DbUnitTestExecutionListener.class})
@DbUnitConfiguration(dataSetLoader = ReplacementDataSetLoader.class)
@DatabaseSetup({"notification-init.xml"})
@SpringBootTest(classes = {TestApplication.class, DaoConfig.class})
public class NotificationRepositoryTest {

@Autowired
private NotificationRepository notificationRepository;

@After
@DatabaseTearDown
public void tearDown() throws Exception {

}

@Before
public void setUp() throws Exception {
    //donorModel = donorRepository.findOne(0L);
}

All I want to set these two properties when I am configuring my H2 database.
DatabaseConfig.PROPERTY_ESCAPE_PATTERN
DatabaseConfig.FEATURE_ALLOW_EMPTY_FIELDS

A:

Here is an example from a spring boot project using JavaConfig to set those 2 properties:
@Configuration
@Profile("test")
public class DBUnitConfiguration {

    @Bean
    public DatabaseConfigBean dbUnitDatabaseConfig() {
        DatabaseConfigBean bean = new DatabaseConfigBean();
        bean.setAllowEmptyFields(true);
        bean.setEscapePattern("\"?\"");
        return bean;
    }

    @Bean
    public DatabaseDataSourceConnectionFactoryBean dbUnitDatabaseConnection(
            DatabaseConfigBean dbUnitDatabaseConfig,
            DataSource dataSource
    ) {
        DatabaseDataSourceConnectionFactoryBean bean = new DatabaseDataSourceConnectionFactoryBean(dataSource);
        bean.setDatabaseConfig(dbUnitDatabaseConfig);
        return bean;
    }
}

It requires 1.3.0 version of spring-test-dbunit to set the ALLOW_EMPTY_FIELDS prop:
<dependency>
    <groupId>com.github.springtestdbunit</groupId>
    <artifactId>spring-test-dbunit</artifactId>
    <version>1.3.0</version>
    <scope>test</scope>
</dependency>

