org.springframework.test.jpa
Class AbstractJpaTests
java.lang.Object
junit.framework.Assert
junit.framework.TestCase
org.springframework.test.ConditionalTestCase
org.springframework.test.AbstractSpringContextTests
org.springframework.test.AbstractSingleSpringContextTests
org.springframework.test.AbstractDependencyInjectionSpringContextTests
org.springframework.test.AbstractTransactionalSpringContextTests
org.springframework.test.AbstractTransactionalDataSourceSpringContextTests
org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests
org.springframework.test.jpa.AbstractJpaTests
- All Implemented Interfaces:
- Test
- Direct Known Subclasses:
- AbstractAspectjJpaTests
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
Method Summary |
protected String |
cacheKeys()
|
protected javax.persistence.EntityManager |
createContainerManagedEntityManager()
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 ClassLoader |
createShadowingClassLoader(ClassLoader classLoader)
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(ClassLoader shadowingClassLoader)
Customize the shadowing class loader. |
protected String |
getActualOrmXmlLocation()
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()
Overridden to populate transaction definition from annotations. |
void |
setDirty()
Called to say that the "applicationContext" instance variable is dirty and
should be reloaded. |
void |
setEntityManagerFactory(javax.persistence.EntityManagerFactory entityManagerFactory)
|
protected boolean |
shouldUseShadowLoader()
Subclasses should override this method if they wish
to disable shadow class loading. |
Methods inherited from class org.springframework.test.AbstractTransactionalSpringContextTests |
endTransaction, onSetUp, onSetUpBeforeTransaction, onSetUpInTransaction, onTearDown, onTearDownAfterTransaction, onTearDownInTransaction, preventTransaction, setDefaultRollback, setTransactionDefinition, setTransactionManager, startNewTransaction |
Methods inherited from class org.springframework.test.AbstractSingleSpringContextTests |
contextKey, createApplicationContext, customizeBeanFactory, getApplicationContext, getConfigLocations, getConfigPath, getConfigPaths, getLoadCount, loadContext, loadContextLocations, setUp, tearDown |
Methods inherited from class junit.framework.Assert |
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail |
entityManagerFactory
protected javax.persistence.EntityManagerFactory entityManagerFactory
sharedEntityManager
protected javax.persistence.EntityManager sharedEntityManager
- Subclasses can use this in test cases.
It will participate in any current transaction.
AbstractJpaTests
public AbstractJpaTests()
setEntityManagerFactory
public void setEntityManagerFactory(javax.persistence.EntityManagerFactory entityManagerFactory)
createContainerManagedEntityManager
protected javax.persistence.EntityManager createContainerManagedEntityManager()
- 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()
- Subclasses should override this method if they wish
to disable shadow class loading. Do this only
if instrumentation is not required in your
JPA implementation.
- Returns:
- whether to disable shadow loading functionality
setDirty
public void setDirty()
- 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 Throwable
- Description copied from class:
AbstractAnnotationAwareTransactionalTests
- Overridden to populate transaction definition from annotations.
- Overrides:
runBare
in class AbstractAnnotationAwareTransactionalTests
- Throws:
Throwable
cacheKeys
protected String cacheKeys()
createShadowingClassLoader
protected ClassLoader createShadowingClassLoader(ClassLoader classLoader)
- 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(ClassLoader shadowingClassLoader)
- 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 String getActualOrmXmlLocation()
- 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
Copyright © 2002-2007 The Spring Framework.