Search in sources :

Example 41 with WireMockResponse

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

the class MappingsAcceptanceTest method notFoundResponseIsReturnedForUnregisteredUrl.

@Test
public void notFoundResponseIsReturnedForUnregisteredUrl() {
    WireMockResponse response = testClient.get("/non-existent/resource");
    assertThat(response.statusCode(), is(HTTP_NOT_FOUND));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 42 with WireMockResponse

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

the class MappingsAcceptanceTest method readsJsonMapping.

@Test
public void readsJsonMapping() {
    WireMockResponse response = testClient.get("/testjsonmapping");
    assertThat(response.statusCode(), is(200));
    assertThat(response.content(), is("{\"bignumber\":1234567890.12,\"array\":[1,2,3],\"key\":\"value\"}"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 43 with WireMockResponse

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

the class MappingsAcceptanceTest method basicMappingWithExactUrlAndMethodMatchIsCreatedAndReturned.

@Test
public void basicMappingWithExactUrlAndMethodMatchIsCreatedAndReturned() {
    testClient.addResponse(MappingJsonSamples.BASIC_MAPPING_REQUEST_WITH_RESPONSE_HEADER);
    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 44 with WireMockResponse

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

the class MappingsLoaderAcceptanceTest method mappingsLoadedFromJsonFiles.

@Test
public void mappingsLoadedFromJsonFiles() {
    buildWireMock(configuration);
    wireMockServer.loadMappingsUsing(new JsonFileMappingsSource(new SingleRootFileSource(filePath("test-requests"))));
    WireMockResponse response = testClient.get("/canned/resource/1");
    assertThat(response.statusCode(), is(200));
    response = testClient.get("/canned/resource/2");
    assertThat(response.statusCode(), is(401));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) JsonFileMappingsSource(com.github.tomakehurst.wiremock.standalone.JsonFileMappingsSource) SingleRootFileSource(com.github.tomakehurst.wiremock.common.SingleRootFileSource) Test(org.junit.jupiter.api.Test)

Example 45 with WireMockResponse

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

the class MultipartBodyMatchingAcceptanceTest method multipartBodiesCanBeMatchedWhenStubsWithOtherBodyMatchTypesArePresent.

// https://github.com/tomakehurst/wiremock/issues/1179
@Test
public void multipartBodiesCanBeMatchedWhenStubsWithOtherBodyMatchTypesArePresent() {
    stubFor(post("/multipart").withMultipartRequestBody(aMultipart().withHeader("Content-Disposition", containing("wiremocktest"))).willReturn(ok()));
    stubFor(post("/json").withRequestBody(equalToJson("{ \"stuff\": 123 }")).willReturn(ok()));
    WireMockResponse response = testClient.postWithMultiparts("/multipart", singletonList(part("wiremocktest", "Whatever", TEXT_PLAIN)));
    assertThat(response.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