Search in sources :

Example 81 with WireMockResponse

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!"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 82 with WireMockResponse

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"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) WireMockTestClient(com.github.tomakehurst.wiremock.testsupport.WireMockTestClient) Stopwatch(com.google.common.base.Stopwatch) Test(org.junit.jupiter.api.Test)

Example 83 with WireMockResponse

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"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 84 with WireMockResponse

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));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 85 with WireMockResponse

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"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) WireMockTestClient(com.github.tomakehurst.wiremock.testsupport.WireMockTestClient) Matchers.containsString(org.hamcrest.Matchers.containsString) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) Test(org.junit.jupiter.api.Test)

Aggregations

WireMockResponse (com.github.tomakehurst.wiremock.testsupport.WireMockResponse)172 Test (org.junit.jupiter.api.Test)168 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 Errors (com.github.tomakehurst.wiremock.common.Errors)11 WireMockTestClient (com.github.tomakehurst.wiremock.testsupport.WireMockTestClient)9 StubMapping (com.github.tomakehurst.wiremock.stubbing.StubMapping)7 UUID (java.util.UUID)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Stopwatch (com.google.common.base.Stopwatch)3 ByteArrayEntity (org.apache.hc.core5.http.io.entity.ByteArrayEntity)3 StringEntity (org.apache.hc.core5.http.io.entity.StringEntity)3 ConsoleNotifier (com.github.tomakehurst.wiremock.common.ConsoleNotifier)2 Request (com.github.tomakehurst.wiremock.http.Request)2 JsonVerifiable (com.toomuchcoding.jsonassert.JsonVerifiable)2 IOException (java.io.IOException)2 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)1 WireMock (com.github.tomakehurst.wiremock.client.WireMock)1 FileSource (com.github.tomakehurst.wiremock.common.FileSource)1 SingleRootFileSource (com.github.tomakehurst.wiremock.common.SingleRootFileSource)1 Admin (com.github.tomakehurst.wiremock.core.Admin)1