use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class StubbingAcceptanceTest method mappingWithUrlContainingQueryParameters.
@Test
public void mappingWithUrlContainingQueryParameters() {
stubFor(get(urlEqualTo("/search?name=John&postcode=N44LL")).willReturn(aResponse().withHeader("Location", "/nowhere").withStatus(302)));
WireMockResponse response = testClient.get("/search?name=John&postcode=N44LL");
assertThat(response.statusCode(), is(302));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class StubbingAcceptanceTest method matchingOnRequestBodyWithAdvancedXPath.
@Test
public void matchingOnRequestBodyWithAdvancedXPath() {
stubFor(post("/xpath/advanced").withRequestBody(matchingXPath("//counter/text()", equalTo("123"))).willReturn(ok()));
WireMockResponse response = testClient.postXml("/xpath/advanced", "<counter>6666</counter>");
assertThat(response.statusCode(), is(HTTP_NOT_FOUND));
response = testClient.postXml("/xpath/advanced", "<counter>123</counter>");
assertThat(response.statusCode(), is(HTTP_OK));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class StubbingAcceptanceTest method matchingOnRequestBodyWithAContainsAndANegativeRegex.
@Test
public void matchingOnRequestBodyWithAContainsAndANegativeRegex() {
stubFor(put(urlEqualTo("/match/this/body/too")).withRequestBody(containing("Blah")).withRequestBody(notMatching(".*[0-9]+.*")).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 matchingOnMultipartRequestBodyWithTwoRegexes.
@Test
public void matchingOnMultipartRequestBodyWithTwoRegexes() {
stubFor(post(urlEqualTo("/match/this/part")).withMultipartRequestBody(aMultipart().withBody(matching(".*Blah.*"))).withMultipartRequestBody(aMultipart().withBody(matching(".*@[0-9]{5}@.*"))).willReturn(aResponse().withStatus(HTTP_OK).withBodyFile("plain-example.txt")));
WireMockResponse response = testClient.postWithMultiparts("/match/this/part", singletonList(part("part-1", "Blah...but not the rest", TEXT_PLAIN)));
assertThat(response.statusCode(), is(HTTP_NOT_FOUND));
response = testClient.postWithMultiparts("/match/this/part", singletonList(part("part-1", "@12345@...but not the rest", TEXT_PLAIN)));
assertThat(response.statusCode(), is(HTTP_NOT_FOUND));
response = testClient.postWithMultiparts("/match/this/part", singletonList(part("good-part", "BlahBlah@56565@Blah", 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 getAndAssertUnderlyingExceptionInstanceClass.
private void getAndAssertUnderlyingExceptionInstanceClass(String url, Class<?> expectedClass) {
boolean thrown = false;
try {
WireMockResponse response = testClient.get(url);
response.content();
} catch (Exception e) {
assertThat(e.getCause(), instanceOf(expectedClass));
thrown = true;
}
assertTrue(thrown, "No exception was thrown");
}
Aggregations