Class AbstractTestContainersProvider<T extends org.testcontainers.containers.GenericContainer<? extends T>>
java.lang.Object
io.micronaut.testresources.testcontainers.AbstractTestContainersProvider<T>
- Type Parameters:
T
- the container type
- All Implemented Interfaces:
io.micronaut.core.order.Ordered
,TestResourcesResolver
,ToggableTestResourcesResolver
- Direct Known Subclasses:
AbstractHibernateReactiveTestResourceProvider
,AbstractJdbcTestResourceProvider
,AbstractR2DBCTestResourceProvider
,ElasticsearchTestResourceProvider
,HiveMQTestResourceProvider
,KafkaTestResourceProvider
,LocalStackTestResourceProvider
,MongoDBTestResourceProvider
,Neo4jTestResourceProvider
,RabbitMQTestResourceProvider
,RedisClusterTestResourceProvider
,RedisTestResourceProvider
,VaultTestResourceProvider
public abstract class AbstractTestContainersProvider<T extends org.testcontainers.containers.GenericContainer<? extends T>>
extends Object
implements ToggableTestResourcesResolver
The base class for test resources providers which spawn test containers.
-
Field Summary
Fields inherited from interface io.micronaut.core.order.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Fields inherited from interface io.micronaut.testresources.core.TestResourcesResolver
TEST_RESOURCES_PROPERTY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
configureContainer
(T container, Map<String, Object> properties, Map<String, Object> testResourcesConfig) protected abstract T
createContainer
(org.testcontainers.utility.DockerImageName imageName, Map<String, Object> requestedProperties, Map<String, Object> testResourcesConfig) Creates the test container.protected abstract String
Returns the default image name.getName()
int
getOrder()
protected abstract String
Returns the name of the resource resolver, for example "kafka" or "mysql".Resolves the given property.resolveProperty
(String propertyName, T container) resolveWithoutContainer
(String propertyName, Map<String, Object> properties, Map<String, Object> testResourcesConfig) Lets a resolver provide a value for the requested property without triggering the creation of a test container.protected boolean
shouldAnswer
(String propertyName, Map<String, Object> requestedProperties, Map<String, Object> testResourcesConfig) Determines if this resolver can resolve the requested property.protected final String
stringOrNull
(Object value) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.micronaut.testresources.core.TestResourcesResolver
getId, getRequiredProperties, getRequiredPropertyEntries, getResolvableProperties
Methods inherited from interface io.micronaut.testresources.core.ToggableTestResourcesResolver
getDisplayName, isEnabled
-
Constructor Details
-
AbstractTestContainersProvider
public AbstractTestContainersProvider()
-
-
Method Details
-
getName
- Specified by:
getName
in interfaceToggableTestResourcesResolver
-
getOrder
public int getOrder()- Specified by:
getOrder
in interfaceio.micronaut.core.order.Ordered
-
getSimpleName
Returns the name of the resource resolver, for example "kafka" or "mysql".- Returns:
- the name of the resolver
-
getDefaultImageName
Returns the default image name.- Returns:
- the default image name.
-
createContainer
protected abstract T createContainer(org.testcontainers.utility.DockerImageName imageName, Map<String, Object> requestedProperties, Map<String, Object> testResourcesConfig) Creates the test container.- Parameters:
imageName
- the docker image namerequestedProperties
- the resolved propertiestestResourcesConfig
- the test resources configuration- Returns:
- a container
-
shouldAnswer
protected boolean shouldAnswer(String propertyName, Map<String, Object> requestedProperties, Map<String, Object> testResourcesConfig) Determines 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.- Parameters:
propertyName
- the property to resolverequestedProperties
- the resolved propertiestestResourcesConfig
- the test resources configuration- Returns:
- if this resolver should answer
-
resolveWithoutContainer
protected Optional<String> resolveWithoutContainer(String propertyName, Map<String, Object> properties, Map<String, Object> testResourcesConfig) Lets a resolver provide a value for the requested property without triggering the creation of a test container. This can be used in case a resolver wants to check existing containers first.- Parameters:
propertyName
- the name of the property to resolveproperties
- the properties used to resolvetestResourcesConfig
- the test resources configuration- Returns:
- a resolved property
-
resolve
public final Optional<String> resolve(String propertyName, Map<String, Object> properties, Map<String, Object> testResourcesConfig) Description copied from interface:TestResourcesResolver
Resolves the given property.- Specified by:
resolve
in interfaceTestResourcesResolver
- Parameters:
propertyName
- the property to resolveproperties
- the resolved required propertiestestResourcesConfig
- the test resources configuration- Returns:
- the resolved property or empty if not found
-
configureContainer
-
resolveProperty
-
stringOrNull
-