Class MySQLTestResourceProvider
java.lang.Object
io.micronaut.testresources.testcontainers.AbstractTestContainersProvider<org.testcontainers.mysql.MySQLContainer>
io.micronaut.testresources.jdbc.AbstractJdbcTestResourceProvider<org.testcontainers.mysql.MySQLContainer>
io.micronaut.testresources.mysql.MySQLTestResourceProvider
- All Implemented Interfaces:
io.micronaut.core.order.Ordered, TestResourcesResolver, ToggableTestResourcesResolver
public class MySQLTestResourceProvider
extends AbstractJdbcTestResourceProvider<org.testcontainers.mysql.MySQLContainer>
A test resource provider which will spawn a MySQL test container.
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractTestContainersProvider
AbstractTestContainersProvider.ContainerCommand -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from class AbstractJdbcTestResourceProvider
PREFIX, RESOURCE_NAMEFields inherited from interface io.micronaut.core.order.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCEFields inherited from interface TestResourcesResolver
TEST_RESOURCES_PROPERTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidconfigureContainer(org.testcontainers.mysql.MySQLContainer container, Map<String, Object> properties, Map<String, Object> testResourcesConfig) protected voidcreateAdditionalDatabase(org.testcontainers.mysql.MySQLContainer container, String databaseName) Creates an additional logical database inside an already started container.protected org.testcontainers.mysql.MySQLContainercreateContainer(org.testcontainers.utility.DockerImageName imageName, Map<String, Object> requestedProperties, Map<String, Object> testResourcesConfig) Creates the test container.protected StringReturns the default image name.Returns a display name for a test resources resolver, used for debugging purposes.getResolvableProperties(Map<String, Collection<String>> propertyEntries, Map<String, Object> testResourcesConfig) Returns the list of properties that this resolver is able to support.protected StringReturns the name of the resource resolver, for example "kafka" or "mysql".protected StringjdbcUrlFor(org.testcontainers.mysql.MySQLContainer container, String databaseName) Builds a JDBC URL that targets the supplied logical database on the running container.protected StringresolveDbSpecificProperty(String propertyName, org.testcontainers.containers.JdbcDatabaseContainer<?> container, Map<String, Object> properties, Map<String, Object> testResourcesConfig) Resolves vendor-specific properties using the started container plus the original requested-property map.protected booleanIndicates whether this provider can create additional logical databases inside the same running container.Methods inherited from class AbstractJdbcTestResourceProvider
datasourceExpressionOf, datasourceNameFrom, datasourcePropertyFrom, findRequestedDatabaseName, getContainerOwnerKey, getContainerQuery, getDbTypes, getRequiredProperties, getRequiredPropertyEntries, isDatasourceExpression, prepareContainer, resolveDbSpecificProperty, resolveJdbcUrl, resolveProperty, resolveProperty, shouldAnswerMethods inherited from class AbstractTestContainersProvider
executeInContainer, getName, getOrder, resolve, resolveWithoutContainer, stringOrNullMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface TestResourcesResolver
getIdMethods inherited from interface ToggableTestResourcesResolver
isEnabled
-
Field Details
-
DISPLAY_NAME
- See Also:
-
MYSQL_OFFICIAL_IMAGE
- See Also:
-
DOCKER_OFFICIAL_IMAGE
- See Also:
-
SIMPLE_NAME
- See Also:
-
X_PROTOCOL_URL
- See Also:
-
DEFAULT_X_PROTOCOL_PORT
public static final int DEFAULT_X_PROTOCOL_PORT- See Also:
-
-
Constructor Details
-
MySQLTestResourceProvider
public MySQLTestResourceProvider()
-
-
Method Details
-
getDisplayName
Description copied from interface:TestResourcesResolverReturns a display name for a test resources resolver, used for debugging purposes.- Returns:
- the display name
-
getSimpleName
Description copied from class:AbstractTestContainersProviderReturns the name of the resource resolver, for example "kafka" or "mysql".- Specified by:
getSimpleNamein classAbstractTestContainersProvider<org.testcontainers.mysql.MySQLContainer>- Returns:
- the name of the resolver
-
getDefaultImageName
Description copied from class:AbstractTestContainersProviderReturns the default image name.- Specified by:
getDefaultImageNamein classAbstractTestContainersProvider<org.testcontainers.mysql.MySQLContainer>- Returns:
- the default image name.
-
supportsMultipleDatabases
protected boolean supportsMultipleDatabases()Description copied from class:AbstractJdbcTestResourceProviderIndicates whether this provider can create additional logical databases inside the same running container. Subclasses overriding this method must also implement the database-creation hooks consistently for the same container type.- Overrides:
supportsMultipleDatabasesin classAbstractJdbcTestResourceProvider<org.testcontainers.mysql.MySQLContainer>- Returns:
truewhen additional logical databases are supported
-
createAdditionalDatabase
protected void createAdditionalDatabase(org.testcontainers.mysql.MySQLContainer container, String databaseName) Description copied from class:AbstractJdbcTestResourceProviderCreates an additional logical database inside an already started container. This is only invoked whenAbstractJdbcTestResourceProvider.supportsMultipleDatabases()returnstrue, so subclasses overriding one hook should override the other as a matching pair.- Overrides:
createAdditionalDatabasein classAbstractJdbcTestResourceProvider<org.testcontainers.mysql.MySQLContainer>- Parameters:
container- the running containerdatabaseName- the database to create
-
jdbcUrlFor
Description copied from class:AbstractJdbcTestResourceProviderBuilds a JDBC URL that targets the supplied logical database on the running container. Subclasses overriding this method should return a URL compatible with the driver exposed by the container.- Overrides:
jdbcUrlForin classAbstractJdbcTestResourceProvider<org.testcontainers.mysql.MySQLContainer>- Parameters:
container- the running containerdatabaseName- the logical database name requested by the caller- Returns:
- the JDBC URL for that database
-
createContainer
protected org.testcontainers.mysql.MySQLContainer createContainer(org.testcontainers.utility.DockerImageName imageName, Map<String, Object> requestedProperties, Map<String, Object> testResourcesConfig) Description copied from class:AbstractTestContainersProviderCreates the test container.- Specified by:
createContainerin classAbstractTestContainersProvider<org.testcontainers.mysql.MySQLContainer>- Parameters:
imageName- the docker image namerequestedProperties- the resolved propertiestestResourcesConfig- the test resources configuration- Returns:
- a container
-
configureContainer
protected void configureContainer(org.testcontainers.mysql.MySQLContainer container, Map<String, Object> properties, Map<String, Object> testResourcesConfig) - Overrides:
configureContainerin classAbstractJdbcTestResourceProvider<org.testcontainers.mysql.MySQLContainer>
-
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- Overrides:
getResolvablePropertiesin classAbstractJdbcTestResourceProvider<org.testcontainers.mysql.MySQLContainer>- Parameters:
propertyEntries- the property entriestestResourcesConfig- the test resources configuration- Returns:
- the list of properties
-
resolveDbSpecificProperty
protected String resolveDbSpecificProperty(String propertyName, org.testcontainers.containers.JdbcDatabaseContainer<?> container, Map<String, Object> properties, Map<String, Object> testResourcesConfig) Description copied from class:AbstractJdbcTestResourceProviderResolves vendor-specific properties using the started container plus the original requested-property map. Subclasses may override when the resolved value depends on request metadata in addition to the container state.- Overrides:
resolveDbSpecificPropertyin classAbstractJdbcTestResourceProvider<org.testcontainers.mysql.MySQLContainer>- Parameters:
propertyName- the property to resolvecontainer- the started containerproperties- the resolved properties for the requesttestResourcesConfig- the test resources configuration- Returns:
- the resolved property, or
nullif not resolvable
-