Class EmbeddedPgExtension
java.lang.Object
de.softwareforge.testing.postgres.junit5.EmbeddedPgExtension
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterAllCallback
,org.junit.jupiter.api.extension.AfterEachCallback
,org.junit.jupiter.api.extension.BeforeAllCallback
,org.junit.jupiter.api.extension.BeforeEachCallback
,org.junit.jupiter.api.extension.Extension
,org.junit.jupiter.api.extension.ParameterResolver
public final class EmbeddedPgExtension
extends Object
implements org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.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
(org.junit.jupiter.api.extension.ExtensionContext extensionContext) void
afterEach
(org.junit.jupiter.api.extension.ExtensionContext extensionContext) void
beforeAll
(org.junit.jupiter.api.extension.ExtensionContext extensionContext) void
beforeEach
(org.junit.jupiter.api.extension.ExtensionContext extensionContext) Returns a newDatabaseInfo
describing a database connection.Returns a data source.resolveParameter
(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) boolean
supportsParameter
(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.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
public void beforeAll(@NonNull org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Exception - Specified by:
beforeAll
in interfaceorg.junit.jupiter.api.extension.BeforeAllCallback
- Throws:
Exception
-
afterAll
public void afterAll(@NonNull org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Exception - Specified by:
afterAll
in interfaceorg.junit.jupiter.api.extension.AfterAllCallback
- Throws:
Exception
-
beforeEach
public void beforeEach(@NonNull org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Exception - Specified by:
beforeEach
in interfaceorg.junit.jupiter.api.extension.BeforeEachCallback
- Throws:
Exception
-
afterEach
public void afterEach(@NonNull org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Exception - Specified by:
afterEach
in interfaceorg.junit.jupiter.api.extension.AfterEachCallback
- Throws:
Exception
-
supportsParameter
public boolean supportsParameter(@NonNull org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) - Specified by:
supportsParameter
in interfaceorg.junit.jupiter.api.extension.ParameterResolver
-
resolveParameter
public Object resolveParameter(@NonNull org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) - Specified by:
resolveParameter
in interfaceorg.junit.jupiter.api.extension.ParameterResolver
-