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\""));
}
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));
}
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());
}
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));
}
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());
}
Aggregations