com.anasoft.os.daofusion.test
Class BaseHibernateIntegrationTest

java.lang.Object
  extended by com.anasoft.os.daofusion.test.BaseHibernateIntegrationTest
Direct Known Subclasses:
BaseHibernateCoreIntegrationTest

@TestExecutionListeners(value={org.springframework.test.context.support.DependencyInjectionTestExecutionListener.class,org.springframework.test.context.transaction.TransactionalTestExecutionListener.class})
@TransactionConfiguration(defaultRollback=true)
@Transactional
@ContextConfiguration(locations="classpath:testContext-hibernate-baseIntegration.xml")
public abstract class BaseHibernateIntegrationTest
extends java.lang.Object

Base class for JUnit / Spring TestContext framework integration tests interacting with a database instance via JPA / Hibernate.

This class represents a generic integration test which is agnostic of the underlying database instance in use, providing a basic JPA / Hibernate integration test infrastructure to build on.

There are several configuration steps necessary in order to make integration tests work properly:

  1. Following Spring bean properties need to be set up via the PropertyOverrideConfigurer according to the database instance in use:
  2. Within the META-INF/persistence.xml file a dedicated integration test persistence unit of type RESOURCE_LOCAL needs to be defined for the target database instance. Name of this persistence unit must match the entityManagerFactory.persistenceUnitName bean property value. The hibernate.dialect property needs to be set up as well within the persistence unit.
  3. Additional persistence unit configuration (e.g. defining entity mappings or setting the default schema name) should be done via the mapping-file element(s) within META-INF/persistence.xml.
In case of in-memory integration tests (integration tests interacting with an in-memory database instance), it is recommended that the database instance setup is done within the child Spring test context (test contexts are automatically cached for all test cases unless explicitly marked as dirty).

Specific integration test subclasses interacting with local or remote databases (excluding in-memory databases) should use the test profile functionality via the IfProfileValue annotation. Following profile values are applicable for the dbType profile property name:

For example:
 @ContextConfiguration(locations = { ... })
 @IfProfileValue(name = BaseHibernateIntegrationTest.PROFILE_DBTYPE_NAME,
      values = { BaseHibernateIntegrationTest.PROFILE_DBTYPE_VALUE_ALL, BaseHibernateIntegrationTest.PROFILE_DBTYPE_VALUE_REMOTE })
 public class CustomRemoteIntegrationTest extends BaseHibernateIntegrationTest {
      ...
 }
 

Note that all integration tests should follow the default method-level rollback strategy, ensuring a proper test data separation between multiple test runs.

Author:
vojtech.szocs

Field Summary
protected static java.lang.String CONTEXT_LOCATION
           
static java.lang.String PROFILE_DBTYPE_NAME
           
static java.lang.String PROFILE_DBTYPE_VALUE_ALL
           
static java.lang.String PROFILE_DBTYPE_VALUE_LOCAL
           
static java.lang.String PROFILE_DBTYPE_VALUE_REMOTE
           
 
Constructor Summary
BaseHibernateIntegrationTest()
           
 
Method Summary
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTEXT_LOCATION

protected static final java.lang.String CONTEXT_LOCATION
See Also:
Constant Field Values

PROFILE_DBTYPE_NAME

public static final java.lang.String PROFILE_DBTYPE_NAME
See Also:
Constant Field Values

PROFILE_DBTYPE_VALUE_ALL

public static final java.lang.String PROFILE_DBTYPE_VALUE_ALL
See Also:
Constant Field Values

PROFILE_DBTYPE_VALUE_LOCAL

public static final java.lang.String PROFILE_DBTYPE_VALUE_LOCAL
See Also:
Constant Field Values

PROFILE_DBTYPE_VALUE_REMOTE

public static final java.lang.String PROFILE_DBTYPE_VALUE_REMOTE
See Also:
Constant Field Values
Constructor Detail

BaseHibernateIntegrationTest

public BaseHibernateIntegrationTest()


Copyright © 2008-2009 ANASOFT and contributors. All Rights Reserved.