Search in sources :

Example 91 with WireMockResponse

use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.

the class MappingsAcceptanceTest method appendsTransferEncodingHeaderIfNoContentLengthHeaderIsPresentInMapping.

@Test
public void appendsTransferEncodingHeaderIfNoContentLengthHeaderIsPresentInMapping() throws Exception {
    testClient.addResponse("{ 													\n" + "	\"request\": {									\n" + "		\"method\": \"GET\",						\n" + "		\"url\": \"/with/body\"						\n" + "	},												\n" + "	\"response\": {									\n" + "		\"status\": 200,							\n" + "		\"body\": \"Some content\"					\n" + "	}												\n" + "}													");
    WireMockResponse response = testClient.get("/with/body");
    assertThat(response.firstHeader("Transfer-Encoding"), is("chunked"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 92 with WireMockResponse

use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.

the class MappingsAcceptanceTest method getResponseAndAssert200Status.

private void getResponseAndAssert200Status(String url) {
    WireMockResponse response = testClient.get(url);
    assertThat(response.statusCode(), is(200));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse)

Example 93 with WireMockResponse

use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.

the class MappingsAcceptanceTest method basicMappingCheckNonUtf8.

@Test
public void basicMappingCheckNonUtf8() {
    testClient.addResponse(MappingJsonSamples.MAPPING_REQUEST_FOR_NON_UTF8, "GB2312");
    WireMockResponse response = testClient.get("/test/nonutf8/");
    assertThat(response.statusCode(), is(200));
    assertThat(response.content(), is("国家标准"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 94 with WireMockResponse

use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.

the class MappingsAcceptanceTest method basicMappingCheckCharsetMismatch.

@Test
public void basicMappingCheckCharsetMismatch() {
    testClient.addResponse(MappingJsonSamples.MAPPING_REQUEST_FOR_NON_UTF8, "ISO-8859-8");
    WireMockResponse response = testClient.get("/test/nonutf8/");
    assertThat(response.statusCode(), is(200));
    // charset in request doesn't match body content
    assertThat(response.content(), is("????"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 95 with WireMockResponse

use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.

the class RequestFilterAcceptanceTest method filterCanBeAppliedToStubs.

@Test
public void filterCanBeAppliedToStubs() {
    initialise(new StubAuthenticatingFilter());
    wm.stubFor(get(url).willReturn(ok()));
    String adminUrl = "/__admin/mappings";
    WireMockResponse good = client.get(url, withHeader("Authorization", "Token 123"));
    assertThat(good.statusCode(), is(200));
    WireMockResponse bad = client.get(url);
    assertThat(bad.statusCode(), is(401));
    // Admin routes are unaffected
    WireMockResponse stub = client.get(adminUrl);
    assertThat(stub.statusCode(), is(200));
}
Also used : 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