Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @RunWith(SpringJUnit4ClassRunner.class)
- @ContextConfiguration(locations = {"file:src/test/resources/applicationContext.xml"})
- @Transactional
- @WebAppConfiguration
- public class ServiceTest {
- private static DataSource ds;
- @BeforeClass
- public static void setUpConnection(){
- ds = new DataSource();
- ds.setDriverClassName("org.h2.Driver");
- ds.setUrl("jdbc:h2:mem:testDB");
- ds.setUsername("sa");
- ds.setPassword("");
- HibernateConfiguration.dataSourceTest(ds);
- }
- @AfterClass
- public static void cleanConnection(){
- HibernateConfiguration.dataSourceTest(null);
- }
- }
- <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
- xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.0.xsd
- http://www.springframework.org/schema/tx
- 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">
- <bean id="entityManagerFactory"
- class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
- <property name="persistenceXmlLocation" value="classpath:persistence.xml" />
- <property name="persistenceUnitName" value="testingSetup" />
- <property name="dataSource" ref="dataSource" />
- <property name="jpaVendorAdapter">
- <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
- </property>
- </bean>
- <context:component-scan base-package="com.adistec" />
- <context:annotation-config/>
- <persistence xmlns="http://java.sun.com/xml/ns/persistence"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
- version="2.0">
- <persistence-unit name="testingSetup" transaction-type="RESOURCE_LOCAL">
- <provider>org.hibernate.ejb.HibernatePersistence</provider>
- <properties>
- <property name="hibernate.connection.driver_class" value="org.h2.Driver" />
- <property name="hibernate.connection.url" value="jdbc:h2:mem:testDB;DB_CLOSE_DELAY=-1;MODE=MySQL" />
- <property name="hibernate.connection.username" value="sa" />
- <property name="hibernate.connection.password" value="" />
- <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
- <property name="hibernate.archive.autodetection" value="class, hbm"/>
- <property name="hibernate.show_sql" value="false"/>
- <property name="hibernate.hbm2ddl.auto" value="create"/>
- </properties>
- </persistence-unit>
- @Entity
- public class MailConfig {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- Long id;
- @Column
- String host;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement