-
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 MySQL databases (#354)
* Add testcontainers and MySQL driver dependencies * Add JDBI3 and JDBC DAO tests for MySQL * Add new utilities to TestHelpers * Add custom MySQL migration file Closes #352
- Loading branch information
1 parent
b44f47d
commit c91b802
Showing
5 changed files
with
178 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
40 changes: 40 additions & 0 deletions
40
...st/java/org/kiwiproject/dropwizard/error/dao/jdbi3/MySqlJdbi3ApplicationErrorDaoTest.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,40 @@ | ||
package org.kiwiproject.dropwizard.error.dao.jdbi3; | ||
|
||
import static org.kiwiproject.dropwizard.error.util.TestHelpers.migrateDatabase; | ||
import static org.kiwiproject.dropwizard.error.util.TestHelpers.newLatestMySQLContainer; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.kiwiproject.test.junit.jupiter.Jdbi3DaoExtension; | ||
import org.testcontainers.containers.MySQLContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
import java.sql.SQLException; | ||
|
||
@DisplayName("Jdbi3ApplicationErrorDao (MySQL)") | ||
@Testcontainers | ||
class MySqlJdbi3ApplicationErrorDaoTest extends AbstractJdbi3ApplicationErrorDaoTest { | ||
|
||
@Container | ||
private static final MySQLContainer<?> MYSQL = newLatestMySQLContainer(); | ||
|
||
@RegisterExtension | ||
final Jdbi3DaoExtension<Jdbi3ApplicationErrorDao> jdbi3DaoExtension = | ||
Jdbi3DaoExtension.<Jdbi3ApplicationErrorDao>builder() | ||
.daoType(Jdbi3ApplicationErrorDao.class) | ||
.url(MYSQL.getJdbcUrl()) | ||
.username(MYSQL.getUsername()) | ||
.password(MYSQL.getPassword()) | ||
.build(); | ||
|
||
@Override | ||
Jdbi3DaoExtension<Jdbi3ApplicationErrorDao> getTestExtension() { | ||
return jdbi3DaoExtension; | ||
} | ||
|
||
@BeforeAll | ||
static void beforeAll() throws SQLException { | ||
migrateDatabase(MYSQL, "dropwizard-app-errors-migrations-mysql.xml"); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/test/java/org/kiwiproject/dropwizard/error/dao/jdk/MySqlJdbcApplicationErrorDaoTest.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,34 @@ | ||
package org.kiwiproject.dropwizard.error.dao.jdk; | ||
|
||
import static org.kiwiproject.dropwizard.error.util.TestHelpers.migrateDatabase; | ||
import static org.kiwiproject.dropwizard.error.util.TestHelpers.newLatestMySQLContainer; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.kiwiproject.test.jdbc.SimpleSingleConnectionDataSource; | ||
import org.testcontainers.containers.MySQLContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
@Testcontainers | ||
@DisplayName("MySqlJdbcApplicationErrorDao (MySQL)") | ||
class MySqlJdbcApplicationErrorDaoTest extends AbstractJdbcApplicationErrorDaoTest { | ||
|
||
private static SimpleSingleConnectionDataSource DATA_SOURCE; | ||
|
||
@Container | ||
private static final MySQLContainer<?> MYSQL = newLatestMySQLContainer(); | ||
|
||
@BeforeAll | ||
static void beforeAll() { | ||
migrateDatabase(MYSQL, "dropwizard-app-errors-migrations-mysql.xml"); | ||
|
||
DATA_SOURCE = new SimpleSingleConnectionDataSource( | ||
MYSQL.getJdbcUrl(), MYSQL.getUsername(), MYSQL.getPassword()); | ||
} | ||
|
||
@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
51 changes: 51 additions & 0 deletions
51
src/test/resources/dropwizard-app-errors-migrations-mysql.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,51 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Migrations file for integration tests using MySQL 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"> | ||
<column name="id" type="bigint" autoIncrement="true"> | ||
<constraints primaryKey="true" nullable="false"/> | ||
</column> | ||
<!-- | ||
The fractional seconds part "(6)"" MUST be specified here for both type and default value. | ||
See https://dev.mysql.com/doc/refman/8.3/en/date-and-time-type-syntax.html | ||
--> | ||
<column name="created_at" type="timestamp(6)" defaultValueComputed="current_timestamp(6)"> | ||
<constraints nullable="false"/> | ||
</column> | ||
<column name="updated_at" type="timestamp(6)" defaultValueComputed="current_timestamp(6)"> | ||
<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"/> | ||
<!-- | ||
MySQL doesn't have booleans, so this actually becomes a tinyint(1). | ||
See https://www.mysqltutorial.org/mysql-basics/mysql-boolean/ and also | ||
https://dev.mysql.com/doc/refman/8.3/en/boolean-literals.html | ||
--> | ||
<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> |