Skip to content

Commit 2a0359c

Browse files
committed
additional feedback
1 parent 94348f1 commit 2a0359c

File tree

4 files changed

+20
-48
lines changed

4 files changed

+20
-48
lines changed

modules/application-server-commons/src/main/java/org/testcontainers/applicationserver/ApplicationServerContainer.java

+4-17
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import java.util.Map;
2424
import java.util.Objects;
2525
import java.util.concurrent.Future;
26-
import java.util.function.Function;
27-
import java.util.function.Predicate;
2826
import java.util.function.Supplier;
2927
import java.util.stream.Collectors;
3028
import java.util.stream.Stream;
@@ -137,10 +135,10 @@ public void setExposedPorts(List<Integer> exposedPorts) {
137135
* @param archives - An archive created using shrinkwrap and test runtime
138136
* @return self
139137
*/
140-
public ApplicationServerContainer withArchvies(@NonNull Archive<?>... archives) {
138+
public ApplicationServerContainer withArchives(@NonNull Archive<?>... archives) {
141139
Stream.of(archives).forEach(archive -> {
142140
String name = archive.getName();
143-
Path target = Paths.get(getTempDirectory().toString(), name);
141+
Path target = Paths.get(createTempDirectory().toString(), name);
144142
archive.as(ZipExporter.class).exportTo(target.toFile(), true);
145143
this.archives.add(MountableFile.forHostPath(target));
146144
});
@@ -310,17 +308,6 @@ public String getBaseURL() {
310308
return "http://" + getHost() + ':' + getMappedPort(this.httpPort);
311309
}
312310

313-
/**
314-
* Gets the current state of the HTTP port.
315-
* Helpful during the configure step for implementations to set a default port
316-
* if none was configured by the user.
317-
*
318-
* @return true if an httpPort was set, false otherwise.
319-
*/
320-
protected boolean isHttpPortSet() {
321-
return Objects.nonNull(httpPort);
322-
}
323-
324311
// Abstract
325312

326313
/**
@@ -329,7 +316,7 @@ protected boolean isHttpPortSet() {
329316
*
330317
* @return - the application install directory
331318
*/
332-
abstract protected String getApplicationInstallDirectory();
319+
protected abstract String getApplicationInstallDirectory();
333320

334321
// Helpers
335322

@@ -338,7 +325,7 @@ protected boolean isHttpPortSet() {
338325
*
339326
* @return - The temporary directory path
340327
*/
341-
protected static Path getTempDirectory() {
328+
protected static Path createTempDirectory() {
342329
if( Objects.nonNull(tempDirectory) ) {
343330
return tempDirectory;
344331
}

modules/application-server-commons/src/test/java/org/testcontainers/applicationserver/ApplicationServerContainerTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.testcontainers.utility.DockerImageName;
66

77
import java.time.Duration;
8+
import java.util.Arrays;
89
import java.util.List;
910
import java.util.concurrent.Future;
1011

@@ -39,7 +40,7 @@ public void testNormalizePath() {
3940
public void httpPortMapping() {
4041
List<Integer> expected, actual;
4142

42-
expected = List.of(8080, 9080, 9443);
43+
expected = Arrays.asList(8080, 9080, 9443);
4344

4445
// Test expose ports, then add httpPort
4546
testContainer = new ApplicationServerContainerStub(DockerImageName.parse("open-liberty:kernel-slim-java11-openj9"));
@@ -60,7 +61,7 @@ public void httpPortMapping() {
6061
//Test httpPort then set exposed ports
6162
testContainer = new ApplicationServerContainerStub(DockerImageName.parse("open-liberty:kernel-slim-java11-openj9"));
6263
testContainer.withHttpPort(8080);
63-
testContainer.setExposedPorts(List.of(9080, 9443));
64+
testContainer.setExposedPorts(Arrays.asList(9080, 9443));
6465

6566
actual = testContainer.getExposedPorts();
6667
assertThat(actual).containsExactlyElementsOf(expected);

modules/liberty/src/main/java/org/testcontainers/containers/LibertyServerContainer.java

+12-28
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
package org.testcontainers.containers;
22

33
import lombok.NonNull;
4+
import org.testcontainers.images.builder.Transferable;
45
import org.testcontainers.utility.DockerImageName;
56
import org.testcontainers.utility.MountableFile;
67
import org.testcontainers.applicationserver.ApplicationServerContainer;
78

8-
import java.io.IOException;
9-
import java.nio.charset.StandardCharsets;
10-
import java.nio.file.Files;
11-
import java.nio.file.Path;
12-
import java.nio.file.Paths;
13-
import java.nio.file.StandardOpenOption;
149
import java.time.Duration;
1510
import java.util.ArrayList;
1611
import java.util.Arrays;
@@ -22,19 +17,17 @@
2217
*/
2318
public class LibertyServerContainer extends ApplicationServerContainer {
2419

25-
public static final String NAME = "Liberty";
26-
2720
// About the image
28-
public static final String IMAGE = "open-liberty";
21+
static final String IMAGE = "open-liberty";
2922

30-
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse(IMAGE);
23+
static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse(IMAGE);
3124

3225
// Container defaults
33-
public static final int DEFAULT_HTTP_PORT = 9080;
26+
static final int DEFAULT_HTTP_PORT = 9080;
3427

35-
public static final int DEFAULT_HTTPS_PORT = 9443;
28+
static final int DEFAULT_HTTPS_PORT = 9443;
3629

37-
private static final Duration DEFAULT_WAIT_TIMEOUT = Duration.ofSeconds(30);
30+
static final Duration DEFAULT_WAIT_TIMEOUT = Duration.ofSeconds(30);
3831

3932
private static final String SERVER_CONFIG_DIR = "/config/";
4033

@@ -43,7 +36,7 @@ public class LibertyServerContainer extends ApplicationServerContainer {
4336
private static final List<String> DEFAULT_FEATURES = Arrays.asList("webProfile-10.0");
4437

4538
// Container fields
46-
private MountableFile serverConfiguration;
39+
private Transferable serverConfiguration;
4740

4841
private List<String> features = new ArrayList<>();
4942

@@ -74,16 +67,16 @@ public void configure() {
7467

7568
// Copy server configuration
7669
if( Objects.nonNull(serverConfiguration) ) {
77-
withCopyFileToContainer(serverConfiguration, SERVER_CONFIG_DIR + "server.xml");
70+
withCopyToContainer(serverConfiguration, SERVER_CONFIG_DIR + "server.xml");
7871
return;
7972
}
8073

8174
if ( ! features.isEmpty() ) {
82-
withCopyFileToContainer(generateServerConfiguration(features), SERVER_CONFIG_DIR + "server.xml");
75+
withCopyToContainer(generateServerConfiguration(features), SERVER_CONFIG_DIR + "server.xml");
8376
return;
8477
}
8578

86-
withCopyFileToContainer(generateServerConfiguration(DEFAULT_FEATURES), SERVER_CONFIG_DIR + "server.xml");
79+
withCopyToContainer(generateServerConfiguration(DEFAULT_FEATURES), SERVER_CONFIG_DIR + "server.xml");
8780

8881
}
8982

@@ -122,7 +115,7 @@ public LibertyServerContainer withFeatures(String... features) {
122115

123116
// Helpers
124117

125-
private static final MountableFile generateServerConfiguration(List<String> features) {
118+
private static final Transferable generateServerConfiguration(List<String> features) {
126119
String configContents = "";
127120
configContents += "<server><featureManager>";
128121
for(String feature : features) {
@@ -131,15 +124,6 @@ private static final MountableFile generateServerConfiguration(List<String> feat
131124
configContents += "</featureManager></server>";
132125
configContents += System.lineSeparator();
133126

134-
Path generatedConfigPath = Paths.get(getTempDirectory().toString(), "generatedServer.xml");
135-
136-
try {
137-
Files.write(generatedConfigPath, configContents.getBytes(StandardCharsets.UTF_8),
138-
StandardOpenOption.CREATE, StandardOpenOption.WRITE);
139-
} catch (IOException ioe) {
140-
throw new RuntimeException("Unable to generate server configuration at runtime", ioe);
141-
}
142-
143-
return MountableFile.forHostPath(generatedConfigPath);
127+
return Transferable.of(configContents);
144128
}
145129
}

modules/liberty/src/test/java/org/testcontainers/containers/LibertyContainerTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class LibertyContainerTest {
3333
.withTag("23.0.0.3-full-java17-openj9");
3434

3535
private static ApplicationServerContainer testContainer = new LibertyServerContainer(libertyImage)
36-
.withArchvies(createDeployment())
36+
.withArchives(createDeployment())
3737
.withAppContextRoot("test/app/service/")
3838
.withLazyEnv("mock.port", () -> "" + dependantService.getMappedPort(80))
3939
.dependsOn(dependantService);

0 commit comments

Comments
 (0)