Class AbstractR2DBCTestResourceProvider<T extends org.testcontainers.containers.GenericContainer<? extends T>>

java.lang.Object
io.micronaut.testresources.testcontainers.AbstractTestContainersProvider<T>
io.micronaut.testresources.r2dbc.core.AbstractR2DBCTestResourceProvider<T>
Type Parameters:
T - the container type
All Implemented Interfaces:
io.micronaut.core.order.Ordered, TestResourcesResolver, ToggableTestResourcesResolver
Direct Known Subclasses:
R2DBCMariaDBTestResourceProvider, R2DBCMSSQLTestResourceProvider, R2DBCMySQLTestResourceProvider, R2DBCOracleFreeTestResourceProvider, R2DBCOracleXETestResourceProvider, R2DBCPostgreSQLTestResourceProvider

public abstract class AbstractR2DBCTestResourceProvider<T extends org.testcontainers.containers.GenericContainer<? extends T>> extends AbstractTestContainersProvider<T>
Base class for R2DBC test resources. Unlike JDBC test resources, this resolver is capable of reusing an existing JDBC test resources and expose it via R2DBC: this can be useful for Flyway database migrations which work over JDBC for example. For this to work, a datasource of the same name must exist, in which case it would be resolved first. If no such datasource exists, then a new container will be created.
  • Constructor Details

    • AbstractR2DBCTestResourceProvider

      public AbstractR2DBCTestResourceProvider()
  • Method Details

    • getDbTypes

      protected List<String> getDbTypes()
      Returns the list of db-types supported by this provider.
      Returns:
      the list of db types
    • getRequiredPropertyEntries

      public List<String> getRequiredPropertyEntries()
    • getRequiredProperties

      public List<String> getRequiredProperties(String expression)
      Description copied from interface: TestResourcesResolver
      Returns the list of properties which should be read before resolving an expression: this can be used if the resolver itself needs some configuration properties.
      Parameters:
      expression - the expression which needs to be resolved.
      Returns:
      the list of configuration properties this resolver requires
    • getResolvableProperties

      public List<String> getResolvableProperties(Map<String, Collection<String>> propertyEntries, Map<String,Object> testResourcesConfig)
      Description copied from interface: TestResourcesResolver
      Returns 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 calling TestResourcesResolver.getRequiredPropertyEntries() and values are those property entries resolved.
      Parameters:
      propertyEntries - the property entries
      testResourcesConfig - the test resources configuration
      Returns:
      the list of properties
    • shouldAnswer

      protected boolean shouldAnswer(String propertyName, Map<String,Object> requestedProperties, Map<String,Object> testResourcesConfig)
      Description copied from class: AbstractTestContainersProvider
      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.
      Overrides:
      shouldAnswer in class AbstractTestContainersProvider<T extends org.testcontainers.containers.GenericContainer<? extends T>>
      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)
      Description copied from class: AbstractTestContainersProvider
      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.
      Overrides:
      resolveWithoutContainer in class AbstractTestContainersProvider<T extends org.testcontainers.containers.GenericContainer<? extends T>>
      Parameters:
      propertyName - the name of the property to resolve
      properties - the properties used to resolve
      testResourcesConfig - the test resources configuration
      Returns:
      a resolved property
    • resolveProperty

      protected final Optional<String> resolveProperty(String expression, T container)
      Specified by:
      resolveProperty in class AbstractTestContainersProvider<T extends org.testcontainers.containers.GenericContainer<? extends T>>
    • resolveProperty

      protected final Optional<String> resolveProperty(String expression, T container, Map<String,Object> properties, Map<String,Object> testResourcesConfig)
      Description copied from class: AbstractTestContainersProvider
      Resolves the requested property from the started container with access to the full requested-property map and test-resources configuration. Subclasses may override when the resolved value depends on request metadata in addition to the container itself.
      Overrides:
      resolveProperty in class AbstractTestContainersProvider<T extends org.testcontainers.containers.GenericContainer<? extends T>>
      Parameters:
      expression - the property being resolved
      container - the started container
      properties - the resolved properties for the request
      testResourcesConfig - the test resources configuration
      Returns:
      the resolved value, if any
    • getContainerOwnerKey

      protected String getContainerOwnerKey(String propertyName, Map<String,Object> properties, Map<String,Object> testResourcesConfig)
      Description copied from class: AbstractTestContainersProvider
      Returns the owner key used to scope cached containers for this resolver. Subclasses may override to share a physical container across multiple logical consumers, but should keep the returned key stable for equivalent requests.
      Overrides:
      getContainerOwnerKey in class AbstractTestContainersProvider<T extends org.testcontainers.containers.GenericContainer<? extends T>>
      Parameters:
      propertyName - the property being resolved
      properties - the resolved properties for the request
      testResourcesConfig - the test resources configuration
      Returns:
      the owner key used for container reuse
    • getContainerQuery

      protected Map<String,Object> getContainerQuery(String propertyName, Map<String,Object> properties, Map<String,Object> testResourcesConfig)
      Description copied from class: AbstractTestContainersProvider
      Returns the query object used to look up or create a cached container. Subclasses may override to normalize request-specific properties into a stable physical-resource identity while preserving any keys needed for safe reuse.
      Overrides:
      getContainerQuery in class AbstractTestContainersProvider<T extends org.testcontainers.containers.GenericContainer<? extends T>>
      Parameters:
      propertyName - the property being resolved
      properties - the resolved properties for the request
      testResourcesConfig - the test resources configuration
      Returns:
      the container query used for cache lookup
    • prepareContainer

      protected void prepareContainer(String propertyName, T container, Map<String,Object> properties, Map<String,Object> testResourcesConfig)
      Overrides:
      prepareContainer in class AbstractTestContainersProvider<T extends org.testcontainers.containers.GenericContainer<? extends T>>
    • extractOptions

      protected abstract Optional<io.r2dbc.spi.ConnectionFactoryOptions> extractOptions(org.testcontainers.containers.GenericContainer<?> container)
    • supportsMultipleDatabases

      protected boolean supportsMultipleDatabases()
      Indicates whether this provider can create additional logical databases inside the same running container. Subclasses overriding this method must also implement the matching database-creation hooks for the same container type.
      Returns:
      true when additional logical databases are supported
    • createAdditionalDatabase

      protected void createAdditionalDatabase(T container, String databaseName)
      Creates an additional logical database inside an already started container. This is only invoked when supportsMultipleDatabases() returns true, so subclasses should override both hooks together.
      Parameters:
      container - the running container
      databaseName - the database to create
    • extractDefaultDatabaseName

      protected Optional<String> extractDefaultDatabaseName(T container)
      Extracts the default logical database name already configured on the running container. Subclasses may override when the provider can compare requested databases against a provider-specific default.
      Parameters:
      container - the running container
      Returns:
      the default logical database name, if one can be derived
    • findRequestedDatabaseName

      protected Optional<String> findRequestedDatabaseName(String propertyName, Map<String,Object> properties)
      Extracts the logical database name requested by the caller from the R2DBC datasource properties. Subclasses may override when the provider supports alternative configuration keys for database selection.
      Parameters:
      propertyName - the property being resolved
      properties - the resolved properties for the request
      Returns:
      the requested logical database name, if present