-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DAO tests for SQLite databases (#357)
* Add DAO tests for SQLite databases * Add SQLite driver test dependency * Add JDBI3 and JDBC DAO tests for SQLite * Add new utilities to TestHelpers * Add custom SQLite migration file
- Loading branch information
1 parent
46cbabf
commit e75135e
Showing
5 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...t/java/org/kiwiproject/dropwizard/error/dao/jdbi3/SqliteJdbi3ApplicationErrorDaoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.kiwiproject.dropwizard.error.dao.jdbi3; | ||
|
||
import static org.kiwiproject.dropwizard.error.util.TestHelpers.migrateDatabase; | ||
import static org.kiwiproject.dropwizard.error.util.TestHelpers.newInMemorySqliteDataSource; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.kiwiproject.test.jdbc.SimpleSingleConnectionDataSource; | ||
import org.kiwiproject.test.junit.jupiter.Jdbi3DaoExtension; | ||
|
||
import java.sql.SQLException; | ||
|
||
@DisplayName("Jdbi3ApplicationErrorDao (SQLite)") | ||
class SqliteJdbi3ApplicationErrorDaoTest extends AbstractJdbi3ApplicationErrorDaoTest { | ||
|
||
private static SimpleSingleConnectionDataSource DATA_SOURCE; | ||
|
||
@BeforeAll | ||
static void beforeAll() throws SQLException { | ||
DATA_SOURCE = newInMemorySqliteDataSource(); | ||
migrateDatabase(DATA_SOURCE, "dropwizard-app-errors-migrations-sqlite.xml"); | ||
} | ||
|
||
@RegisterExtension | ||
final Jdbi3DaoExtension<Jdbi3ApplicationErrorDao> jdbi3DaoExtension = | ||
Jdbi3DaoExtension.<Jdbi3ApplicationErrorDao>builder() | ||
.daoType(Jdbi3ApplicationErrorDao.class) | ||
.dataSource(DATA_SOURCE) | ||
.build(); | ||
|
||
@Override | ||
Jdbi3DaoExtension<Jdbi3ApplicationErrorDao> getTestExtension() { | ||
return jdbi3DaoExtension; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...test/java/org/kiwiproject/dropwizard/error/dao/jdk/SqliteJdbcApplicationErrorDaoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.kiwiproject.dropwizard.error.dao.jdk; | ||
|
||
import static org.kiwiproject.dropwizard.error.util.TestHelpers.migrateDatabase; | ||
import static org.kiwiproject.dropwizard.error.util.TestHelpers.newInMemorySqliteDataSource; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.kiwiproject.test.jdbc.SimpleSingleConnectionDataSource; | ||
|
||
import java.sql.SQLException; | ||
|
||
@DisplayName("JdbcApplicationErrorDao (SQLite)") | ||
class SqliteJdbcApplicationErrorDaoTest extends AbstractJdbcApplicationErrorDaoTest { | ||
|
||
private static SimpleSingleConnectionDataSource DATA_SOURCE; | ||
|
||
@BeforeAll | ||
static void beforeAll() throws SQLException { | ||
DATA_SOURCE = newInMemorySqliteDataSource(); | ||
migrateDatabase(DATA_SOURCE, "dropwizard-app-errors-migrations-sqlite.xml"); | ||
} | ||
|
||
@Override | ||
protected SimpleSingleConnectionDataSource getDataSource() { | ||
return DATA_SOURCE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/test/resources/dropwizard-app-errors-migrations-sqlite.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Migrations file for integration tests using SQLite as the database. | ||
--> | ||
|
||
<databaseChangeLog | ||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd"> | ||
|
||
<changeSet id="0001-add-application-errors-table" author="dropwizard-application-errors"> | ||
<createTable tableName="application_errors" remarks="Stores application errors"> | ||
|
||
<!-- SQLite auto increment columns must be integer --> | ||
<column name="id" type="integer" autoIncrement="true"> | ||
<constraints primaryKey="true" nullable="false"/> | ||
</column> | ||
|
||
<!-- | ||
SQLite doesn't have date/time/timestamp types. This migration uses the integer type, | ||
which will result in numeric timestamps stored in the database. | ||
See Datatypes In SQLite: https://www.sqlite.org/datatype3.html | ||
You can also read this tutorial with examples: https://www.sqlitetutorial.net/sqlite-date/ | ||
--> | ||
<column name="created_at" type="integer" defaultValueComputed="current_timestamp"> | ||
<constraints nullable="false"/> | ||
</column> | ||
<column name="updated_at" type="integer" defaultValueComputed="current_timestamp"> | ||
<constraints nullable="false"/> | ||
</column> | ||
<column name="num_times_occurred" type="integer" defaultValueNumeric="1"> | ||
<constraints nullable="false"/> | ||
</column> | ||
<column name="description" type="text"> | ||
<constraints nullable="false"/> | ||
</column> | ||
<column name="exception_type" type="text"/> | ||
<column name="exception_message" type="text"/> | ||
<column name="exception_cause_type" type="text"/> | ||
<column name="exception_cause_message" type="text"/> | ||
<column name="stack_trace" type="text"/> | ||
<column name="resolved" type="boolean" defaultValueBoolean="false"> | ||
<constraints nullable="false"/> | ||
</column> | ||
<column name="host_name" type="text"/> | ||
<column name="ip_address" type="text"/> | ||
<column name="port" type="integer"/> | ||
</createTable> | ||
</changeSet> | ||
|
||
</databaseChangeLog> |