Skip to content

Commit 17b9ffc

Browse files
Move static config from configure() to constructors (testcontainers#2473)
1 parent f5948a9 commit 17b9ffc

12 files changed

Lines changed: 25 additions & 34 deletions

File tree

modules/clickhouse/src/main/java/org/testcontainers/containers/ClickHouseContainer.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ public ClickHouseContainer() {
2626

2727
public ClickHouseContainer(String dockerImageName) {
2828
super(dockerImageName);
29-
}
3029

31-
@Override
32-
protected void configure() {
3330
withExposedPorts(HTTP_PORT, NATIVE_PORT);
3431
waitingFor(
3532
new HttpWaitStrategy()

modules/db2/src/main/java/org/testcontainers/containers/Db2Container.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public Db2Container(String imageName) {
3737
this.waitStrategy = new LogMessageWaitStrategy()
3838
.withRegEx(".*Setup has completed\\..*")
3939
.withStartupTimeout(Duration.of(10, ChronoUnit.MINUTES));
40+
41+
addExposedPort(DB2_PORT);
4042
}
4143

4244
@Override
@@ -52,8 +54,6 @@ protected void configure() {
5254
acceptLicense();
5355
}
5456

55-
addExposedPort(DB2_PORT);
56-
5757
addEnv("DBNAME", databaseName);
5858
addEnv("DB2INSTANCE", username);
5959
addEnv("DB2INST1_PASSWORD", password);

modules/influxdb/src/main/java/org/testcontainers/containers/InfluxDBContainer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ public InfluxDBContainer(final String version) {
3636
waitStrategy = new WaitAllStrategy()
3737
.withStrategy(Wait.forHttp("/ping").withBasicCredentials(username, password).forStatusCode(204))
3838
.withStrategy(Wait.forListeningPort());
39+
40+
addExposedPort(INFLUXDB_PORT);
3941
}
4042

4143
@Override
4244
protected void configure() {
43-
addExposedPort(INFLUXDB_PORT);
44-
4545
addEnv("INFLUXDB_ADMIN_USER", admin);
4646
addEnv("INFLUXDB_ADMIN_PASSWORD", adminPassword);
4747

modules/mariadb/src/main/java/org/testcontainers/containers/MariaDBContainer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public MariaDBContainer() {
2424

2525
public MariaDBContainer(String dockerImageName) {
2626
super(dockerImageName);
27+
addExposedPort(MARIADB_PORT);
2728
}
2829

2930
@Override
@@ -35,7 +36,6 @@ protected Integer getLivenessCheckPort() {
3536
protected void configure() {
3637
optionallyMapResourceParameterAsVolume(MY_CNF_CONFIG_OVERRIDE_PARAM_NAME, "/etc/mysql/conf.d", "mariadb-default-conf");
3738

38-
addExposedPort(MARIADB_PORT);
3939
addEnv("MYSQL_DATABASE", databaseName);
4040
addEnv("MYSQL_USER", username);
4141
if (password != null && !password.isEmpty()) {
@@ -83,7 +83,7 @@ public SELF withConfigurationOverride(String s) {
8383
parameters.put(MY_CNF_CONFIG_OVERRIDE_PARAM_NAME, s);
8484
return self();
8585
}
86-
86+
8787
@Override
8888
public SELF withDatabaseName(final String databaseName) {
8989
this.databaseName = databaseName;

modules/mssqlserver/src/main/java/org/testcontainers/containers/MSSQLServerContainer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public MSSQLServerContainer(final String dockerImageName) {
3636
super(dockerImageName);
3737
withStartupTimeoutSeconds(DEFAULT_STARTUP_TIMEOUT_SECONDS);
3838
withConnectTimeoutSeconds(DEFAULT_CONNECT_TIMEOUT_SECONDS);
39+
addExposedPort(MS_SQL_SERVER_PORT);
3940
}
4041

4142
@Override
@@ -45,11 +46,8 @@ protected Integer getLivenessCheckPort() {
4546

4647
@Override
4748
protected void configure() {
48-
addExposedPort(MS_SQL_SERVER_PORT);
49-
5049
LicenseAcceptance.assertLicenseAccepted(this.getDockerImageName());
5150
addEnv("ACCEPT_EULA", "Y");
52-
5351
addEnv("SA_PASSWORD", password);
5452
}
5553

modules/mysql/src/main/java/org/testcontainers/containers/MySQLContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public MySQLContainer() {
2727

2828
public MySQLContainer(String dockerImageName) {
2929
super(dockerImageName);
30+
addExposedPort(MYSQL_PORT);
3031
}
3132

3233
@NotNull
@@ -40,7 +41,6 @@ protected void configure() {
4041
optionallyMapResourceParameterAsVolume(MY_CNF_CONFIG_OVERRIDE_PARAM_NAME, "/etc/mysql/conf.d",
4142
"mysql-default-conf");
4243

43-
addExposedPort(MYSQL_PORT);
4444
addEnv("MYSQL_DATABASE", databaseName);
4545
addEnv("MYSQL_USER", username);
4646
if (password != null && !password.isEmpty()) {

modules/neo4j/src/main/java/org/testcontainers/containers/Neo4jContainer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ public Neo4jContainer(String dockerImageName) {
8787
.withStrategy(waitForBolt)
8888
.withStrategy(waitForHttp)
8989
.withStartupTimeout(Duration.ofMinutes(2));
90+
91+
addExposedPorts(DEFAULT_BOLT_PORT, DEFAULT_HTTP_PORT, DEFAULT_HTTPS_PORT);
9092
}
9193

9294
@Override
@@ -100,8 +102,6 @@ public Set<Integer> getLivenessCheckPortNumbers() {
100102
@Override
101103
protected void configure() {
102104

103-
addExposedPorts(DEFAULT_BOLT_PORT, DEFAULT_HTTP_PORT, DEFAULT_HTTPS_PORT);
104-
105105
boolean emptyAdminPassword = this.adminPassword == null || this.adminPassword.isEmpty();
106106
String neo4jAuth = emptyAdminPassword ? "none" : String.format(AUTH_FORMAT, this.adminPassword);
107107
addEnv("NEO4J_AUTH", neo4jAuth);

modules/nginx/src/main/java/org/testcontainers/containers/NginxContainer.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ public class NginxContainer<SELF extends NginxContainer<SELF>> extends GenericCo
1616
private static final int NGINX_DEFAULT_PORT = 80;
1717

1818
public NginxContainer() {
19-
super("nginx:1.9.4");
19+
this("nginx:1.9.4");
20+
}
21+
22+
public NginxContainer(String dockerImageName) {
23+
super(dockerImageName);
24+
25+
addExposedPort(NGINX_DEFAULT_PORT);
26+
setCommand("nginx", "-g", "daemon off;");
2027
}
2128

2229
@NotNull
@@ -25,12 +32,6 @@ protected Set<Integer> getLivenessCheckPorts() {
2532
return Collections.singleton(getMappedPort(80));
2633
}
2734

28-
@Override
29-
protected void configure() {
30-
addExposedPort(NGINX_DEFAULT_PORT);
31-
setCommand("nginx", "-g", "daemon off;");
32-
}
33-
3435
public URL getBaseUrl(String scheme, int port) throws MalformedURLException {
3536
return new URL(scheme + "://" + getContainerIpAddress() + ":" + getMappedPort(port));
3637
}

modules/oracle-xe/src/main/java/org/testcontainers/containers/OracleContainer.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,14 @@ public OracleContainer(Future<String> dockerImageName) {
4646
super(dockerImageName);
4747
withStartupTimeoutSeconds(DEFAULT_STARTUP_TIMEOUT_SECONDS);
4848
withConnectTimeoutSeconds(DEFAULT_CONNECT_TIMEOUT_SECONDS);
49+
addExposedPorts(ORACLE_PORT, APEX_HTTP_PORT);
4950
}
5051

5152
@Override
5253
protected Integer getLivenessCheckPort() {
5354
return getMappedPort(ORACLE_PORT);
5455
}
5556

56-
@Override
57-
protected void configure() {
58-
addExposedPorts(ORACLE_PORT, APEX_HTTP_PORT);
59-
}
60-
6157
@Override
6258
public String getDriverClassName() {
6359
return "oracle.jdbc.OracleDriver";

modules/orientdb/src/main/java/org/testcontainers/containers/OrientDBContainer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,12 @@ public OrientDBContainer(@NonNull String dockerImageName) {
6666
.withStrategy(Wait.forListeningPort())
6767
.withStrategy(waitForHttp)
6868
.withStartupTimeout(Duration.ofMinutes(2));
69+
70+
addExposedPorts(DEFAULT_BINARY_PORT, DEFAULT_HTTP_PORT);
6971
}
7072

7173
@Override
7274
protected void configure() {
73-
addExposedPorts(DEFAULT_BINARY_PORT, DEFAULT_HTTP_PORT);
7475
addEnv("ORIENTDB_ROOT_PASSWORD", serverPassword);
7576
}
7677

0 commit comments

Comments
 (0)