Search in sources :

Example 76 with WireMockResponse

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

the class StubbingAcceptanceTest method jsonResponseWithStringValue.

@Test
public void jsonResponseWithStringValue() {
    stubFor(get("/json-from-string").willReturn(jsonResponse("{ \"message\": \"Json From String\" }", 200)));
    WireMockResponse response = testClient.get("/json-from-string");
    assertThat(response.statusCode(), is(200));
    assertThat(response.firstHeader(HttpHeaders.CONTENT_TYPE), is("application/json"));
    assertThat(response.content(), containsString("\"Json From String\""));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 77 with WireMockResponse

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

the class StubbingAcceptanceTest method mappingWithCaseInsensitiveHeaderMatchers.

@Test
public void mappingWithCaseInsensitiveHeaderMatchers() {
    stubFor(put(urlEqualTo("/case/insensitive")).withHeader("ONE", equalTo("abcd1234")).withHeader("two", matching("[a-z]{5}")).withHeader("Three", notMatching("[A-Z]+")).willReturn(aResponse().withStatus(204)));
    WireMockResponse response = testClient.put("/case/insensitive", withHeader("one", "abcd1234"), withHeader("TWO", "thing"), withHeader("tHrEe", "something"));
    assertThat(response.statusCode(), is(204));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 78 with WireMockResponse

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

the class TransferEncodingAcceptanceTest method sendsTransferEncodingChunkedWhenPolicyIsBodyFileAndBodyFileIsUsed.

@Test
public void sendsTransferEncodingChunkedWhenPolicyIsBodyFileAndBodyFileIsUsed() {
    startWithChunkedEncodingPolicy(Options.ChunkedEncodingPolicy.BODY_FILE);
    final String fileUrl = "/chunked-encoding-body";
    final String inlineBodyUrl = "/chunked-encoding-body-file";
    wm.stubFor(get(fileUrl).willReturn(ok().withBodyFile("plain-example.txt")));
    wm.stubFor(get(inlineBodyUrl).willReturn(ok("Body content")));
    WireMockResponse response = testClient.get(fileUrl);
    assertThat(response.statusCode(), is(200));
    assertThat(response.firstHeader("Transfer-Encoding"), is("chunked"));
    assertThat(response.firstHeader("Content-Length"), nullValue());
    response = testClient.get(inlineBodyUrl);
    assertThat(response.statusCode(), is(200));
    assertThat(response.firstHeader("Transfer-Encoding"), nullValue());
    assertThat(response.firstHeader("Content-Length"), notNullValue());
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 79 with WireMockResponse

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

the class TransferEncodingAcceptanceTest method sendsContentLengthWhenTransferEncodingChunkedPolicyIsNeverAndDribbleDelayIsApplied.

@Test
public void sendsContentLengthWhenTransferEncodingChunkedPolicyIsNeverAndDribbleDelayIsApplied() {
    startWithChunkedEncodingPolicy(Options.ChunkedEncodingPolicy.NEVER);
    final String url = "/content-length-encoding";
    final String body = "Slightly longer body content in this string";
    wm.stubFor(get(url).willReturn(ok(body).withChunkedDribbleDelay(5, 200)));
    WireMockResponse response = testClient.get(url);
    assertThat(response.statusCode(), is(200));
    String expectedContentLength = String.valueOf(body.getBytes().length);
    assertThat(response.firstHeader("Transfer-Encoding"), nullValue());
    assertThat(response.firstHeader("Content-Length"), is(expectedContentLength));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 80 with WireMockResponse

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

the class TransferEncodingAcceptanceTest method sendsTransferEncodingChunkedWhenPolicyIsAlways.

@Test
public void sendsTransferEncodingChunkedWhenPolicyIsAlways() {
    startWithChunkedEncodingPolicy(Options.ChunkedEncodingPolicy.ALWAYS);
    final String url = "/chunked-encoding-always";
    final String body = "Body content";
    wm.stubFor(get(url).willReturn(ok(body)));
    WireMockResponse response = testClient.get(url);
    assertThat(response.statusCode(), is(200));
    assertThat(response.firstHeader("Transfer-Encoding"), is("chunked"));
    assertThat(response.firstHeader("Content-Length"), nullValue());
}
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