Class EmbeddedPgExtension
java.lang.Object
de.softwareforge.testing.postgres.junit5.EmbeddedPgExtension
- All Implemented Interfaces:
AfterAllCallback,AfterEachCallback,BeforeAllCallback,BeforeEachCallback,Extension,ParameterResolver
public final class EmbeddedPgExtension
extends Object
implements BeforeAllCallback, AfterAllCallback, BeforeEachCallback, AfterEachCallback, ParameterResolver
A JUnit 5 extension that manages an embedded PostgreSQL database server.
This extension can provide the EmbeddedPostgres instance, a DatabaseInfo or a DataSource object as test parameters.
- Using a
DatabaseInfoparameter is equivalent to callingcreateDatabaseInfo(). - Using a
DataSourceparameter is equivalent to callingcreateDataSource().
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder forEmbeddedPgExtensioncustomization. -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor which allows using this extension with theExtendWithannotation. -
Method Summary
Modifier and TypeMethodDescriptionvoidafterAll(ExtensionContext extensionContext) voidafterEach(ExtensionContext extensionContext) voidbeforeAll(ExtensionContext extensionContext) voidbeforeEach(ExtensionContext extensionContext) Returns a newDatabaseInfodescribing a database connection.Returns a data source.resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) booleansupportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
-
Constructor Details
-
EmbeddedPgExtension
public EmbeddedPgExtension()Default constructor which allows using this extension with theExtendWithannotation.This is equivalent to using
@RegisterExtension public static EmbeddedPgExtension pg = MultiDatabaseBuilder.instanceWithDefaults().build();- Since:
- 3.0
-
-
Method Details
-
createDataSource
Returns a data source. Depending on the mode it returns a datasource connected to the same database (single mode) or a new database (multi mode) on every call.- Returns:
- A
DataSourceinstance. This is never null. - Throws:
SQLException- If a problem connecting to the database occurs.
-
createDatabaseInfo
Returns a newDatabaseInfodescribing a database connection.Depending on the mode, this either describes the same database (single mode) or a new database (multi mode).
- Returns:
- A
DatabaseInfoinstance. This is never null. - Throws:
SQLException- If a problem connecting to the database occurs.
-
beforeAll
- Specified by:
beforeAllin interfaceBeforeAllCallback- Throws:
Exception
-
afterAll
- Specified by:
afterAllin interfaceAfterAllCallback- Throws:
Exception
-
beforeEach
- Specified by:
beforeEachin interfaceBeforeEachCallback- Throws:
Exception
-
afterEach
- Specified by:
afterEachin interfaceAfterEachCallback- Throws:
Exception
-
supportsParameter
public boolean supportsParameter(@Nonnull ParameterContext parameterContext, ExtensionContext extensionContext) - Specified by:
supportsParameterin interfaceParameterResolver
-
resolveParameter
public Object resolveParameter(@Nonnull ParameterContext parameterContext, ExtensionContext extensionContext) - Specified by:
resolveParameterin interfaceParameterResolver
-