org.springframework.test.jpa
Class AbstractJpaTests

java.lang.Object
  extended by TestCase
      extended by org.springframework.test.ConditionalTestCase
          extended by org.springframework.test.AbstractSpringContextTests
              extended by org.springframework.test.AbstractSingleSpringContextTests
                  extended by org.springframework.test.AbstractDependencyInjectionSpringContextTests
                      extended by org.springframework.test.AbstractTransactionalSpringContextTests
                          extended by org.springframework.test.AbstractTransactionalDataSourceSpringContextTests
                              extended by org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests
                                  extended by org.springframework.test.jpa.AbstractJpaTests
Direct Known Subclasses:
AbstractAspectjJpaTests

Deprecated. as of Spring 3.0, in favor of using the listener-based test context framework (AbstractJUnit38SpringContextTests)

@Deprecated
public abstract class AbstractJpaTests
extends AbstractAnnotationAwareTransactionalTests

Convenient support class for JPA-related tests. Offers the same contract as AbstractTransactionalDataSourceSpringContextTests and equally good performance, even when performing the instrumentation required by the JPA specification.

Exposes an EntityManagerFactory and a shared EntityManager. Requires an EntityManagerFactory to be injected, plus the DataSource and JpaTransactionManager through the superclass.

When using Xerces, make sure a post 2.0.2 version is available on the classpath to avoid a critical bug that leads to StackOverflow. Maven users are likely to encounter this problem since 2.0.2 is used by default.

A workaround is to explicitly specify the Xerces version inside the Maven POM:

 <dependency>
   <groupId>xerces</groupId>
     <artifactId>xercesImpl</artifactId>
   <version>2.8.1</version>
 </dependency>
 

Since:
2.0
Author:
Rod Johnson, Rob Harrop, Juergen Hoeller

Nested Class Summary
private static class AbstractJpaTests.LoadTimeWeaverInjectingBeanPostProcessor
          Deprecated.  
private static class AbstractJpaTests.ShadowingLoadTimeWeaver
          Deprecated.  
 
Field Summary
private static java.util.Map<java.lang.String,java.lang.ClassLoader> classLoaderCache
          Deprecated.  
private static java.util.Map<java.lang.String,java.lang.Object> contextCache
          Deprecated. Map from String defining unique combination of config locations, to ApplicationContext.
private static java.lang.String DEFAULT_ORM_XML_LOCATION
          Deprecated.  
protected  EntityManagerFactory entityManagerFactory
          Deprecated.  
private  java.lang.Object shadowParent
          Deprecated. If this instance is in a shadow loader, this variable will contain the parent instance of the subclass.
protected  EntityManager sharedEntityManager
          Deprecated. Subclasses can use this in test cases.
 
Fields inherited from class org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests
profileValueSource, simpleJdbcTemplate
 
Fields inherited from class org.springframework.test.AbstractTransactionalDataSourceSpringContextTests
jdbcTemplate
 
Fields inherited from class org.springframework.test.AbstractTransactionalSpringContextTests
transactionDefinition, transactionManager, transactionStatus
 
Fields inherited from class org.springframework.test.AbstractDependencyInjectionSpringContextTests
AUTOWIRE_BY_NAME, AUTOWIRE_BY_TYPE, AUTOWIRE_NO
 
Fields inherited from class org.springframework.test.AbstractSingleSpringContextTests
applicationContext
 
Fields inherited from class org.springframework.test.ConditionalTestCase
logger
 
Constructor Summary
AbstractJpaTests()
          Deprecated.  
 
Method Summary
protected  java.lang.String cacheKeys()
          Deprecated.  
protected  EntityManager createContainerManagedEntityManager()
          Deprecated. Create an EntityManager that will always automatically enlist itself in current transactions, in contrast to an EntityManager returned by EntityManagerFactory.createEntityManager() (which requires an explicit joinTransaction() call).
protected  java.lang.ClassLoader createShadowingClassLoader(java.lang.ClassLoader classLoader)
          Deprecated. NB: This method must not have a return type of ShadowingClassLoader as that would cause that class to be loaded eagerly when this test case loads, creating verify errors at runtime.
protected  void customizeResourceOverridingShadowingClassLoader(java.lang.ClassLoader shadowingClassLoader)
          Deprecated. Customize the shadowing class loader.
protected  java.lang.String getActualOrmXmlLocation()
          Deprecated. Subclasses can override this to return the real location path for orm.xml or null if they do not wish to find any orm.xml
 void runBare()
          Deprecated. Overridden to populate transaction definition from annotations.
 void setDirty()
          Deprecated. Called to say that the "applicationContext" instance variable is dirty and should be reloaded.
 void setEntityManagerFactory(EntityManagerFactory entityManagerFactory)
          Deprecated.  
protected  boolean shouldUseShadowLoader()
          Deprecated. Subclasses should override this method if they wish to disable shadow class loading.
 
Methods inherited from class org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests
findUniqueProfileValueSourceFromContext, getTestMethod, isDisabledInThisEnvironment, isRollback, setDataSource
 
