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

Add /health endpoint in waiting strategy #76

Merged
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 @@ -50,6 +50,8 @@ public class WireMockContainer extends GenericContainer<WireMockContainer> {
private static final String WIREMOCK_2_LATEST_TAG = "2.35.0";
/*package*/ static final String WIREMOCK_2_MINIMUM_SUPPORTED_VERSION = "2.0.0";

static final String WIREMOCK_HEALTH_CHECK_SUPPORT_MINIMUM_VERSION = "3.0.0-1";

public static final DockerImageName WIREMOCK_2_LATEST =
DockerImageName.parse(OFFICIAL_IMAGE_NAME).withTag(WIREMOCK_2_LATEST_TAG);

Expand All @@ -61,6 +63,11 @@ public class WireMockContainer extends GenericContainer<WireMockContainer> {
.forHttp("/__admin/mappings")
.withMethod("GET")
.forStatusCode(200);

private static final WaitStrategy HEALTH_CHECK_ENDPOINT_WAITER = Wait
.forHttp("/__admin/health")
.withMethod("GET")
.forStatusCode(200);
private static final int PORT = 8080;
private final StringBuilder wireMockArgs;
private final Map<String, Stub> mappingStubs = new HashMap<>();
Expand Down Expand Up @@ -91,7 +98,13 @@ public WireMockContainer(DockerImageName dockerImage) {
}

wireMockArgs = new StringBuilder();
setWaitStrategy(DEFAULT_WAITER);

if (version.isGreaterThanOrEqualTo(WIREMOCK_HEALTH_CHECK_SUPPORT_MINIMUM_VERSION)) {
setWaitStrategy(HEALTH_CHECK_ENDPOINT_WAITER);
}
else {
setWaitStrategy(DEFAULT_WAITER);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.wiremock.integrations.testcontainers;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.wiremock.integrations.testcontainers.testsupport.http.HttpResponse;
import org.wiremock.integrations.testcontainers.testsupport.http.TestHttpClient;

import static org.assertj.core.api.Assertions.assertThat;

@Testcontainers
public class WireMockContainerWithWireMockVersionThreeTest
{
@Container
WireMockContainer wiremockServer = new WireMockContainer("wiremock/wiremock:" + WireMockContainer.WIREMOCK_HEALTH_CHECK_SUPPORT_MINIMUM_VERSION)
.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");


@ParameterizedTest
@ValueSource(strings = {
"hello",
"/hello"
})
void helloWorld(String path) throws Exception {
// given
String url = wiremockServer.getUrl(path);

// when
HttpResponse response = new TestHttpClient().get(url);

// then
assertThat(response.getBody())
.as("Wrong response body")
.contains("Hello, world!");
}
}