Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. @Configuration
  2. @EnableJpaRepositories(basePackages = "com.repository")
  3. @EntityScan(basePackages = {"com.insurance.*"})
  4. @EnableTransactionManagement
  5. @Slf4j
  6. public class TestConfig {
  7. @Bean
  8. public DataSource dataSource() throws IOException {
  9. return embeddedPostgres().getPostgresDatabase();
  10. }
  11.  
  12. @Bean
  13. public EmbeddedPostgres embeddedPostgres() throws IOException {
  14. return EmbeddedPostgres.start();
  15. }
  16.  
  17. @Bean
  18. public HibernateExceptionTranslator hibernateExceptionTranslator() {
  19. return new HibernateExceptionTranslator();
  20. }
  21.  
  22. @Bean
  23. public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
  24. JpaTransactionManager transactionManager = new JpaTransactionManager();
  25. transactionManager.setEntityManagerFactory(emf);
  26. return transactionManager;
  27. }
  28.  
  29. @Bean
  30. public JdbcTemplate jdbcTemplate(DataSource dataSource) throws IOException {
  31. return new JdbcTemplate(dataSource);
  32. }
  33.  
  34. @Bean
  35. public Flyway flyway() throws IOException {
  36. Flyway flyway = new Flyway();
  37. flyway.setDataSource(dataSource());
  38. flyway.setLocations("db/migration");
  39. flyway.migrate();
  40. return flyway;
  41. }
  42. }
  43.  
  44. <dependency>
  45. <groupId>com.opentable.components</groupId>
  46. <artifactId>otj-pg-embedded</artifactId>
  47. <version>0.10.0</version>
  48. <scope>test</scope>
  49. </dependency>
  50. <dependency>
  51. <groupId>org.flywaydb</groupId>
  52. <artifactId>flyway-core</artifactId>
  53. </dependency>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement