public abstract class AbstractJpaTestRule
extends org.junit.rules.ExternalResource
TestRule that creates a temporary file-based database (using
an AbstractDbTestRule instance) during test execution and wraps
Spring/Hibernate based local JPA container around it.
The developer can influence the temporary folder, where the database should
be created and/or can provide initial configuration logic for the used
BasicDataSource and LocalContainerEntityManagerFactoryBean
via a AbstractJpaTestRule.EntityManagerFactoryConfigurator.
There is no need for a persistence.xml file for test execution,
instead a list of package names must be provided that will automatically be
scanned for entity classes.
| Modifier and Type | Class and Description |
|---|---|
static interface |
AbstractJpaTestRule.EntityManagerFactoryConfigurator
A command interface for providing custom configuration logic for the
internal
LocalContainerEntityManagerFactoryBean and
BasicDataSource. |
| Modifier and Type | Method and Description |
|---|---|
javax.persistence.EntityManager |
createEntityManager()
Creates and returns a new
EntityManager using the internal
EntityManagerFactory. |
javax.persistence.EntityManager |
createEntityManager(Map properties)
Creates and returns a new
EntityManager using the internal
EntityManagerFactory and applying the given Map of
properties. |
javax.persistence.EntityManagerFactory |
getEntityManagerFactory()
Returns the internal
EntityManagerFactory. |
public javax.persistence.EntityManagerFactory getEntityManagerFactory()
EntityManagerFactory.EntityManagerFactorypublic javax.persistence.EntityManager createEntityManager()
EntityManager using the internal
EntityManagerFactory.EntityManagerpublic javax.persistence.EntityManager createEntityManager(Map properties)
EntityManager using the internal
EntityManagerFactory and applying the given Map of
properties.
As Hibernate is used as internal JPA layer, the properties need to be Hibernate-specific.
properties - a Map of properties to use for creating the
EntityManagerEntityManagerCopyright © 2013. All Rights Reserved.