2 * Copyright 2013 F.B.A. Scheper.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. *
16 package org.bitbucket.fbascheper.tutorial.envers;
18 import org.bitbucket.fbascheper.tutorial.envers.util.InitScriptRunner;
19 import org.junit.Before;
20 import org.junit.runner.RunWith;
21 import org.springframework.beans.factory.annotation.Value;
22 import org.springframework.test.context.ContextConfiguration;
23 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
24 import org.springframework.test.context.support.DelegatingSmartContextLoader;
25 import org.springframework.transaction.PlatformTransactionManager;
26 import org.springframework.transaction.support.TransactionTemplate;
28 import javax.annotation.Resource;
29 import javax.inject.Inject;
30 import javax.persistence.EntityManager;
31 import javax.persistence.PersistenceContext;
32 import javax.sql.DataSource;
33 import java.io.IOException;
35 import static org.hamcrest.CoreMatchers.notNullValue;
36 import static org.junit.Assert.assertThat;
39 * Base class for the integration tests using Spring, Hibernate and JTA.
41 * @author Erik-Berndt Scheper
44 @RunWith(SpringJUnit4ClassRunner.class)
45 @ContextConfiguration(
46 loader = DelegatingSmartContextLoader.class,
47 locations = {"classpath:/hhv-test-datamodel-domain-context.xml", "classpath:/spring-persistence-context.xml"})
48 public abstract class AbstractIntegrationTest {
51 private EntityManager entityManager;
54 private PlatformTransactionManager transactionManager;
56 @Value(value = "${hibernate.dialect}")
57 private String hibernateDialect;
59 @Resource(name = "dataSource")
60 private DataSource dataSource;
63 private InitScriptRunner initScriptRunner;
66 public void initIntegrationTest() throws IOException {
67 assertThat(transactionManager, notNullValue());
68 assertThat(entityManager, notNullValue());
69 assertThat(hibernateDialect, notNullValue());
70 assertThat(dataSource, notNullValue());
72 // re-run the database creation script for each test
73 initScriptRunner.runScript();
77 protected EntityManager getEntityManager() {
81 protected TransactionTemplate getTransactionTemplate() {
83 TransactionTemplate template = new TransactionTemplate(transactionManager);