org.testcontainers.containers.MySQLR2DBCDatabaseContainerProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mysql Show documentation
Show all versions of mysql Show documentation
Isolated container management for Java code testing
The newest version!
package org.testcontainers.containers;
import io.asyncer.r2dbc.mysql.MySqlConnectionFactoryProvider;
import io.r2dbc.spi.ConnectionFactoryMetadata;
import io.r2dbc.spi.ConnectionFactoryOptions;
import org.testcontainers.r2dbc.R2DBCDatabaseContainer;
import org.testcontainers.r2dbc.R2DBCDatabaseContainerProvider;
import javax.annotation.Nullable;
public class MySQLR2DBCDatabaseContainerProvider implements R2DBCDatabaseContainerProvider {
static final String DRIVER = MySqlConnectionFactoryProvider.MYSQL_DRIVER;
@Override
public boolean supports(ConnectionFactoryOptions options) {
return DRIVER.equals(options.getRequiredValue(ConnectionFactoryOptions.DRIVER));
}
@Override
public R2DBCDatabaseContainer createContainer(ConnectionFactoryOptions options) {
String image = MySQLContainer.IMAGE + ":" + options.getRequiredValue(IMAGE_TAG_OPTION);
MySQLContainer> container = new MySQLContainer<>(image)
.withDatabaseName((String) options.getRequiredValue(ConnectionFactoryOptions.DATABASE));
if (Boolean.TRUE.equals(options.getValue(REUSABLE_OPTION))) {
container.withReuse(true);
}
return new MySQLR2DBCDatabaseContainer(container);
}
@Nullable
@Override
public ConnectionFactoryMetadata getMetadata(ConnectionFactoryOptions options) {
ConnectionFactoryOptions.Builder builder = options.mutate();
if (!options.hasOption(ConnectionFactoryOptions.USER)) {
builder.option(ConnectionFactoryOptions.USER, MySQLContainer.DEFAULT_USER);
}
if (!options.hasOption(ConnectionFactoryOptions.PASSWORD)) {
builder.option(ConnectionFactoryOptions.PASSWORD, MySQLContainer.DEFAULT_PASSWORD);
}
return R2DBCDatabaseContainerProvider.super.getMetadata(builder.build());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy