org.testcontainers.containers.MSSQLR2DBCDatabaseContainerProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mssqlserver Show documentation
Show all versions of mssqlserver Show documentation
Isolated container management for Java code testing
package org.testcontainers.containers;
import io.r2dbc.mssql.MssqlConnectionFactoryProvider;
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 MSSQLR2DBCDatabaseContainerProvider implements R2DBCDatabaseContainerProvider {
static final String DRIVER = MssqlConnectionFactoryProvider.MSSQL_DRIVER;
@Override
public boolean supports(ConnectionFactoryOptions options) {
return DRIVER.equals(options.getRequiredValue(ConnectionFactoryOptions.DRIVER));
}
@Override
public R2DBCDatabaseContainer createContainer(ConnectionFactoryOptions options) {
// TODO work out how best to do this if these constants become private
String image = MSSQLServerContainer.IMAGE + ":" + options.getRequiredValue(IMAGE_TAG_OPTION);
MSSQLServerContainer> container = new MSSQLServerContainer<>(image);
if (Boolean.TRUE.equals(options.getValue(REUSABLE_OPTION))) {
container.withReuse(true);
}
return new MSSQLR2DBCDatabaseContainer(container);
}
@Nullable
@Override
public ConnectionFactoryMetadata getMetadata(ConnectionFactoryOptions options) {
ConnectionFactoryOptions.Builder builder = options.mutate();
if (!options.hasOption(ConnectionFactoryOptions.USER)) {
builder.option(ConnectionFactoryOptions.USER, MSSQLServerContainer.DEFAULT_USER);
}
if (!options.hasOption(ConnectionFactoryOptions.PASSWORD)) {
builder.option(ConnectionFactoryOptions.PASSWORD, MSSQLServerContainer.DEFAULT_PASSWORD);
}
return R2DBCDatabaseContainerProvider.super.getMetadata(builder.build());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy