Search in sources :

Example 56 with WireMockResponse

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

the class NotMatchedPageAcceptanceTest method returns404AndDiffReportWhenPlusSymbolInQuery.

@Test
public void returns404AndDiffReportWhenPlusSymbolInQuery() {
    configure();
    WireMockResponse response = testClient.get("/some/api/records?sort=updated+asc&filter_updated_gt=2019-01-02");
    System.err.println(response.content());
    assertThat(response.statusCode(), is(404));
    assertThat(response.content(), containsString("No response could be served"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 57 with WireMockResponse

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

the class PortNumberTest method canRunOnAnotherPortThan8080.

@Test
public void canRunOnAnotherPortThan8080() {
    int port = Network.findFreePort();
    WireMockServer wireMockServer = createServer(wireMockConfig().port(port));
    wireMockServer.start();
    WireMockTestClient wireMockClient = new WireMockTestClient(port);
    wireMockClient.addResponse(MappingJsonSamples.BASIC_MAPPING_REQUEST_WITH_RESPONSE_HEADER);
    WireMockResponse response = wireMockClient.get("/a/registered/resource");
    assertThat(response.statusCode(), is(401));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) WireMockTestClient(com.github.tomakehurst.wiremock.testsupport.WireMockTestClient) Test(org.junit.jupiter.api.Test)

Example 58 with WireMockResponse

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

the class PostServeActionExtensionTest method canBeSpecifiedAsAJsonObject.

@Test
public void canBeSpecifiedAsAJsonObject() {
    initWithOptions(options().dynamicPort().notifier(new ConsoleNotifier(true)).extensions(new NamedCounterAction()));
    WireMockResponse response = client.postJson("/__admin/mappings", "{\n" + "  \"request\" : {\n" + "    \"urlPath\" : \"/count-me\",\n" + "    \"method\" : \"GET\"\n" + "  },\n" + "  \"response\" : {\n" + "    \"status\" : 200\n" + "  },\n" + "  \"postServeActions\": {\n" + "    \"count-request\": {\n" + "      \"counterName\": \"things\"\n" + "    } \n" + "  }\n" + "}");
    assertThat(response.content(), response.statusCode(), is(201));
    client.get("/count-me");
    client.get("/count-me");
    await().atMost(5, SECONDS).until(getContent("/__admin/named-counter/things"), is("2"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) ConsoleNotifier(com.github.tomakehurst.wiremock.common.ConsoleNotifier) Test(org.junit.jupiter.api.Test)

Example 59 with WireMockResponse

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

the class ProxyAcceptanceTest method addsSpecifiedHeadersToResponse.

@Test
public void addsSpecifiedHeadersToResponse() {
    initWithDefaultConfig();
    target.register(get(urlEqualTo("/extra/headers")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "text/plain").withBody("Proxied content")));
    proxy.register(any(urlEqualTo("/extra/headers")).willReturn(aResponse().withHeader("X-Additional-Header", "Yep").proxiedFrom(targetServiceBaseUrl)));
    WireMockResponse response = testClient.get("/extra/headers");
    assertThat(response.firstHeader("Content-Type"), is("text/plain"));
    assertThat(response.firstHeader("X-Additional-Header"), is("Yep"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 60 with WireMockResponse

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

the class ProxyAcceptanceTest method removesPrefixFromProxyRequestWhenMatching.

@Test
public void removesPrefixFromProxyRequestWhenMatching() {
    initWithDefaultConfig();
    proxy.register(get("/other/service/doc/123").willReturn(aResponse().proxiedFrom(targetServiceBaseUrl + "/approot").withProxyUrlPrefixToRemove("/other/service")));
    target.register(get("/approot/doc/123").willReturn(ok()));
    WireMockResponse response = testClient.get("/other/service/doc/123");
    assertThat(response.statusCode(), is(200));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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