use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class UrlMatchingAcceptanceTest method mappingMatchedWithRegexUrl.
@Test
public void mappingMatchedWithRegexUrl() {
String REGEX_URL_MAPPING_REQUEST = "{ \n" + " \"request\": { \n" + " \"method\": \"GET\", \n" + " \"urlPattern\": \"/one/(.*?)/three\" \n" + " }, \n" + " \"response\": { \n" + " \"body\": \"Matched!\" \n" + " } \n" + "} ";
testClient.addResponse(REGEX_URL_MAPPING_REQUEST);
WireMockResponse response = testClient.get("/one/two/three");
assertThat(response.statusCode(), is(200));
assertThat(response.content(), is("Matched!"));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse 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.WireMockResponse in project wiremock by wiremock.
the class EditMappingAcceptanceTest method editMappingViaTheJsonApi.
@Test
public void editMappingViaTheJsonApi() {
testClient.addResponse(MAPPING_REQUEST_WITH_UUID);
WireMockResponse response = testClient.get("/a/registered/resource");
assertThat(response.statusCode(), is(401));
assertThat(response.content(), is("Not allowed!"));
assertThat(response.firstHeader("Content-Type"), is("text/plain"));
testClient.editMapping(MODIFY_MAPPING_REQUEST_WITH_UUID);
response = testClient.get("/a/registered/resource");
assertThat(response.statusCode(), is(200));
assertThat(response.content(), is("OK"));
assertThat(response.firstHeader("Content-Type"), is("text/html"));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class HeaderMatchingAcceptanceTest method mappingWithExactUrlMethodAndHeaderMatchingIsCreatedAndReturned.
@Test
public void mappingWithExactUrlMethodAndHeaderMatchingIsCreatedAndReturned() {
testClient.addResponse(MappingJsonSamples.MAPPING_REQUEST_WITH_EXACT_HEADERS);
WireMockResponse response = testClient.get("/header/dependent", withHeader("Accept", "text/xml"), withHeader("If-None-Match", "abcd1234"));
assertThat(response.statusCode(), is(304));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse 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"));
}
Aggregations