Advertisement
Guest User

Untitled

a guest
Nov 16th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. @RunWith(SpringJUnit4ClassRunner.class)
  2. @ContextConfiguration(locations = {"file:src/test/resources/applicationContext.xml"})
  3. @Transactional
  4. @WebAppConfiguration
  5. public class ServiceTest {
  6.  
  7. private static DataSource ds;
  8.  
  9. @BeforeClass
  10. public static void setUpConnection(){
  11. ds = new DataSource();
  12. ds.setDriverClassName("org.h2.Driver");
  13. ds.setUrl("jdbc:h2:mem:testDB");
  14. ds.setUsername("sa");
  15. ds.setPassword("");
  16. HibernateConfiguration.dataSourceTest(ds);
  17. }
  18.  
  19. @AfterClass
  20. public static void cleanConnection(){
  21. HibernateConfiguration.dataSourceTest(null);
  22. }
  23. }
  24.  
  25. <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
  26. xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  27. xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans
  28. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  29. http://www.springframework.org/schema/context
  30. http://www.springframework.org/schema/context/spring-context-3.0.xsd
  31. http://www.springframework.org/schema/tx
  32. http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
  33.  
  34. <bean id="entityManagerFactory"
  35. class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  36. <property name="persistenceXmlLocation" value="classpath:persistence.xml" />
  37. <property name="persistenceUnitName" value="testingSetup" />
  38. <property name="dataSource" ref="dataSource" />
  39. <property name="jpaVendorAdapter">
  40. <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
  41. </property>
  42. </bean>
  43.  
  44. <context:component-scan base-package="com.adistec" />
  45. <context:annotation-config/>
  46.  
  47. <persistence xmlns="http://java.sun.com/xml/ns/persistence"
  48. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  49. xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
  50. version="2.0">
  51. <persistence-unit name="testingSetup" transaction-type="RESOURCE_LOCAL">
  52. <provider>org.hibernate.ejb.HibernatePersistence</provider>
  53. <properties>
  54. <property name="hibernate.connection.driver_class" value="org.h2.Driver" />
  55. <property name="hibernate.connection.url" value="jdbc:h2:mem:testDB;DB_CLOSE_DELAY=-1;MODE=MySQL" />
  56. <property name="hibernate.connection.username" value="sa" />
  57. <property name="hibernate.connection.password" value="" />
  58. <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
  59. <property name="hibernate.archive.autodetection" value="class, hbm"/>
  60. <property name="hibernate.show_sql" value="false"/>
  61. <property name="hibernate.hbm2ddl.auto" value="create"/>
  62. </properties>
  63. </persistence-unit>
  64.  
  65. @Entity
  66. public class MailConfig {
  67. @Id
  68. @GeneratedValue(strategy = GenerationType.IDENTITY)
  69. Long id;
  70. @Column
  71. String host;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement