Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package de.patrickgotthard.newsreadr.server.test;
import javax.sql.DataSource;
import org.dbunit.ext.h2.H2DataTypeFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import com.github.springtestdbunit.bean.DatabaseConfigBean;
import com.github.springtestdbunit.bean.DatabaseDataSourceConnectionFactoryBean;
import de.patrickgotthard.newsreadr.server.config.ApplicationConfig;
@Configuration
@Import(ApplicationConfig.class)
public class TestConfig {
/** Overrides the dataSource configured in {@link ApplicationConfig}. */
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).build();
}
@Bean
public DatabaseConfigBean dbUnitDatabaseConfig() {
final DatabaseConfigBean bean = new DatabaseConfigBean();
bean.setDatatypeFactory(new H2DataTypeFactory());
return bean;
}
@Bean
public DatabaseDataSourceConnectionFactoryBean dbUnitDatabaseConnection() {
final DatabaseDataSourceConnectionFactoryBean bean = new DatabaseDataSourceConnectionFactoryBean(dataSource());
bean.setDatabaseConfig(dbUnitDatabaseConfig());
return bean;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.