Methods inherited from class org.springframework.test.AbstractTransactionalDataSourceSpringContextTests
countRowsInTable, deleteFromTables, executeSqlScript, getJdbcTemplate, setComplete, setSqlScriptEncoding
 
Methods inherited from class org.springframework.test.AbstractTransactionalSpringContextTests
endTransaction, isDefaultRollback, onSetUp, onSetUpBeforeTransaction, onSetUpInTransaction, onTearDown, onTearDownAfterTransaction, onTearDownInTransaction, preventTransaction, setDefaultRollback, setTransactionDefinition, setTransactionManager, startNewTransaction
 
Methods inherited from class org.springframework.test.AbstractDependencyInjectionSpringContextTests
getAutowireMode, injectDependencies, isDependencyCheck, isPopulateProtectedVariables, prepareTestInstance, setAutowireMode, setDependencyCheck, setPopulateProtectedVariables
 
Methods inherited from class org.springframework.test.AbstractSingleSpringContextTests
contextKey, createApplicationContext, createBeanDefinitionReader, customizeBeanFactory, getApplicationContext, getConfigLocations, getConfigPath, getConfigPaths, getLoadCount, loadContext, loadContextLocations, prepareApplicationContext, setUp, tearDown
 
Methods inherited from class org.springframework.test.AbstractSpringContextTests
addContext, contextKeyString, getContext, hasCachedContext, isContextKeyEmpty, setDirty
 
Methods inherited from class org.springframework.test.ConditionalTestCase
getDisabledTestCount, isDisabledInThisEnvironment, recordDisabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ORM_XML_LOCATION

private static final java.lang.String DEFAULT_ORM_XML_LOCATION
Deprecated. 
See Also:
Constant Field Values

contextCache

private static java.util.Map<java.lang.String,java.lang.Object> contextCache
Deprecated. 
Map from String defining unique combination of config locations, to ApplicationContext. Values are intentionally not strongly typed, to avoid potential class cast exceptions through use between different class loaders.


classLoaderCache

private static java.util.Map<java.lang.String,java.lang.ClassLoader> classLoaderCache
Deprecated. 

entityManagerFactory

protected EntityManagerFactory entityManagerFactory
Deprecated. 

shadowParent

private java.lang.Object shadowParent
Deprecated. 
If this instance is in a shadow loader, this variable will contain the parent instance of the subclass. The class will not be the same as the class of the shadow instance, as it was loaded by a different class loader, but it can be invoked reflectively. The shadowParent and the shadow loader can communicate reflectively but not through direct invocation.


sharedEntityManager

protected EntityManager sharedEntityManager
Deprecated. 
Subclasses can use this in test cases. It will participate in any current transaction.

Constructor Detail

AbstractJpaTests

public AbstractJpaTests()
Deprecated. 
Method Detail

setEntityManagerFactory

public void setEntityManagerFactory(EntityManagerFactory entityManagerFactory)
Deprecated. 

createContainerManagedEntityManager

protected EntityManager createContainerManagedEntityManager()
Deprecated. 
Create an EntityManager that will always automatically enlist itself in current transactions, in contrast to an EntityManager returned by EntityManagerFactory.createEntityManager() (which requires an explicit joinTransaction() call).


shouldUseShadowLoader

protected boolean shouldUseShadowLoader()
Deprecated. 
Subclasses should override this method if they wish to disable shadow class loading.

The default implementation deactivates shadow class loading if Spring's InstrumentationSavingAgent has been configured on VM startup.


setDirty

public void setDirty()
Deprecated. 
Description copied from class: AbstractSingleSpringContextTests
Called to say that the "applicationContext" instance variable is dirty and should be reloaded. We need to do this if a test has modified the context (for example, by replacing a bean definition).

Overrides:
setDirty in class AbstractSingleSpringContextTests

runBare

public void runBare()
             throws java.lang.Throwable
Deprecated. 
Description copied from class: AbstractAnnotationAwareTransactionalTests
Overridden to populate transaction definition from annotations.

Overrides:
runBare in class AbstractAnnotationAwareTransactionalTests
Throws:
java.lang.Throwable

cacheKeys

protected java.lang.String cacheKeys()
Deprecated. 

createShadowingClassLoader

protected java.lang.ClassLoader createShadowingClassLoader(java.lang.ClassLoader classLoader)
Deprecated. 
NB: This method must not have a return type of ShadowingClassLoader as that would cause that class to be loaded eagerly when this test case loads, creating verify errors at runtime.


customizeResourceOverridingShadowingClassLoader

protected void customizeResourceOverridingShadowingClassLoader(java.lang.ClassLoader shadowingClassLoader)
Deprecated. 
Customize the shadowing class loader.

Parameters:
shadowingClassLoader - this parameter is actually of type ResourceOverridingShadowingClassLoader, and can safely to be cast to that type. However, the signature must not be of that type as that would cause the present class loader to load that type.

getActualOrmXmlLocation

protected java.lang.String getActualOrmXmlLocation()
Deprecated. 
Subclasses can override this to return the real location path for orm.xml or null if they do not wish to find any orm.xml

Returns:
orm.xml path or null to hide any such file