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.

  • Constructor Details

    • EmbeddedPgExtension

      public EmbeddedPgExtension()
      Default constructor which allows using this extension with the ExtendWith annotation.

      This is equivalent to using

      
           @RegisterExtension
           public static EmbeddedPgExtension pg = MultiDatabaseBuilder.instanceWithDefaults().build();
           
      Since:
      3.0
  • Method Details

    • createDataSource

      @NonNull public DataSource createDataSource() throws SQLException
      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

      @NonNull public DatabaseInfo createDatabaseInfo() throws SQLException
      Returns a new DatabaseInfo 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 interface org.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 interface org.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 interface org.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 interface org.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 interface org.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 interface org.junit.jupiter.api.extension.ParameterResolver