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")));
}
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!"));
}
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."));
}
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"));
}
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"));
}
Aggregations