Guest User

Untitled

a guest
May 25th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. @RunWith(SpringJUnit4ClassRunner.class)
  2. @ContextConfiguration(classes = {ITConfig.class})
  3. @TestExecutionListeners({DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class,
  4. TransactionalTestExecutionListener.class, DbUnitTestExecutionListener.class})
  5. @DatabaseSetup("/META-INF/dbtest/db-data.xml")
  6. public class RentedRepositoryTest {
  7. @Autowired
  8. private GraphRepo rentedRepo;
  9. }
  10.  
  11. @Configuration
  12. @ComponentScan(value = "ro.ubb.stcatalog.core",
  13. excludeFilters = {@ComponentScan.Filter(value = {JPAConfig.class}, type = FilterType.ASSIGNABLE_TYPE)})
  14. @Import({JPAConfigIT.class})
  15. @PropertySources({@PropertySource(value = "classpath:db-h2.properties")})
  16. public class ITConfig {
  17.  
  18. @Bean
  19. public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
  20. return new PropertySourcesPlaceholderConfigurer();
  21. }
  22. }
  23.  
  24. @Configuration
  25. @EnableJpaRepositories("ro.ubb.stcatalog.core.repository")
  26. @EnableTransactionManagement
  27. public class JPAConfigIT {
  28.  
  29. // @Value("${db.jdbcURL}")
  30. private String jdbcURL = "";
  31.  
  32. // @Value("${db.user}")
  33. private String user = "postgres";
  34.  
  35. // @Value("${db.password}")
  36. private String password = "";
  37.  
  38. // @Value("${db.generateDDL}")
  39. private Boolean generateDDL = true;
  40.  
  41.  
  42. @Bean
  43. public DataSource dataSource() {
  44. HikariDataSource dataSource = new HikariDataSource();
  45. dataSource.setJdbcUrl(jdbcURL);
  46. dataSource.setUsername(user);
  47. dataSource.setPassword(password);
  48.  
  49. return dataSource;
  50. }
  51.  
  52. @Bean
  53. public EntityManagerFactory entityManagerFactory() {
  54. HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
  55. vendorAdapter.setDatabase(Database.H2);
  56. vendorAdapter.setGenerateDdl(true);
  57. vendorAdapter.setShowSql(true);
  58.  
  59. LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
  60. factory.setJpaVendorAdapter(vendorAdapter);
  61. factory.setPackagesToScan("ro.ubb.stcatalog.core.model");
  62. factory.setDataSource(dataSource());
  63. // factory.getJpaPropertyMap().put("hibernate.generate_statistics", true);
  64. factory.afterPropertiesSet();
  65.  
  66. return factory.getObject();
  67. }
  68.  
  69. @Bean
  70. public EntityManager entityManager(EntityManagerFactory entityManagerFactory) {
  71. return entityManagerFactory.createEntityManager();
  72. }
  73.  
  74. @Bean
  75. public PlatformTransactionManager transactionManager() {
  76. JpaTransactionManager txManager = new JpaTransactionManager();
  77. txManager.setEntityManagerFactory(entityManagerFactory());
  78. return txManager;
  79. }
  80.  
  81. @Bean
  82. public HibernateExceptionTranslator hibernateExceptionTranslator() {
  83. return new HibernateExceptionTranslator();
  84. }
  85. }
Add Comment
Please, Sign In to add comment