Search in sources :

Example 51 with WireMockResponse

use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.

the class NotMatchedPageAcceptanceTest method adjustsWidthWhenConsoleWidthHeaderSpecified.

@Test
public void adjustsWidthWhenConsoleWidthHeaderSpecified() {
    configure();
    stubFor(post("/thing").withName("The post stub with a really long name that ought to wrap and let us see exactly how that looks when it is done").withHeader("X-My-Header", containing("correct value")).withHeader("Accept", matching("text/plain.*")).withRequestBody(equalToJson("{                              \n" + "    \"thing\": {               \n" + "        \"stuff\": [1, 2, 3]   \n" + "    }                          \n" + "}")).willReturn(ok()));
    WireMockResponse response = testClient.postJson("/thin", "{                        \n" + "    \"thing\": {           \n" + "        \"nothing\": {}    \n" + "    }                      \n" + "}", withHeader("X-My-Header", "wrong value"), withHeader("Accept", "text/plain"), withHeader(CONSOLE_WIDTH_HEADER_KEY, "69"));
    System.out.println(response.content());
    assertThat(response.content(), equalsMultiLine(file("not-found-diff-sample_ascii-narrow.txt")));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 52 with WireMockResponse

use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.

the class NotMatchedPageAcceptanceTest method supportsCustomNoMatchRenderer.

@Test
public void supportsCustomNoMatchRenderer() {
    configure(wireMockConfig().notMatchedRenderer(new NotMatchedRenderer() {

        @Override
        protected ResponseDefinition render(Admin admin, Request request) {
            return ResponseDefinitionBuilder.responseDefinition().withStatus(403).withBody("No you don't!").build();
        }
    }));
    WireMockResponse response = testClient.get("/should-not-match");
    assertThat(response.statusCode(), is(403));
    assertThat(response.content(), is("No you don't!"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) NotMatchedRenderer(com.github.tomakehurst.wiremock.verification.notmatched.NotMatchedRenderer) Request(com.github.tomakehurst.wiremock.http.Request) Admin(com.github.tomakehurst.wiremock.core.Admin) Test(org.junit.jupiter.api.Test)

Example 53 with WireMockResponse

use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.

the class NotMatchedPageAcceptanceTest method showsADefaultMessageWhenNoStubsWerePresent.

@Test
public void showsADefaultMessageWhenNoStubsWerePresent() {
    configure();
    WireMockResponse response = testClient.get("/no-stubs-to-match");
    assertThat(response.statusCode(), is(404));
    assertThat(response.firstHeader(CONTENT_TYPE), is("text/plain"));
    assertThat(response.content(), is("No response could be served as there are no stub mappings in this WireMock instance."));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 54 with WireMockResponse

use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.

the class NotMatchedPageAcceptanceTest method showsNotFoundDiffMessageWhenRequestBodyIsGZipped.

@Test
public void showsNotFoundDiffMessageWhenRequestBodyIsGZipped() {
    configure();
    stubFor(post(urlPathEqualTo("/gzip")).withHeader("Content-Encoding", equalToIgnoreCase("gzip")).withRequestBody(equalToJson("{\"id\":\"ok\"}")).willReturn(ok()));
    ByteArrayEntity entity = new ByteArrayEntity(Gzip.gzip("{\"id\":\"wrong\"}"), ContentType.DEFAULT_BINARY);
    WireMockResponse response = testClient.post("/gzip", entity, withHeader("Content-Encoding", "gzip"));
    assertThat(response.statusCode(), is(404));
    assertThat(response.content(), containsString("Request was not matched"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) ByteArrayEntity(org.apache.hc.core5.http.io.entity.ByteArrayEntity) Test(org.junit.jupiter.api.Test)

Example 55 with WireMockResponse

use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.

the class NotMatchedPageAcceptanceTest method showsNotFoundDiffMessageForNonStandardHttpMethods.

@Test
public void showsNotFoundDiffMessageForNonStandardHttpMethods() {
    configure();
    stubFor(request("PAAARP", urlPathEqualTo("/pip")).willReturn(ok()));
    WireMockResponse response = testClient.request("PAAARP", "/pop");
    assertThat(response.statusCode(), is(404));
    assertThat(response.content(), containsString("Request was not matched"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) 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