use of com.github.tomakehurst.wiremock.testsupport.WireMockTestClient in project wiremock by wiremock.
the class DelayAndCustomMatcherAcceptanceTest method delayIsAddedWhenCustomResponseTransformerPresent.
@Test
public void delayIsAddedWhenCustomResponseTransformerPresent() {
stubFor(get(urlEqualTo("/delay-this")).willReturn(aResponse().withStatus(200).withTransformers("response-body-changer").withUniformRandomDelay(500, 1000)));
WireMockTestClient client = new WireMockTestClient(wireMockRule.getPort());
Stopwatch stopwatch = Stopwatch.createStarted();
WireMockResponse response = client.get("/delay-this");
stopwatch.stop();
assertThat(stopwatch.elapsed(MILLISECONDS), greaterThanOrEqualTo(500L));
assertThat(response.statusCode(), is(200));
assertThat(response.content(), is("Transformed body"));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockTestClient in project wiremock by wiremock.
the class ClientAuthenticationAcceptanceTest method supportsCustomAuthenticator.
@Test
public void supportsCustomAuthenticator() {
initialise(new Authenticator() {
@Override
public boolean authenticate(Request request) {
return request.containsHeader("X-Magic-Header");
}
}, new ClientAuthenticator() {
@Override
public List<HttpHeader> generateAuthHeaders() {
return singletonList(httpHeader("X-Magic-Header", "blah"));
}
});
WireMockTestClient noAuthClient = new WireMockTestClient(server.port());
assertThat(noAuthClient.get("/__admin/mappings").statusCode(), is(401));
assertThat(noAuthClient.get("/__admin/mappings", withHeader("X-Magic-Header", "anything")).statusCode(), is(200));
// Throws an exception on a non 2xx response
goodClient.getServeEvents();
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockTestClient in project wiremock by wiremock.
the class ClientAuthenticationAcceptanceTest method canRequireHttpsOnAdminApi.
@Test
public void canRequireHttpsOnAdminApi() {
server = new WireMockServer(wireMockConfig().dynamicPort().dynamicHttpsPort().basicAdminAuthenticator("user", "password").requireHttpsForAdminApi());
server.start();
WireMockTestClient client = new WireMockTestClient(server.port());
String authHeader = new BasicCredentials("user", "password").asAuthorizationHeaderValue();
WireMockResponse response = client.get("/__admin/requests", withHeader(AUTHORIZATION, authHeader));
assertThat(response.statusCode(), is(403));
assertThat(response.content(), containsString("HTTPS is required for accessing the admin API"));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockTestClient in project wiremock by wiremock.
the class WireMockJUnitRuleTest method assertCanRegisterStubAndFetchOnCorrectPort.
public static void assertCanRegisterStubAndFetchOnCorrectPort(int port) {
givenThat(get(urlEqualTo("/rule/test")).willReturn(aResponse().withBody("Rule test body")));
WireMockTestClient testClient = new WireMockTestClient(port);
assertThat(testClient.get("/rule/test").content(), is("Rule test body"));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockTestClient in project wiremock by wiremock.
the class WireMockServerTests method supportsRecordingProgrammaticallyWithoutHeaderMatching.
// https://github.com/tomakehurst/wiremock/issues/193
@Test
public void supportsRecordingProgrammaticallyWithoutHeaderMatching() {
WireMockServer wireMockServer = new WireMockServer(DYNAMIC_PORT, new SingleRootFileSource(tempDir), false, new ProxySettings("proxy.company.com", DYNAMIC_PORT));
wireMockServer.start();
wireMockServer.enableRecordMappings(new SingleRootFileSource(tempDir + "/mappings"), new SingleRootFileSource(tempDir + "/__files"));
wireMockServer.stubFor(get(urlEqualTo("/something")).willReturn(aResponse().withStatus(200)));
WireMockTestClient client = new WireMockTestClient(wireMockServer.port());
assertThat(client.get("http://localhost:" + wireMockServer.port() + "/something").statusCode(), is(200));
}
Aggregations