Class AbstractJdbcTestResourceProvider<T extends org.testcontainers.containers.JdbcDatabaseContainer<? extends T>>
java.lang.Object
io.micronaut.testresources.testcontainers.AbstractTestContainersProvider<T>
io.micronaut.testresources.jdbc.AbstractJdbcTestResourceProvider<T>
- Type Parameters:
T- the type of the container
- All Implemented Interfaces:
io.micronaut.core.order.Ordered, TestResourcesResolver, ToggableTestResourcesResolver
- Direct Known Subclasses:
MariaDBTestResourceProvider, MSSQLTestResourceProvider, MySQLTestResourceProvider, OracleFreeTestResourceProvider, OracleXETestResourceProvider, PostgreSQLTestResourceProvider
public abstract class AbstractJdbcTestResourceProvider<T extends org.testcontainers.containers.JdbcDatabaseContainer<? extends T>>
extends AbstractTestContainersProvider<T>
Superclass for JDBC test containers providers.
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractTestContainersProvider
AbstractTestContainersProvider.ContainerCommand -
Field Summary
FieldsFields 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 voidconfigureContainer(T container, Map<String, Object> properties, Map<String, Object> testResourcesConfig) protected voidcreateAdditionalDatabase(T container, String databaseName) Creates an additional logical database inside an already started container.protected static StringdatasourceExpressionOf(String datasource, String property) protected static StringdatasourceNameFrom(String expression) protected static StringdatasourcePropertyFrom(String expression) findRequestedDatabaseName(String propertyName, Map<String, Object> requestedProperties) Extracts the logical database name requested by the caller from the datasource property set.protected StringgetContainerOwnerKey(String propertyName, Map<String, Object> properties, Map<String, Object> testResourcesConfig) Returns the owner key used to scope cached containers for this resolver.getContainerQuery(String propertyName, Map<String, Object> properties, Map<String, Object> testResourcesConfig) Returns the query object used to look up or create a cached container.Returns the list of db-types supported by this provider.getRequiredProperties(String expression) Returns the list of properties which should be read before resolving an expression: this can be used if the resolver itself needs some configuration properties.getResolvableProperties(Map<String, Collection<String>> propertyEntries, Map<String, Object> testResourcesConfig) Returns the list of properties that this resolver is able to support.protected static booleanisDatasourceExpression(String expression) protected StringjdbcUrlFor(T container, String databaseName) Builds a JDBC URL that targets the supplied logical database on the running container.protected voidprepareContainer(String propertyName, T container, Map<String, Object> properties, Map<String, Object> testResourcesConfig) protected StringresolveDbSpecificProperty(String propertyName, org.testcontainers.containers.JdbcDatabaseContainer<?> container) Given the started container, resolves properties which are specific to a particular JDBC implementation.protected StringresolveDbSpecificProperty(String propertyName, org.testcontainers.containers.JdbcDatabaseContainer<?> container, Map<String, Object> properties, Map<String, Object> testResourcesConfig) Resolves vendor-specific properties using the started container plus the original requested-property map.protected StringResolves the JDBC URL for the requested datasource.resolveProperty(String expression, T container) resolveProperty(String expression, T container, Map<String, Object> properties, Map<String, Object> testResourcesConfig) Resolves the requested property from the started container with access to the full requested-property map and test-resources configuration.protected booleanshouldAnswer(String propertyName, Map<String, Object> requestedProperties, Map<String, Object> testResourcesConfig) Determines if this resolver can resolve the requested property.protected booleanIndicates whether this provider can create additional logical databases inside the same running container.Methods inherited from class AbstractTestContainersProvider
createContainer, executeInContainer, getDefaultImageName, getDefaultStartupTimeout, getName, getOrder, getSimpleName, 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
getDisplayName, isEnabled
-
Field Details
-
PREFIX
- See Also:
-
RESOURCE_NAME
- See Also:
-
-
Constructor Details
-
AbstractJdbcTestResourceProvider
public AbstractJdbcTestResourceProvider()
-
-
Method Details
-
getDbTypes
-
getResolvableProperties
public List<String> getResolvableProperties(Map<String, Collection<String>> propertyEntries, Map<String, Object> testResourcesConfig) Description copied from interface:TestResourcesResolverReturns the list of properties that this resolver is able to support. The property entries map is a map which keys are the property entries retrieved from callingTestResourcesResolver.getRequiredPropertyEntries()and values are those property entries resolved.- Parameters:
propertyEntries- the property entriestestResourcesConfig- the test resources configuration- Returns:
- the list of properties
-
getRequiredPropertyEntries
-
getRequiredProperties
Description copied from interface:TestResourcesResolverReturns the list of properties which should be read before resolving an expression: this can be used if the resolver itself needs some configuration properties.- Parameters:
expression- the expression which needs to be resolved.- Returns:
- the list of configuration properties this resolver requires
-
shouldAnswer
protected boolean shouldAnswer(String propertyName, Map<String, Object> requestedProperties, Map<String, Object> testResourcesConfig) Description copied from class:AbstractTestContainersProviderDetermines if this resolver can resolve the requested property. It is used in order to make sure that a "Postgres" resolver wouldn't provide a value if the requested container type is for MySQL, for example.- Overrides:
shouldAnswerin classAbstractTestContainersProvider<T extends org.testcontainers.containers.JdbcDatabaseContainer<? extends T>>- Parameters:
propertyName- the property to resolverequestedProperties- the resolved propertiestestResourcesConfig- the test resources configuration- Returns:
- if this resolver should answer
-
resolveProperty
- Specified by:
resolvePropertyin classAbstractTestContainersProvider<T extends org.testcontainers.containers.JdbcDatabaseContainer<? extends T>>
-
resolveProperty
protected Optional<String> resolveProperty(String expression, T container, Map<String, Object> properties, Map<String, Object> testResourcesConfig) Description copied from class:AbstractTestContainersProviderResolves the requested property from the started container with access to the full requested-property map and test-resources configuration. Subclasses may override when the resolved value depends on request metadata in addition to the container itself.- Overrides:
resolvePropertyin classAbstractTestContainersProvider<T extends org.testcontainers.containers.JdbcDatabaseContainer<? extends T>>- Parameters:
expression- the property being resolvedcontainer- the started containerproperties- the resolved properties for the requesttestResourcesConfig- the test resources configuration- Returns:
- the resolved value, if any
-
getContainerOwnerKey
protected String getContainerOwnerKey(String propertyName, Map<String, Object> properties, Map<String, Object> testResourcesConfig) Description copied from class:AbstractTestContainersProviderReturns the owner key used to scope cached containers for this resolver. Subclasses may override to share a physical container across multiple logical consumers, but should keep the returned key stable for equivalent requests.- Overrides:
getContainerOwnerKeyin classAbstractTestContainersProvider<T extends org.testcontainers.containers.JdbcDatabaseContainer<? extends T>>- Parameters:
propertyName- the property being resolvedproperties- the resolved properties for the requesttestResourcesConfig- the test resources configuration- Returns:
- the owner key used for container reuse
-
getContainerQuery
protected Map<String,Object> getContainerQuery(String propertyName, Map<String, Object> properties, Map<String, Object> testResourcesConfig) Description copied from class:AbstractTestContainersProviderReturns the query object used to look up or create a cached container. Subclasses may override to normalize request-specific properties into a stable physical-resource identity while preserving any keys needed for safe reuse.- Overrides:
getContainerQueryin classAbstractTestContainersProvider<T extends org.testcontainers.containers.JdbcDatabaseContainer<? extends T>>- Parameters:
propertyName- the property being resolvedproperties- the resolved properties for the requesttestResourcesConfig- the test resources configuration- Returns:
- the container query used for cache lookup
-
prepareContainer
-
resolveDbSpecificProperty
protected String resolveDbSpecificProperty(String propertyName, org.testcontainers.containers.JdbcDatabaseContainer<?> container) Given the started container, resolves properties which are specific to a particular JDBC implementation.- Parameters:
propertyName- the property to resolvecontainer- the started container- Returns:
- the resolved property, or null if not resolvable
-
resolveDbSpecificProperty
protected String resolveDbSpecificProperty(String propertyName, org.testcontainers.containers.JdbcDatabaseContainer<?> container, Map<String, Object> properties, Map<String, Object> testResourcesConfig) Resolves vendor-specific properties using the started container plus the original requested-property map. Subclasses may override when the resolved value depends on request metadata in addition to the container state.- Parameters:
propertyName- the property to resolvecontainer- the started containerproperties- the resolved properties for the requesttestResourcesConfig- the test resources configuration- Returns:
- the resolved property, or
nullif not resolvable
-
configureContainer
-
isDatasourceExpression
-
datasourceNameFrom
-
datasourcePropertyFrom
-
datasourceExpressionOf
-
supportsMultipleDatabases
protected boolean supportsMultipleDatabases()Indicates 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.- Returns:
truewhen additional logical databases are supported
-
createAdditionalDatabase
Creates an additional logical database inside an already started container. This is only invoked whensupportsMultipleDatabases()returnstrue, so subclasses overriding one hook should override the other as a matching pair.- Parameters:
container- the running containerdatabaseName- the database to create
-
resolveJdbcUrl
Resolves the JDBC URL for the requested datasource. Subclasses may override to customize how the requested logical database name maps onto the running container.- Parameters:
expression- the property expression being resolvedcontainer- the running containerproperties- the resolved properties for the request- Returns:
- the JDBC URL to expose to the caller
-
jdbcUrlFor
Builds 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.- Parameters:
container- the running containerdatabaseName- the logical database name requested by the caller- Returns:
- the JDBC URL for that database
-
findRequestedDatabaseName
protected Optional<String> findRequestedDatabaseName(String propertyName, Map<String, Object> requestedProperties) Extracts the logical database name requested by the caller from the datasource property set. Subclasses may override when the provider supports alternative configuration keys for selecting databases.- Parameters:
propertyName- the property being resolvedrequestedProperties- the resolved properties for the request- Returns:
- the requested logical database name, if present
-