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,io.micronaut.testresources.core.TestResourcesResolver
public abstract class AbstractTestContainersProvider<T extends org.testcontainers.containers.GenericContainer<? extends T>> extends java.lang.Object implements io.micronaut.testresources.core.TestResourcesResolverThe base class for test resources providers which spawn test containers.
-
-
Constructor Summary
Constructors Constructor Description AbstractTestContainersProvider()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidconfigureContainer(T container, java.util.Map<java.lang.String,java.lang.Object> properties, java.util.Map<java.lang.String,java.lang.Object> testResourcesConfiguration)protected abstract TcreateContainer(org.testcontainers.utility.DockerImageName imageName, java.util.Map<java.lang.String,java.lang.Object> requestedProperties, java.util.Map<java.lang.String,java.lang.Object> testResourcesConfiguration)Creates the test container.protected abstract java.lang.StringgetDefaultImageName()Returns the default image name.intgetOrder()protected abstract java.lang.StringgetSimpleName()Returns the name of the resource resolver, for example "kafka" or "mysql".java.util.Optional<java.lang.String>resolve(java.lang.String propertyName, java.util.Map<java.lang.String,java.lang.Object> properties, java.util.Map<java.lang.String,java.lang.Object> testResourcesConfiguration)protected abstract java.util.Optional<java.lang.String>resolveProperty(java.lang.String propertyName, T container)protected java.util.Optional<java.lang.String>resolveWithoutContainer(java.lang.String propertyName, java.util.Map<java.lang.String,java.lang.Object> properties, java.util.Map<java.lang.String,java.lang.Object> testResourcesConfiguration)Lets a resolver provide a value for the requested property without triggering the creation of a test container.protected booleanshouldAnswer(java.lang.String propertyName, java.util.Map<java.lang.String,java.lang.Object> requestedProperties, java.util.Map<java.lang.String,java.lang.Object> testResourcesConfiguration)Determines if this resolver can resolve the requested property.protected java.lang.StringstringOrNull(java.lang.Object value)
-
-
-
Method Detail
-
getOrder
public int getOrder()
- Specified by:
getOrderin interfaceio.micronaut.core.order.Ordered
-
getSimpleName
protected abstract java.lang.String getSimpleName()
Returns the name of the resource resolver, for example "kafka" or "mysql".- Returns:
- the name of the resolver
-
getDefaultImageName
protected abstract java.lang.String getDefaultImageName()
Returns the default image name.- Returns:
- the default image name.
-
createContainer
protected abstract T createContainer(org.testcontainers.utility.DockerImageName imageName, java.util.Map<java.lang.String,java.lang.Object> requestedProperties, java.util.Map<java.lang.String,java.lang.Object> testResourcesConfiguration)
Creates the test container.- Parameters:
imageName- the docker image namerequestedProperties- the resolved propertiestestResourcesConfiguration- the test resources configuration- Returns:
- a container
-
shouldAnswer
protected boolean shouldAnswer(java.lang.String propertyName, java.util.Map<java.lang.String,java.lang.Object> requestedProperties, java.util.Map<java.lang.String,java.lang.Object> testResourcesConfiguration)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 propertiestestResourcesConfiguration- the test resources configuration- Returns:
- if this resolver should answer
-
resolveWithoutContainer
protected java.util.Optional<java.lang.String> resolveWithoutContainer(java.lang.String propertyName, java.util.Map<java.lang.String,java.lang.Object> properties, java.util.Map<java.lang.String,java.lang.Object> testResourcesConfiguration)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 resolvetestResourcesConfiguration- the test resources configuration- Returns:
- a resolved property
-
resolve
public final java.util.Optional<java.lang.String> resolve(java.lang.String propertyName, java.util.Map<java.lang.String,java.lang.Object> properties, java.util.Map<java.lang.String,java.lang.Object> testResourcesConfiguration)- Specified by:
resolvein interfaceio.micronaut.testresources.core.TestResourcesResolver
-
configureContainer
protected void configureContainer(T container, java.util.Map<java.lang.String,java.lang.Object> properties, java.util.Map<java.lang.String,java.lang.Object> testResourcesConfiguration)
-
resolveProperty
protected abstract java.util.Optional<java.lang.String> resolveProperty(java.lang.String propertyName, T container)
-
stringOrNull
protected final java.lang.String stringOrNull(java.lang.Object value)
-
-