public class HsqlJpaTestRule extends AbstractJpaTestRule
TestRule that creates a temporary file-based Hypersonic SQL
database (using HsqlDbTestRule) 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 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.
Usage example:
public class HsqlDbTestRuleTest
{
@Rule
public HsqlJpaTestRule _jpa = new HsqlJpaTestRule(FooEntity.class.getPackage().getName());
@Test
public void test() throws SQLException
{
final EntityManager em = _jpa.createEntityManager();
Assert.assertNotNull(em);
em.getTransaction().begin();
// Do some JPA operations
em.getTranscation().commit();
em.close();
}
}
AbstractJpaTestRule.EntityManagerFactoryConfigurator| Constructor and Description |
|---|
HsqlJpaTestRule(AbstractJpaTestRule.EntityManagerFactoryConfigurator configurator,
File dbFolder,
String... entityPackages)
Creates a new instance using the given
EntityManagerFactoryConfigurator and folder for the
internal database. |
HsqlJpaTestRule(AbstractJpaTestRule.EntityManagerFactoryConfigurator configurator,
String... entityPackages)
Creates a new instance using the given
EntityManagerFactoryConfigurator for the internal database. |
HsqlJpaTestRule(File dbFolder,
String... entityPackages)
Creates a new instance using the given
folder for the
internal database. |
HsqlJpaTestRule(String... entityPackages)
Creates a new instance with no special configuration.
|
createEntityManager, createEntityManager, getEntityManagerFactorypublic HsqlJpaTestRule(AbstractJpaTestRule.EntityManagerFactoryConfigurator configurator, File dbFolder, String... entityPackages)
EntityManagerFactoryConfigurator and folder for the
internal database.configurator - a EntityManagerFactoryConfigurator for performing custom
configuration logic on the internal BasicDataSource and
LocalContainerEntityManagerFactoryBeandbFolder - the temporary folder where the database should be set upentityPackages - a list of names of packages to scan for entity classesIllegalArgumentException - if the list of package names is emptypublic HsqlJpaTestRule(File dbFolder, String... entityPackages)
folder for the
internal database.dbFolder - the temporary folder where the database should be set upentityPackages - a list of names of packages to scan for entity classesIllegalArgumentException - if the list of package names is emptypublic HsqlJpaTestRule(AbstractJpaTestRule.EntityManagerFactoryConfigurator configurator, String... entityPackages)
EntityManagerFactoryConfigurator for the internal database.configurator - a EntityManagerFactoryConfigurator for performing custom
configuration logic on the internal BasicDataSource and
LocalContainerEntityManagerFactoryBeanentityPackages - a list of names of packages to scan for entity classesIllegalArgumentException - if the list of package names is emptypublic HsqlJpaTestRule(String... entityPackages)
entityPackages - a list of names of packages to scan for entity classesIllegalArgumentException - if the list of package names is emptyCopyright © 2013. All Rights Reserved.