Class Jdbi3Extension
- java.lang.Object
-
- org.kiwiproject.test.junit.jupiter.Jdbi3Extension
-
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterEachCallback
,org.junit.jupiter.api.extension.BeforeEachCallback
,org.junit.jupiter.api.extension.Extension
public class Jdbi3Extension extends Object implements org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback
A JUnit JupiterExtension
to easily test JDBI 3 DAOs using the "Fluent API" (as opposed to the SQL Objects API) against any database and using transaction rollback to make sure tests never commit to the database.You must supply one of three methods for obtaining a database
Connection
: (1) aDataSource
, (2) a JDBIConnectionFactory
, or (3) the JDBC URL, username, and password.Before each tests, sets up a transaction. After each test completes, rolls the transaction back.
NOTE: If the DAO under test creates its own
Handle
s, then you need to make sure that you always use the same connection otherwise there will be transaction isolation issues. Prefer using theHandle
provided by this extension.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterEach(org.junit.jupiter.api.extension.ExtensionContext context)
Rolls back the transaction and closes theHandle
.void
beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)
Opens aHandle
and begins a transaction.
-
-
-
Method Detail
-
beforeEach
public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)
Opens aHandle
and begins a transaction.- Specified by:
beforeEach
in interfaceorg.junit.jupiter.api.extension.BeforeEachCallback
- Parameters:
context
- the extension context- See Also:
Jdbi.open()
,Handle.begin()
-
afterEach
public void afterEach(org.junit.jupiter.api.extension.ExtensionContext context)
Rolls back the transaction and closes theHandle
.- Specified by:
afterEach
in interfaceorg.junit.jupiter.api.extension.AfterEachCallback
- Parameters:
context
- the extension context- See Also:
Handle.rollback()
,Handle.close()
-
-