Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve fluent builders #657

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* <p>Callers are responsible for ensuring that this fixed port is actually available; failure will occur if it is
* not available - which could manifest as flaky or unstable tests.</p>
*/
public class FixedHostPortGenericContainer<SELF extends FixedHostPortGenericContainer<SELF>> extends GenericContainer<SELF> {
public class FixedHostPortGenericContainer extends GenericContainer<FixedHostPortGenericContainer> {
public FixedHostPortGenericContainer(@NotNull String dockerImageName) {
super(dockerImageName);
}
Expand All @@ -22,7 +22,7 @@ public FixedHostPortGenericContainer(@NotNull String dockerImageName) {
* @param containerPort a port in the container
* @return this container
*/
public SELF withFixedExposedPort(int hostPort, int containerPort) {
public FixedHostPortGenericContainer withFixedExposedPort(int hostPort, int containerPort) {

return withFixedExposedPort(hostPort, containerPort, InternetProtocol.TCP);
}
Expand All @@ -34,7 +34,7 @@ public SELF withFixedExposedPort(int hostPort, int containerPort) {
* @param protocol an internet protocol (tcp or udp)
* @return this container
*/
public SELF withFixedExposedPort(int hostPort, int containerPort, InternetProtocol protocol) {
public FixedHostPortGenericContainer withFixedExposedPort(int hostPort, int containerPort, InternetProtocol protocol) {

super.addFixedExposedPort(hostPort, containerPort, protocol);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class CustomizableMysqlTest {

// Add MYSQL_ROOT_HOST environment so that we can root login from anywhere for testing purposes
@Rule
public MySQLContainer mysql = (MySQLContainer) new MySQLContainer("mysql:5.5")
public MySQLContainer mysql = new MySQLContainer("mysql:5.5")
.withDatabaseName(DB_NAME)
.withUsername(USER)
.withPassword(PWD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class SimpleMySQLTest {

@Test
public void testSimple() throws SQLException {
MySQLContainer mysql = (MySQLContainer) new MySQLContainer()
MySQLContainer mysql = new MySQLContainer()
.withConfigurationOverride("somepath/mysql_conf_override")
.withLogConsumer(new Slf4jLogConsumer(logger));
mysql.start();
Expand All @@ -62,7 +62,7 @@ public void testSimple() throws SQLException {

@Test
public void testSpecificVersion() throws SQLException {
MySQLContainer mysqlOldVersion = (MySQLContainer) new MySQLContainer("mysql:5.5")
MySQLContainer mysqlOldVersion = new MySQLContainer("mysql:5.5")
.withConfigurationOverride("somepath/mysql_conf_override")
.withLogConsumer(new Slf4jLogConsumer(logger));
mysqlOldVersion.start();
Expand Down Expand Up @@ -96,7 +96,7 @@ public void testMySQLWithCustomIniFile() throws SQLException {

@Test
public void testCommandOverride() throws SQLException {
MySQLContainer mysqlCustomConfig = (MySQLContainer) new MySQLContainer().withCommand("mysqld --auto_increment_increment=42");
MySQLContainer mysqlCustomConfig = new MySQLContainer().withCommand("mysqld --auto_increment_increment=42");
mysqlCustomConfig.start();

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @author Miguel Gonzalez Sanchez
*/
public class MariaDBContainer<SELF extends MariaDBContainer<SELF>> extends JdbcDatabaseContainer<SELF> {
public class MariaDBContainer extends JdbcDatabaseContainer<MariaDBContainer> {

public static final String NAME = "mariadb";
public static final String IMAGE = "mariadb";
Expand Down Expand Up @@ -55,7 +55,7 @@ public String getJdbcUrl() {

@Override
public String getDatabaseName() {
return MARIADB_DATABASE;
return MARIADB_DATABASE;
}

@Override
Expand All @@ -73,7 +73,7 @@ public String getTestQueryString() {
return "SELECT 1";
}

public SELF withConfigurationOverride(String s) {
public MariaDBContainer withConfigurationOverride(String s) {
parameters.put(MY_CNF_CONFIG_OVERRIDE_PARAM_NAME, s);
return self();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* @author richardnorth
*/
public class MySQLContainer<SELF extends MySQLContainer<SELF>> extends JdbcDatabaseContainer<SELF> {
public class MySQLContainer extends JdbcDatabaseContainer<MySQLContainer> {

public static final String NAME = "mysql";
public static final String IMAGE = "mysql";
Expand Down Expand Up @@ -88,25 +88,25 @@ public String getTestQueryString() {
return "SELECT 1";
}

public SELF withConfigurationOverride(String s) {
public MySQLContainer withConfigurationOverride(String s) {
parameters.put(MY_CNF_CONFIG_OVERRIDE_PARAM_NAME, s);
return self();
}

@Override
public SELF withDatabaseName(final String databaseName) {
public MySQLContainer withDatabaseName(final String databaseName) {
this.databaseName = databaseName;
return self();
}

@Override
public SELF withUsername(final String username) {
public MySQLContainer withUsername(final String username) {
this.username = username;
return self();
}

@Override
public SELF withPassword(final String password) {
public MySQLContainer withPassword(final String password) {
this.password = password;
return self();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* @author richardnorth
*/
public class NginxContainer<SELF extends NginxContainer<SELF>> extends GenericContainer<SELF> implements LinkableContainer {
public class NginxContainer extends GenericContainer<NginxContainer> implements LinkableContainer {

private static final int NGINX_DEFAULT_PORT = 80;

Expand Down Expand Up @@ -39,7 +39,7 @@ public void setCustomContent(String htmlContentPath) {
addFileSystemBind(htmlContentPath, "/usr/share/nginx/html", BindMode.READ_ONLY);
}

public SELF withCustomContent(String htmlContentPath) {
public NginxContainer withCustomContent(String htmlContentPath) {
this.setCustomContent(htmlContentPath);
return self();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class SimpleNginxTest {
private static File contentFolder = new File(System.getProperty("user.home") + "/.tmp-test-container");

@Rule
public NginxContainer nginx = new NginxContainer<>()
public NginxContainer nginx = new NginxContainer()
.withCustomContent(contentFolder.toString())
.waitingFor(new HttpWaitStrategy());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* @author gusohal
*/
public class OracleContainer extends JdbcDatabaseContainer {
public class OracleContainer extends JdbcDatabaseContainer<OracleContainer> {

public static final String NAME = "oracle";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* @author richardnorth
*/
public class PostgreSQLContainer<SELF extends PostgreSQLContainer<SELF>> extends JdbcDatabaseContainer<SELF> {
public class PostgreSQLContainer extends JdbcDatabaseContainer<PostgreSQLContainer> {
public static final String NAME = "postgresql";
public static final String IMAGE = "postgres";
public static final String DEFAULT_TAG = "9.6.8";
Expand Down Expand Up @@ -81,19 +81,19 @@ public String getTestQueryString() {
}

@Override
public SELF withDatabaseName(final String databaseName) {
public PostgreSQLContainer withDatabaseName(final String databaseName) {
this.databaseName = databaseName;
return self();
}

@Override
public SELF withUsername(final String username) {
public PostgreSQLContainer withUsername(final String username) {
this.username = username;
return self();
}

@Override
public SELF withPassword(final String password) {
public PostgreSQLContainer withPassword(final String password) {
this.password = password;
return self();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* <p>
* The container should expose Selenium remote control protocol and VNC.
*/
public class BrowserWebDriverContainer<SELF extends BrowserWebDriverContainer<SELF>> extends GenericContainer<SELF> implements VncService, LinkableContainer {
public class BrowserWebDriverContainer extends GenericContainer<BrowserWebDriverContainer> implements VncService, LinkableContainer {

private static final String CHROME_IMAGE = "selenium/standalone-chrome-debug:%s";
private static final String FIREFOX_IMAGE = "selenium/standalone-firefox-debug:%s";
Expand Down Expand Up @@ -84,7 +84,7 @@ public BrowserWebDriverContainer(String dockerImageName) {
}


public SELF withDesiredCapabilities(DesiredCapabilities desiredCapabilities) {
public BrowserWebDriverContainer withDesiredCapabilities(DesiredCapabilities desiredCapabilities) {
this.desiredCapabilities = desiredCapabilities;
return self();
}
Expand Down Expand Up @@ -266,18 +266,18 @@ private void stopAndRetainRecordingForDescriptionAndSuccessState(Description des
* @deprecated Links are deprecated (see <a href="https://github.com/testcontainers/testcontainers-java/issues/465">#465</a>). Please use {@link Network} features instead.
*/
@Deprecated
public SELF withLinkToContainer(LinkableContainer otherContainer, String alias) {
public BrowserWebDriverContainer withLinkToContainer(LinkableContainer otherContainer, String alias) {
addLink(otherContainer, alias);
return self();
}

public SELF withRecordingMode(VncRecordingMode recordingMode, File vncRecordingDirectory) {
public BrowserWebDriverContainer withRecordingMode(VncRecordingMode recordingMode, File vncRecordingDirectory) {
this.recordingMode = recordingMode;
this.vncRecordingDirectory = vncRecordingDirectory;
return self();
}

public SELF withRecordingFileFactory(RecordingFileFactory recordingFileFactory) {
public BrowserWebDriverContainer withRecordingFileFactory(RecordingFileFactory recordingFileFactory) {
this.recordingFileFactory = recordingFileFactory;
return self();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public class CustomWaitTimeoutWebDriverContainerTest extends BaseWebDriverContainerTest {

@Rule
public BrowserWebDriverContainer chromeWithCustomTimeout = new BrowserWebDriverContainer<>()
public BrowserWebDriverContainer chromeWithCustomTimeout = new BrowserWebDriverContainer()
.withDesiredCapabilities(DesiredCapabilities.chrome())
.withStartupTimeout(Duration.of(30, SECONDS));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public class LinkedContainerTest {
public Network network = Network.newNetwork();

@Rule
public NginxContainer nginx = new NginxContainer<>()
public NginxContainer nginx = new NginxContainer()
.withNetwork(network)
.withNetworkAliases("nginx")
.withCustomContent(contentFolder.toString());

@Rule
public BrowserWebDriverContainer chrome = new BrowserWebDriverContainer<>()
public BrowserWebDriverContainer chrome = new BrowserWebDriverContainer()
.withNetwork(network)
.withDesiredCapabilities(DesiredCapabilities.chrome());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* Other helpful features include the withVaultPort, and withVaultToken methods for convenience.
*/
public class VaultContainer<SELF extends VaultContainer<SELF>> extends GenericContainer<SELF>
public class VaultContainer extends GenericContainer<VaultContainer>
implements LinkableContainer {

private static final String VAULT_PORT = "8200";
Expand Down Expand Up @@ -78,7 +78,7 @@ private String[] buildExecCommand(Map<String, List<String>> map) {
* @param token the root token value to set for Vault.
* @return this
*/
public SELF withVaultToken(String token) {
public VaultContainer withVaultToken(String token) {
withEnv("VAULT_DEV_ROOT_TOKEN_ID", token);
withEnv("VAULT_TOKEN", token);
return self();
Expand All @@ -90,7 +90,7 @@ public SELF withVaultToken(String token) {
* @param port the port number you want to have the Vault container listen on for tests.
* @return this
*/
public SELF withVaultPort(int port){
public VaultContainer withVaultPort(int port){
setVaultPortRequested(true);
String vaultPort = String.valueOf(port);
withEnv("VAULT_ADDR", "http://0.0.0.0:" + VAULT_PORT);
Expand All @@ -110,7 +110,7 @@ public SELF withVaultPort(int port){
* @param remainingSecrets var args list of secrets to add to specified path
* @return this
*/
public SELF withSecretInVault(String path, String firstSecret, String... remainingSecrets) {
public VaultContainer withSecretInVault(String path, String firstSecret, String... remainingSecrets) {
List<String> list = new ArrayList<>();
list.add(firstSecret);
for(String secret : remainingSecrets) {
Expand All @@ -130,4 +130,4 @@ private void setVaultPortRequested(boolean vaultPortRequested) {
private boolean isVaultPortRequested() {
return vaultPortRequested;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class VaultContainerTest {
private static final String VAULT_TOKEN = "my-root-token";

@ClassRule
public static VaultContainer vaultContainer = new VaultContainer<>()
public static VaultContainer vaultContainer = new VaultContainer()
.withVaultToken(VAULT_TOKEN)
.withVaultPort(VAULT_PORT)
.withSecretInVault("secret/testing1", "top_secret=password123")
Expand Down