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 Details

    • JdbiRule

      public JdbiRule()
  • Method Details

    • embeddedPostgres

      public static JdbiRule embeddedPostgres()
      Create a JdbiRule with an embedded PostgreSQL instance. Your project must depend on the otj-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 the otj-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 the postgresql driver artifact.
    • h2

      public static JdbiRule h2()
      Create a JdbiRule with an in-memory H2 database instance. Your project must depend on the h2 database artifact.
    • sqlite

      public static JdbiRule sqlite()
      Create a JdbiRule with an in-memory Sqlite database instance. Your project must depend on the sqlite-jdbc database artifact.
    • withMigration

      public JdbiRule withMigration(Migration newMigration)
      Run database migration.
    • withPlugins

      public JdbiRule withPlugins()
      Discover and install plugins from the classpath.
      See Also:
    • withPlugin

      public JdbiRule withPlugin(JdbiPlugin plugin)
      Install a plugin into JdbiRule.
    • before

      public void before() throws Throwable
      Throws:
      Throwable
    • after

      public void after()
    • getJdbi

      public Jdbi getJdbi()
      Get Jdbi, in case you want to open additional handles to the same data source.
    • getHandle

      public Handle getHandle()
      Get the single Handle instance opened for the duration of this test case.
    • attach

      public <T> T attach(Class<T> extension)
      Attach an extension (such as a SqlObject) to the managed handle.