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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafter()<T> TAttach an extension (such as a SqlObject) to the managed handle.voidbefore()static JdbiRuleCreate a JdbiRule with an embedded PostgreSQL instance.static JdbiRuleembeddedPostgres(Consumer<com.opentable.db.postgres.embedded.EmbeddedPostgres.Builder> customizer) Create a JdbiRule with an embedded PostgreSQL instance.static JdbiRuleCreate 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 JdbiRuleh2()Create a JdbiRule with an in-memory H2 database instance.Deprecated.migrateWithFlyway(String... locations) Deprecated.static JdbiRulesqlite()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-embeddedartifact. -
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-embeddedartifact.- Parameters:
customizer-Consumerto 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 thepostgresqldriver artifact. -
h2
Create a JdbiRule with an in-memory H2 database instance. Your project must depend on theh2database artifact. -
sqlite
Create a JdbiRule with an in-memory Sqlite database instance. Your project must depend on thesqlite-jdbcdatabase artifact. -
migrateWithFlyway
Deprecated.Run database migration scripts fromdb/migrationon the classpath, using Flyway.- Returns:
- this
-
migrateWithFlyway
Deprecated.Run database migration scripts from the given locations on the classpath, using Flyway.- Returns:
- this
-
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.
-
withMigration(Migration)