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

fix: Use addExposedPort instead of setExposedPort which overrides user configuration #171

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -63,16 +63,18 @@ public class WireMockContainer extends GenericContainer<WireMockContainer> {
private static final String FILES_DIR = "/home/wiremock/__files/";

private static final String EXTENSIONS_DIR = "/var/wiremock/extensions/";
private static final int PORT = 8080;
private static final WaitStrategy DEFAULT_WAITER = Wait
.forHttp("/__admin/mappings")
.withMethod("GET")
.forStatusCode(200);
.forStatusCode(200)
.forPort(PORT);

private static final WaitStrategy HEALTH_CHECK_ENDPOINT_WAITER = Wait
.forHttp("/__admin/health")
.withMethod("GET")
.forStatusCode(200);
private static final int PORT = 8080;
.forStatusCode(200)
.forPort(PORT);
private final StringBuilder wireMockArgs;
private final Map<String, Stub> mappingStubs = new HashMap<>();
private final Map<String, MountableFile> mappingFiles = new HashMap<>();
Expand Down Expand Up @@ -371,7 +373,7 @@ public Integer getPort() {
@Override
protected void configure() {
super.configure();
withExposedPorts(PORT);
addExposedPorts(PORT);
for (Stub stub : mappingStubs.values()) {
withCopyToContainer(Transferable.of(stub.json), MAPPINGS_DIR + stub.name + ".json");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@

public class WireMockContainerJunit4Test {

private static final int WIREMOCK_DEFAULT_PORT = 8080;
private static final int ADDITIONAL_MAPPED_PORT = 8443;

@Rule
public WireMockContainer wiremockServer = new WireMockContainer(TestConfig.WIREMOCK_DEFAULT_IMAGE)
.withMapping("hello", WireMockContainerTest.class, "hello-world.json")
.withMapping("hello-resource", WireMockContainerTest.class, "hello-world-resource.json")
.withFileFromResource("hello-world-resource-response.xml", WireMockContainerTest.class, "hello-world-resource-response.xml");
.withFileFromResource("hello-world-resource-response.xml", WireMockContainerTest.class, "hello-world-resource-response.xml")
.withExposedPorts(ADDITIONAL_MAPPED_PORT);

@Test
public void helloWorld() throws Exception {
Expand Down Expand Up @@ -71,4 +75,15 @@ public void helloWorldFromFile() throws Exception {
.as("Wrong response body")
.contains("Hello, world!");
}

@Test
public void customPortsAreExposed() {
//given

//when

//then
assertThat(wiremockServer.getExposedPorts())
.contains(WIREMOCK_DEFAULT_PORT, ADDITIONAL_MAPPED_PORT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@
@Testcontainers(parallel = true)
class WireMockContainerTest {

private static final int WIREMOCK_DEFAULT_PORT = 8080;
private static final int ADDITIONAL_MAPPED_PORT = 8443;

@Container
WireMockContainer wiremockServer = new WireMockContainer(TestConfig.WIREMOCK_DEFAULT_IMAGE)
.withMapping("hello", WireMockContainerTest.class, "hello-world.json")
.withMapping("hello-resource", WireMockContainerTest.class, "hello-world-resource.json")
.withFileFromResource("hello-world-resource-response.xml", WireMockContainerTest.class,
"hello-world-resource-response.xml");
"hello-world-resource-response.xml")
.withExposedPorts(ADDITIONAL_MAPPED_PORT);


@ParameterizedTest
Expand Down Expand Up @@ -67,4 +71,15 @@ void helloWorldFromFile() throws Exception {
.as("Wrong response body")
.contains("Hello, world!");
}

@Test
void customPortsAreExposed() {
//given

//when

//then
assertThat(wiremockServer.getExposedPorts())
.contains(WIREMOCK_DEFAULT_PORT, ADDITIONAL_MAPPED_PORT);
}
}