Search in sources :

Example 66 with WireMockResponse

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"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 67 with WireMockResponse

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));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 68 with WireMockResponse

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));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 69 with WireMockResponse

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));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 70 with WireMockResponse

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\""));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) 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