Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Configuration
- @EnableJpaRepositories(basePackages = "com.repository")
- @EntityScan(basePackages = {"com.insurance.*"})
- @EnableTransactionManagement
- @Slf4j
- public class TestConfig {
- @Bean
- public DataSource dataSource() throws IOException {
- return embeddedPostgres().getPostgresDatabase();
- }
- @Bean
- public EmbeddedPostgres embeddedPostgres() throws IOException {
- return EmbeddedPostgres.start();
- }
- @Bean
- public HibernateExceptionTranslator hibernateExceptionTranslator() {
- return new HibernateExceptionTranslator();
- }
- @Bean
- public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
- JpaTransactionManager transactionManager = new JpaTransactionManager();
- transactionManager.setEntityManagerFactory(emf);
- return transactionManager;
- }
- @Bean
- public JdbcTemplate jdbcTemplate(DataSource dataSource) throws IOException {
- return new JdbcTemplate(dataSource);
- }
- @Bean
- public Flyway flyway() throws IOException {
- Flyway flyway = new Flyway();
- flyway.setDataSource(dataSource());
- flyway.setLocations("db/migration");
- flyway.migrate();
- return flyway;
- }
- }
- <dependency>
- <groupId>com.opentable.components</groupId>
- <artifactId>otj-pg-embedded</artifactId>
- <version>0.10.0</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.flywaydb</groupId>
- <artifactId>flyway-core</artifactId>
- </dependency>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement