Class GenericTestContainerProvider
java.lang.Object
io.micronaut.testresources.testcontainers.GenericTestContainerProvider
- All Implemented Interfaces:
io.micronaut.core.order.Ordered,TestResourcesResolver,ToggableTestResourcesResolver
A generic test containers provider. This provider is special in the sense
that it requires user provided configuration in order to spawn containers.
Therefore, the application configuration must contain entries under the
"test-resources.containers" property prefix.
A generic container is represented with a name, a container image, and
exposes a number of ports.
For example, imagine that a service requires an SMTP server to work
property. Then it is likely that some configuration property needs to
point to the server port. If that property is
smtp.port, then it is
possible to expose a test container which will resolve that property using
the following configuration:
test-resources:
containers:
fakesmtp:
image-name: ghusta/fakesmtp:2.0
hostnames:
- smtp.host
exposed-ports:
- smtp.port: 25
The mapped port from test containers will then be automatically be assigned
to the smtp.port property, and the host name of the running
test container will automatically be assigned to the smtp.host
property.-
Field Summary
Fields inherited from interface io.micronaut.core.order.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCEFields inherited from interface io.micronaut.testresources.core.TestResourcesResolver
TEST_RESOURCES_PROPERTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a display name for a test resources resolver, used for debugging purposes.getName()intgetOrder()getResolvableProperties(Map<String, Collection<String>> propertyEntries, Map<String, Object> testResourcesConfig) Returns the list of properties that this resolver is able to support.booleanResolves the given property.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.testresources.core.TestResourcesResolver
getId, getRequiredProperties, getRequiredPropertyEntries
-
Constructor Details
-
GenericTestContainerProvider
public GenericTestContainerProvider()
-
-
Method Details
-
getDisplayName
Description copied from interface:TestResourcesResolverReturns a display name for a test resources resolver, used for debugging purposes.- Specified by:
getDisplayNamein interfaceTestResourcesResolver- Specified by:
getDisplayNamein interfaceToggableTestResourcesResolver- Returns:
- the display name
-
getName
- Specified by:
getNamein interfaceToggableTestResourcesResolver
-
getOrder
public int getOrder()- Specified by:
getOrderin interfaceio.micronaut.core.order.Ordered
-
isEnabled
- Specified by:
isEnabledin interfaceToggableTestResourcesResolver
-
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.- Specified by:
getResolvablePropertiesin interfaceTestResourcesResolver- Parameters:
propertyEntries- the property entriestestResourcesConfig- the test resources configuration- Returns:
- the list of properties
-
resolve
public Optional<String> resolve(String propertyName, Map<String, Object> properties, Map<String, Object> testResourcesConfig) Description copied from interface:TestResourcesResolverResolves the given property.- Specified by:
resolvein interfaceTestResourcesResolver- Parameters:
propertyName- the property to resolveproperties- the resolved required propertiestestResourcesConfig- the test resources configuration- Returns:
- the resolved property or empty if not found
-