public class DAOTestExtension extends Object implements DropwizardExtension, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback
Example:
public DAOTestExtension daoTestExtension = DAOTestExtension.newBuilder()
.addEntityClass(Person.class)
.build();
private PersonDAO personDAO;
@BeforeEach
public void setUp() throws Exception {
personDAO = new PersonDAO(daoTestRule.getSessionFactory());
}
@Test
public void createPerson() {
Person wizard = daoTestExtension.inTransaction(() -> personDAO.create(new Person("Merlin", "The chief wizard")));
assertThat(wizard.getId()).isGreaterThan(0);
assertThat(wizard.getFullName()).isEqualTo("Merlin");
assertThat(wizard.getJobTitle()).isEqualTo("The chief wizard");
}
| Modifier and Type | Class and Description |
|---|---|
static class |
DAOTestExtension.Builder |
| Modifier and Type | Method and Description |
|---|---|
void |
after()
Executed after test method or class.
|
void |
afterAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext) |
void |
before()
Executed before test method or class.
|
void |
beforeAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext) |
org.hibernate.SessionFactory |
getSessionFactory()
Returns the current active session factory for injecting to DAOs.
|
<T> T |
inTransaction(Callable<T> call)
Performs a call in a transaction
|
void |
inTransaction(Runnable action)
Performs an action in a transaction
|
static DAOTestExtension.Builder |
newBuilder()
Creates a new builder for
DAOTestExtension, which allows to customize a SessionFactory
by different parameters. |
public static DAOTestExtension.Builder newBuilder()
DAOTestExtension, which allows to customize a SessionFactory
by different parameters. By default uses the H2 database in the memory mode.DAOTestExtension.Builderpublic void before()
throws Throwable
DropwizardExtensionbefore in interface DropwizardExtensionThrowablepublic void after()
DropwizardExtensionafter in interface DropwizardExtensionpublic void beforeAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
throws Exception
beforeAll in interface org.junit.jupiter.api.extension.BeforeAllCallbackExceptionpublic void afterAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
afterAll in interface org.junit.jupiter.api.extension.AfterAllCallbackpublic org.hibernate.SessionFactory getSessionFactory()
SessionFactory with an open session.public <T> T inTransaction(Callable<T> call)
T - the type of the returned resultcall - the callpublic void inTransaction(Runnable action)
action - the actionCopyright © 2011. All rights reserved.