Package org.jdbi.v3.testing
Class JdbiRule
java.lang.Object
org.junit.rules.ExternalResource
org.jdbi.v3.testing.JdbiRule
- All Implemented Interfaces:
org.junit.rules.TestRule
public abstract class JdbiRule
extends org.junit.rules.ExternalResource
JUnit
@Rule
to manage a Jdbi instance pointed to a managed database.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
after()
<T> T
Attach an extension (such as a SqlObject) to the managed handle.void
before()
static JdbiRule
Create a JdbiRule with an embedded PostgreSQL instance.static JdbiRule
embeddedPostgres
(Consumer<com.opentable.db.postgres.embedded.EmbeddedPostgres.Builder> customizer) Create a JdbiRule with an embedded PostgreSQL instance.static JdbiRule
Create a JdbiRule using an external PostgreSQL instance.Get the single Handle instance opened for the duration of this test case.getJdbi()
Get Jdbi, in case you want to open additional handles to the same data source.static JdbiRule
h2()
Create a JdbiRule with an in-memory H2 database instance.static JdbiRule
sqlite()
Create a JdbiRule with an in-memory Sqlite database instance.withMigration
(Migration newMigration) Run database migration.withPlugin
(JdbiPlugin plugin) Install a plugin into JdbiRule.Discover and install plugins from the classpath.Methods inherited from class org.junit.rules.ExternalResource
apply
-
Constructor Details
-
JdbiRule
public JdbiRule()
-
-
Method Details
-
embeddedPostgres
Create a JdbiRule with an embedded PostgreSQL instance. Your project must depend on theotj-pg-embedded
artifact. -
embeddedPostgres
public static JdbiRule embeddedPostgres(Consumer<com.opentable.db.postgres.embedded.EmbeddedPostgres.Builder> customizer) Create a JdbiRule with an embedded PostgreSQL instance. Your project must depend on theotj-pg-embedded
artifact.- Parameters:
customizer
-Consumer
to customize the created PostgreSQL instance.
-
externalPostgres
public static JdbiRule externalPostgres(String hostname, Integer port, String username, String password, String database) Create a JdbiRule using an external PostgreSQL instance. Your project must depend on thepostgresql
driver artifact. -
h2
Create a JdbiRule with an in-memory H2 database instance. Your project must depend on theh2
database artifact. -
sqlite
Create a JdbiRule with an in-memory Sqlite database instance. Your project must depend on thesqlite-jdbc
database artifact. -
withMigration
Run database migration. -
withPlugins
Discover and install plugins from the classpath. -
withPlugin
Install a plugin into JdbiRule. -
before
- Throws:
Throwable
-
after
public void after() -
getJdbi
Get Jdbi, in case you want to open additional handles to the same data source. -
getHandle
Get the single Handle instance opened for the duration of this test case. -
attach
Attach an extension (such as a SqlObject) to the managed handle.
-