Class AbstractTestContainersProvider<T extends org.testcontainers.containers.GenericContainer<? extends 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.TestResourcesResolver
    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
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      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)  
      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.
      protected abstract java.lang.String getDefaultImageName()
      Returns the default image name.
      int getOrder()  
      protected abstract java.lang.String getSimpleName()
      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 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.
      protected java.lang.String stringOrNull​(java.lang.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

        getRequiredProperties, getRequiredPropertyEntries, getResolvableProperties
    • Constructor Detail

      • AbstractTestContainersProvider

        public AbstractTestContainersProvider()
    • Method Detail

      • getOrder

        public int getOrder()
        Specified by:
        getOrder in interface io.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 name
        requestedProperties - the resolved properties
        testResourcesConfiguration - 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 resolve
        requestedProperties - the resolved properties
        testResourcesConfiguration - 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 resolve
        properties - the properties used to resolve
        testResourcesConfiguration - 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:
        resolve in interface io.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)