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
DatabaseInfo
parameter is equivalent to callingcreateDatabaseInfo()
. - Using a
DataSource
parameter is equivalent to callingcreateDataSource()
.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Builder forEmbeddedPgExtension
customization. -
Constructor Summary
ConstructorDescriptionDefault constructor which allows using this extension with theExtendWith
annotation. -
Method Summary
Modifier and TypeMethodDescriptionvoid
afterAll
(ExtensionContext extensionContext) void
afterEach
(ExtensionContext extensionContext) void
beforeAll
(ExtensionContext extensionContext) void
beforeEach
(ExtensionContext extensionContext) Returns a newDatabaseInfo
describing a database connection.Returns a data source.resolveParameter
(ParameterContext parameterContext, ExtensionContext extensionContext) boolean
supportsParameter
(ParameterContext parameterContext, ExtensionContext extensionContext)
-
Constructor Details
-
EmbeddedPgExtension
public EmbeddedPgExtension()Default constructor which allows using this extension with theExtendWith
annotation.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
DataSource
instance. This is never null. - Throws:
SQLException
- If a problem connecting to the database occurs.
-
createDatabaseInfo
Returns a newDatabaseInfo
describing a database connection.Depending on the mode, this either describes the same database (single mode) or a new database (multi mode).
- Returns:
- A
DatabaseInfo
instance. This is never null. - Throws:
SQLException
- If a problem connecting to the database occurs.
-
beforeAll
- Specified by:
beforeAll
in interfaceBeforeAllCallback
- Throws:
Exception
-
afterAll
- Specified by:
afterAll
in interfaceAfterAllCallback
- Throws:
Exception
-
beforeEach
- Specified by:
beforeEach
in interfaceBeforeEachCallback
- Throws:
Exception
-
afterEach
- Specified by:
afterEach
in interfaceAfterEachCallback
- Throws:
Exception
-
supportsParameter
public boolean supportsParameter(@NonNull ParameterContext parameterContext, ExtensionContext extensionContext) - Specified by:
supportsParameter
in interfaceParameterResolver
-
resolveParameter
public Object resolveParameter(@NonNull ParameterContext parameterContext, ExtensionContext extensionContext) - Specified by:
resolveParameter
in interfaceParameterResolver
-