Dropwizard hibernate test util

Hibernate utility class for dropwizard applications

Лицензия

Лицензия

Категории

Категории

DropWizard Контейнер Микросервисы Hibernate Данные ORM
Группа

Группа

com.github.mtakaki
Идентификатор

Идентификатор

dropwizard-hibernate-test-util
Последняя версия

Последняя версия

1.3.8
Дата

Дата

Тип

Тип

jar
Описание

Описание

Dropwizard hibernate test util
Hibernate utility class for dropwizard applications
Ссылка на сайт

Ссылка на сайт

https://github.com/mtakaki/dropwizard-hibernate-test-util
Система контроля версий

Система контроля версий

https://github.com/mtakaki/dropwizard-hibernate-test-util

Скачать dropwizard-hibernate-test-util

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.github.mtakaki/dropwizard-hibernate-test-util/ -->
<dependency>
    <groupId>com.github.mtakaki</groupId>
    <artifactId>dropwizard-hibernate-test-util</artifactId>
    <version>1.3.8</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.mtakaki/dropwizard-hibernate-test-util/
implementation 'com.github.mtakaki:dropwizard-hibernate-test-util:1.3.8'
// https://jarcasting.com/artifacts/com.github.mtakaki/dropwizard-hibernate-test-util/
implementation ("com.github.mtakaki:dropwizard-hibernate-test-util:1.3.8")
'com.github.mtakaki:dropwizard-hibernate-test-util:jar:1.3.8'
<dependency org="com.github.mtakaki" name="dropwizard-hibernate-test-util" rev="1.3.8">
  <artifact name="dropwizard-hibernate-test-util" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.mtakaki', module='dropwizard-hibernate-test-util', version='1.3.8')
)
libraryDependencies += "com.github.mtakaki" % "dropwizard-hibernate-test-util" % "1.3.8"
[com.github.mtakaki/dropwizard-hibernate-test-util "1.3.8"]

Зависимости

compile (2)

Идентификатор библиотеки Тип Версия
io.dropwizard : dropwizard-hibernate jar 1.3.8
org.hsqldb : hsqldb jar 2.4.1

provided (2)

Идентификатор библиотеки Тип Версия
org.projectlombok : lombok jar 1.18.4
junit : junit jar 4.12

test (2)

Идентификатор библиотеки Тип Версия
org.mockito : mockito-all jar 1.10.19
org.assertj : assertj-guava jar 3.2.1

Модули Проекта

Данный проект не имеет модулей.

Status

CircleCI Coverage Status Codacy Badge Download Javadoc License

dropwizard-hibernate-test-util

Hibernate utility class for writing integration tests for AbstractDAO classes in dropwizard applications. It uses an in-memory database (HSQLDB) and uses hibernate functionality to auto-create the tables on startup.

This library follows what is described in this blog post: http://www.petrikainulainen.net/programming/testing/writing-tests-for-data-access-code-unit-tests-are-waste/ Bugs often slips through the unit tests with mocks. Using an in-memory database allows you to actually run the SQL scripts and remove the effort of writing mocks.

Supported versions:

Dropwizard Hibernate test util
0.9.3 0.0.1
0.9.3 0.0.2
1.3.8 1.3.8

Maven

The library is available at the maven central, so just add the dependency to pom.xml with scope set to test:

<dependencies>
    <dependency>
        <groupId>com.github.mtakaki</groupId>
        <artifactId>dropwizard-hibernate-test-util</artifactId>
        <version>1.3.8</version>
        <scope>test</scope>
    </dependency>
</dependencies>

Example

The class HibernateDAOTestUtil provides a jUnit Rule, so it can be simply used like this:

public class TestEntityDAOTest {
    @Rule
    public HibernateDAOTestUtil testUtil = new HibernateDAOTestUtil(TestEntity.class);
    
    private TestEntityDAO dao;

    public void setup() {
        this.dao = new TestEntityDAO(this.testUtil.getSessionFactory());
    }

    @Test
    public void testSaveAndQuery() {
        // We have a session opened and ready to be used.
        final Session session = this.testUtil.getSession();
        final TestEntity entity = TestEntity.builder().body("testing writing").build();
        session.save(entity);

        final Optional<TestEntity> foundEntityOptional = this.dao.findById(entity.getId());
        assertThat(foundEntityOptional).isPresent().contains(entity);
    }
}

The schema is completely dropped after each test, guaranteeing test isolation. So no need to clean up after yourself, just let the database be destroyed after the test.

Версии библиотеки

Версия
1.3.8
0.0.2
0.0.1