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, ConsulTestResourceProvider, ElasticsearchTestResourceProvider, HiveMQTestResourceProvider, KafkaTestResourceProvider, LocalStackTestResourceProvider, MongoDBTestResourceProvider, Neo4jTestResourceProvider, OpenSearchTestResourceProvider, 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.
  • Constructor Details

    • AbstractTestContainersProvider

      public AbstractTestContainersProvider()
  • Method Details

    • getName

      public String getName()
      Specified by:
      getName in interface ToggableTestResourcesResolver
    • getOrder

      public int getOrder()
      Specified by:
      getOrder in interface io.micronaut.core.order.Ordered
    • getSimpleName

      protected abstract String getSimpleName()
      Returns the name of the resource resolver, for example "kafka" or "mysql".
      Returns:
      the name of the resolver
    • getDefaultImageName

      protected abstract String 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 name
      requestedProperties - the resolved properties
      testResourcesConfig - 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 resolve
      requestedProperties - the resolved properties
      testResourcesConfig - 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 resolve
      properties - the properties used to resolve
      testResourcesConfig - 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 interface TestResourcesResolver
      Parameters:
      propertyName - the property to resolve
      properties - the resolved required properties
      testResourcesConfig - the test resources configuration
      Returns:
      the resolved property or empty if not found
    • configureContainer

      protected void configureContainer(T container, Map<String,Object> properties, Map<String,Object> testResourcesConfig)
    • resolveProperty

      protected abstract Optional<String> resolveProperty(String propertyName, T container)
    • stringOrNull

      protected final String stringOrNull(Object value)