DAOTestExtension.@Deprecated public class DAOTestRule extends org.junit.rules.ExternalResource
Example:
@Rule
public DAOTestRule daoTestRule = DAOTestRule.newBuilder()
.addEntityClass(Person.class)
.build();
private PersonDAO personDAO;
@Before
public void setUp() throws Exception {
personDAO = new PersonDAO(daoTestRule.getSessionFactory());
}
@Test
public void createPerson() {
Person wizard = daoTestRule.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 |
DAOTestRule.Builder
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
after()
Deprecated.
|
protected void |
before()
Deprecated.
|
org.hibernate.SessionFactory |
getSessionFactory()
Deprecated.
Returns the current active session factory for injecting to DAOs.
|
<T> T |
inTransaction(Callable<T> call)
Deprecated.
Performs a call in a transaction
|
void |
inTransaction(Runnable action)
Deprecated.
Performs an action in a transaction
|
static DAOTestRule.Builder |
newBuilder()
Deprecated.
Creates a new builder for
DAOTestRule, which allows to customize a SessionFactory
by different parameters. |
public static DAOTestRule.Builder newBuilder()
DAOTestRule, which allows to customize a SessionFactory
by different parameters. By default uses the H2 database in the memory mode.DAOTestRule.Builderprotected void before()
throws Throwable
before in class org.junit.rules.ExternalResourceThrowableprotected void after()
after in class org.junit.rules.ExternalResourcepublic 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 © 2020. All rights reserved.