Class JdbiPostgresExtension
java.lang.Object
org.jdbi.v3.testing.junit5.JdbiExtension
org.jdbi.v3.testing.junit5.JdbiPostgresExtension
- All Implemented Interfaces:
AfterAllCallback, AfterEachCallback, BeforeAllCallback, BeforeEachCallback, Extension, ParameterResolver, TestInstantiationAwareExtension
Jdbi PostgreSQL JUnit 5 rule using the pg-embedded component.
Using this class with the @ExtendWith annotation is equivalent to using the SingleDatabaseBuilder to create a EmbeddedPgExtension
that creates a new postgres instance per test. This is slower than using the MultiDatabaseBuilder and using
JdbiExtension.postgres(EmbeddedPgExtension).
Override methods for special case construction:
@RegisterExtension
public JdbiExtension extension = new JdbiPostgresExtension(pg) {
@Override
protected DataSource createDataSource() {
...
}
};
Use with ExtendWith:
@ExtendWith(JdbiPostgresExtension.class)
public class DatabaseTest {
@Test
public void testWithJdbi(Jdbi jdbi) {
...
}
@Test
public void testWithHandle(Handle handle) {
...
}
}
-
Nested Class Summary
Nested classes/interfaces inherited from interface TestInstantiationAwareExtension
TestInstantiationAwareExtension.ExtensionContextScope -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterAll(ExtensionContext context) voidafterEach(ExtensionContext context) voidbeforeAll(ExtensionContext context) voidbeforeEach(ExtensionContext context) getUrl()Returns a JDBC url representing the data source used by this extension.Methods inherited from class JdbiExtension
attach, enableLeakChecker, externalPostgres, getJdbi, getSharedHandle, h2, installPlugins, openHandle, otjEmbeddedPostgres, postgres, resolveParameter, sqlite, supportsParameter, withConfig, withInitializer, withPlugin, withPluginsModifier and TypeMethodDescriptionfinal <T> TConvenience method to attach an extension (such as a SqlObject) to the shared handle.final JdbiExtensionenableLeakChecker(boolean enable) Enable tracking of cleanable resources and handles when running tests.static JdbiExtensionCreates an extension that uses an external (outside the scope of an unit test class) postgres database.final JdbigetJdbi()Returns aJdbiinstance linked to the data source used by this extension.final HandleReturns a sharedHandleused by the extension.static JdbiExtensionh2()Creates a new extension using the H2 database.final JdbiExtensionDeprecated, for removal: This API element is subject to removal in a future version.Registering plugins implicitly is less reliable.final HandleOpen a newHandleto the used data source.static JdbiOtjPostgresExtensionCreates a new extension using a managed, embedded postgres database.static JdbiExtensionpostgres(de.softwareforge.testing.postgres.junit5.EmbeddedPgExtension pg) Creates a new extension using a managed, embedded postgres database.resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) static JdbiExtensionsqlite()Creates a new extension using the SQLite database.booleansupportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) final <C extends JdbiConfig<C>>
JdbiExtensionwithConfig(Class<C> configClass, Consumer<C> configurer) Set aJdbiConfigparameter when creating theJdbiinstance.final JdbiExtensionwithInitializer(JdbiExtensionInitializer initializer) Sets aJdbiExtensionInitializerto initialize theJdbiinstance or the attached data source before running a test.final JdbiExtensionwithPlugin(JdbiPlugin plugin) Install aJdbiPluginwhen creating theJdbiinstance.final JdbiExtensionwithPlugins(JdbiPlugin... pluginList) Install multipleJdbiPlugins when creating theJdbiinstance.Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface TestInstantiationAwareExtension
getTestInstantiationExtensionContextScope
-
Constructor Details
-
JdbiPostgresExtension
public JdbiPostgresExtension()
-
-
Method Details
-
getUrl
Description copied from class:JdbiExtensionReturns a JDBC url representing the data source used by this extension. This url is database-specific and may or may not be used to connect to the data source outside testing code that uses this extension (e.g. theJdbiSqliteExtensionreturns a constant uri for all database instances).- Specified by:
getUrlin classJdbiExtension- Returns:
- A string representing the JDBC URL.
-
beforeEach
- Specified by:
beforeEachin interfaceBeforeEachCallback- Overrides:
beforeEachin classJdbiExtension- Throws:
Exception
-
beforeAll
- Specified by:
beforeAllin interfaceBeforeAllCallback- Overrides:
beforeAllin classJdbiExtension- Throws:
Exception
-
afterEach
- Specified by:
afterEachin interfaceAfterEachCallback- Overrides:
afterEachin classJdbiExtension- Throws:
Exception
-
afterAll
- Specified by:
afterAllin interfaceAfterAllCallback- Overrides:
afterAllin classJdbiExtension- Throws:
Exception
-