use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class StubbingAcceptanceTest method mappingWithExactUrlAndMethodMatch.
@Test
public void mappingWithExactUrlAndMethodMatch() {
stubFor(get(urlEqualTo("/a/registered/resource")).willReturn(aResponse().withStatus(401).withHeader("Content-Type", "text/plain").withBody("Not allowed!")));
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"));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class StubbingAcceptanceTest method doesNotAttemptToMatchXmlBodyWhenStubMappingDoesNotHaveOne.
@Test
public void doesNotAttemptToMatchXmlBodyWhenStubMappingDoesNotHaveOne() {
stubFor(options(urlEqualTo("/no-body")).willReturn(aResponse().withStatus(200)));
stubFor(post(urlEqualTo("/no-body")).withRequestBody(equalToXml("<some-xml />")).willReturn(aResponse().withStatus(201)));
WireMockResponse response = testClient.options("/no-body");
assertThat(response.statusCode(), is(200));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class StubbingAcceptanceTest method matchesQueryParamsUnencoded.
@Test
public void matchesQueryParamsUnencoded() {
stubFor(get(urlPathEqualTo("/query")).withQueryParam("param-one", equalTo("one two three ?")).willReturn(aResponse().withStatus(200)));
WireMockResponse response = testClient.get("/query?param-one=one%20two%20three%20%3F");
assertThat(response.statusCode(), is(200));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class StubbingAcceptanceTest method matchingOnRequestBodyWithEqualTo.
@Test
public void matchingOnRequestBodyWithEqualTo() {
stubFor(put(urlEqualTo("/match/this/body/too")).withRequestBody(equalTo("BlahBlahBlah")).willReturn(aResponse().withStatus(HTTP_OK).withBodyFile("plain-example.txt")));
WireMockResponse response = testClient.putWithBody("/match/this/body/too", "Blah12345", "text/plain");
assertThat(response.statusCode(), is(HTTP_NOT_FOUND));
response = testClient.putWithBody("/match/this/body/too", "BlahBlahBlah", "text/plain");
assertThat(response.statusCode(), is(HTTP_OK));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class StubbingAcceptanceTest method jsonResponseWithObjectValue.
@Test
public void jsonResponseWithObjectValue() {
stubFor(get("/json-from-object").willReturn(jsonResponse(new MockResponse("Json From Object"), 200)));
WireMockResponse response = testClient.get("/json-from-object");
assertThat(response.statusCode(), is(200));
assertThat(response.firstHeader(HttpHeaders.CONTENT_TYPE), is("application/json"));
assertThat(response.content(), containsString("\"Json From Object\""));
}
Aggregations