Class PostgreSQLTestResourceProvider
java.lang.Object
io.micronaut.testresources.testcontainers.AbstractTestContainersProvider<org.testcontainers.postgresql.PostgreSQLContainer>
io.micronaut.testresources.jdbc.AbstractJdbcTestResourceProvider<org.testcontainers.postgresql.PostgreSQLContainer>
io.micronaut.testresources.postgres.PostgreSQLTestResourceProvider
- All Implemented Interfaces:
io.micronaut.core.order.Ordered, TestResourcesResolver, ToggableTestResourcesResolver
public class PostgreSQLTestResourceProvider
extends AbstractJdbcTestResourceProvider<org.testcontainers.postgresql.PostgreSQLContainer>
A test resource provider which will spawn a MySQL test container.
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractTestContainersProvider
AbstractTestContainersProvider.ContainerCommand -
Field Summary
FieldsFields inherited from class AbstractJdbcTestResourceProvider
PREFIX, RESOURCE_NAMEFields inherited from interface io.micronaut.core.order.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCEFields inherited from interface TestResourcesResolver
TEST_RESOURCES_PROPERTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcreateAdditionalDatabase(org.testcontainers.postgresql.PostgreSQLContainer container, String databaseName) Creates an additional logical database inside an already started container.protected org.testcontainers.postgresql.PostgreSQLContainercreateContainer(org.testcontainers.utility.DockerImageName imageName, Map<String, Object> requestedProperties, Map<String, Object> testResourcesConfig) Creates the test container.Returns the list of db-types supported by this provider.protected StringReturns the default image name.Returns a display name for a test resources resolver, used for debugging purposes.protected StringReturns the name of the resource resolver, for example "kafka" or "mysql".protected StringjdbcUrlFor(org.testcontainers.postgresql.PostgreSQLContainer container, String databaseName) Builds a JDBC URL that targets the supplied logical database on the running container.protected booleanIndicates whether this provider can create additional logical databases inside the same running container.Methods inherited from class AbstractJdbcTestResourceProvider
configureContainer, datasourceExpressionOf, datasourceNameFrom, datasourcePropertyFrom, findRequestedDatabaseName, getContainerOwnerKey, getContainerQuery, getRequiredProperties, getRequiredPropertyEntries, getResolvableProperties, isDatasourceExpression, prepareContainer, resolveDbSpecificProperty, resolveDbSpecificProperty, resolveJdbcUrl, resolveProperty, resolveProperty, shouldAnswerMethods inherited from class AbstractTestContainersProvider
executeInContainer, getName, getOrder, resolve, resolveWithoutContainer, stringOrNullMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface TestResourcesResolver
getIdMethods inherited from interface ToggableTestResourcesResolver
isEnabled
-
Field Details
-
DISPLAY_NAME
- See Also:
-
-
Constructor Details
-
PostgreSQLTestResourceProvider
public PostgreSQLTestResourceProvider()
-
-
Method Details
-
getDisplayName
Description copied from interface:TestResourcesResolverReturns a display name for a test resources resolver, used for debugging purposes.- Returns:
- the display name
-
getSimpleName
Description copied from class:AbstractTestContainersProviderReturns the name of the resource resolver, for example "kafka" or "mysql".- Specified by:
getSimpleNamein classAbstractTestContainersProvider<org.testcontainers.postgresql.PostgreSQLContainer>- Returns:
- the name of the resolver
-
getDefaultImageName
Description copied from class:AbstractTestContainersProviderReturns the default image name.- Specified by:
getDefaultImageNamein classAbstractTestContainersProvider<org.testcontainers.postgresql.PostgreSQLContainer>- Returns:
- the default image name.
-
getDbTypes
Description copied from class:AbstractJdbcTestResourceProviderReturns the list of db-types supported by this provider.- Overrides:
getDbTypesin classAbstractJdbcTestResourceProvider<org.testcontainers.postgresql.PostgreSQLContainer>- Returns:
- the list of db types
-
supportsMultipleDatabases
protected boolean supportsMultipleDatabases()Description copied from class:AbstractJdbcTestResourceProviderIndicates whether this provider can create additional logical databases inside the same running container. Subclasses overriding this method must also implement the database-creation hooks consistently for the same container type.- Overrides:
supportsMultipleDatabasesin classAbstractJdbcTestResourceProvider<org.testcontainers.postgresql.PostgreSQLContainer>- Returns:
truewhen additional logical databases are supported
-
createAdditionalDatabase
protected void createAdditionalDatabase(org.testcontainers.postgresql.PostgreSQLContainer container, String databaseName) Description copied from class:AbstractJdbcTestResourceProviderCreates an additional logical database inside an already started container. This is only invoked whenAbstractJdbcTestResourceProvider.supportsMultipleDatabases()returnstrue, so subclasses overriding one hook should override the other as a matching pair.- Overrides:
createAdditionalDatabasein classAbstractJdbcTestResourceProvider<org.testcontainers.postgresql.PostgreSQLContainer>- Parameters:
container- the running containerdatabaseName- the database to create
-
jdbcUrlFor
protected String jdbcUrlFor(org.testcontainers.postgresql.PostgreSQLContainer container, String databaseName) Description copied from class:AbstractJdbcTestResourceProviderBuilds a JDBC URL that targets the supplied logical database on the running container. Subclasses overriding this method should return a URL compatible with the driver exposed by the container.- Overrides:
jdbcUrlForin classAbstractJdbcTestResourceProvider<org.testcontainers.postgresql.PostgreSQLContainer>- Parameters:
container- the running containerdatabaseName- the logical database name requested by the caller- Returns:
- the JDBC URL for that database
-
createContainer
protected org.testcontainers.postgresql.PostgreSQLContainer createContainer(org.testcontainers.utility.DockerImageName imageName, Map<String, Object> requestedProperties, Map<String, Object> testResourcesConfig) Description copied from class:AbstractTestContainersProviderCreates the test container.- Specified by:
createContainerin classAbstractTestContainersProvider<org.testcontainers.postgresql.PostgreSQLContainer>- Parameters:
imageName- the docker image namerequestedProperties- the resolved propertiestestResourcesConfig- the test resources configuration- Returns:
- a container
-