Class TestcontainersDatabaseInformation

java.lang.Object
org.jdbi.v3.testing.junit5.tc.TestcontainersDatabaseInformation

@Beta public final class TestcontainersDatabaseInformation extends Object
Describes the parameters needed to create a new test-specific database or schema to isolate a test. Testcontainers supports many different databases and the Jdbi specific extension requires parameterization.
Custom TestcontainersDatabaseInformation instances can be created e.g. for a specific local setup or a customer docker image.
  • Method Details

    • forTestcontainerClass

      public static TestcontainersDatabaseInformation forTestcontainerClass(Class<? extends JdbcDatabaseContainer> containerClazz)
      Returns a TestcontainersDatabaseInformation instance for a given container instance class.
      Parameters:
      containerClazz - A JdbcDatabaseContainer class object. Must not be null.
      Returns:
      A TestcontainersDatabaseInformation instance describing how to use the database with the JdbiTestcontainersExtension or null if the container class is unknown.
    • of

      public static TestcontainersDatabaseInformation of(String user, String catalog, String schema, BiFunction<String,String,String> createStatement)
      Creates a new database information instance that describes a database.
      Parameters:
      user - Specify a user that can create a new schema or database. If this parameter is null, the testcontainer specific default user is used.
      catalog - Specify a catalog that should be used. This is for databases that do not support creating a new catalog or require a fixed catalog for schema creation (e.g. Trino). If null, use a random catalog identifier.
      schema - Specify a schema that should be used. This is for databases that do not support schemas but create a new database for each test. If null, use a random schema identifier.
      createStatement - Provides the statement to create a new database or schema for test isolation. It gets the selected catalog and schema name als parameters and returns a valid SQL statement.
      Returns:
      A TestcontainersDatabaseInformation object.
    • ofScript

      public static TestcontainersDatabaseInformation ofScript(String user, String catalog, String schema, BiFunction<String,String,List<String>> createStatement)
      Creates a new database information instance that describes a database. This method is used for databases that require more than one statement to create a new schema or database.
      Parameters:
      user - Specify a user that can create a new schema or database. If this parameter is null, the testcontainer specific default user is used.
      catalog - Specify a catalog that should be used. This is for databases that do not support creating a new catalog or require a fixed catalog for schema creation (e.g. Trino). If null, use a random catalog identifier.
      schema - Specify a schema that should be used. This is for databases that do not support schemas but create a new database for each test. If null, use a random schema identifier.
      createStatement - Provides the statement to create a new database or schema for test isolation. It gets the selected catalog and schema name als parameters and returns a list of one or more valid SQL statements.
      Returns:
      A TestcontainersDatabaseInformation object.
    • toString

      public String toString()
      Overrides:
      toString in class Object