public abstract class JdbiRule
extends org.junit.rules.ExternalResource
@Rule to manage a Jdbi instance pointed to a managed database.| Constructor and Description |
|---|
JdbiRule() |
| Modifier and Type | Method and Description |
|---|---|
void |
after() |
<T> T |
attach(Class<T> extension)
Attach an extension (such as a SqlObject) to the managed handle.
|
void |
before() |
protected abstract DataSource |
createDataSource() |
static JdbiRule |
embeddedPostgres()
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 |
externalPostgres(String hostname,
Integer port,
String username,
String password,
String database)
Create a JdbiRule using an external PostgreSQL instance.
|
Handle |
getHandle()
Get the single Handle instance opened for the duration of this test case.
|
Jdbi |
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.
|
JdbiRule |
migrateWithFlyway()
Deprecated.
|
JdbiRule |
migrateWithFlyway(String... locations)
Deprecated.
|
static JdbiRule |
sqlite()
Create a JdbiRule with an in-memory Sqlite database instance.
|
JdbiRule |
withMigration(Migration newMigration)
Run database migration.
|
JdbiRule |
withPlugin(JdbiPlugin plugin)
Install a plugin into JdbiRule.
|
JdbiRule |
withPlugins()
Discover and install plugins from the classpath.
|
protected abstract DataSource createDataSource()
public static JdbiRule embeddedPostgres()
otj-pg-embedded artifact.public static JdbiRule embeddedPostgres(Consumer<com.opentable.db.postgres.embedded.EmbeddedPostgres.Builder> customizer)
otj-pg-embedded artifact.customizer - Consumer to customize the created PostgreSQL instance.public static JdbiRule externalPostgres(String hostname, Integer port, String username, String password, String database)
postgresql driver artifact.public static JdbiRule h2()
h2 database artifact.public static JdbiRule sqlite()
sqlite-jdbc database artifact.@Deprecated public JdbiRule migrateWithFlyway()
withMigration(Migration)db/migration on the classpath, using Flyway.@Deprecated public JdbiRule migrateWithFlyway(String... locations)
withMigration(Migration)public JdbiRule withPlugins()
public JdbiRule withPlugin(JdbiPlugin plugin)
public void before()
throws Throwable
before in class org.junit.rules.ExternalResourceThrowablepublic void after()
after in class org.junit.rules.ExternalResourcepublic Jdbi getJdbi()
public Handle getHandle()
public <T> T attach(Class<T> extension)
Copyright © 2019. All rights reserved.