Search in sources :

Example 1 with WireMockResponse

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

the class ProxyAcceptanceTest method stripsCorsHeadersFromTheTarget.

@Test
public void stripsCorsHeadersFromTheTarget() {
    initWithDefaultConfig();
    proxy.register(any(anyUrl()).willReturn(aResponse().proxiedFrom(targetServiceBaseUrl)));
    target.register(any(urlPathEqualTo("/cors")).withName("Target with CORS").willReturn(ok()));
    WireMockResponse response = testClient.get("/cors", withHeader("Origin", "http://somewhere.com"));
    Collection<String> allowOriginHeaderValues = response.headers().get("Access-Control-Allow-Origin");
    assertThat(allowOriginHeaderValues.size(), is(0));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 2 with WireMockResponse

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

the class AdminApiTest method returnsBadEntityStatusWhenContainsOperandIsNull.

@Test
public void returnsBadEntityStatusWhenContainsOperandIsNull() {
    WireMockResponse response = testClient.postJson("/__admin/mappings", "{\n" + "    \"request\": {\n" + "        \"bodyPatterns\": [\n" + "            {\n" + "                \"contains\": null\n" + "            }\n" + "        ]\n" + "    }\n" + "}");
    assertThat(response.statusCode(), is(422));
    Errors errors = Json.read(response.content(), Errors.class);
    assertThat(errors.first().getSource().getPointer(), is("/request/bodyPatterns/0"));
    assertThat(errors.first().getTitle(), is("Error parsing JSON"));
    assertThat(errors.first().getDetail(), is("contains operand must be a non-null string"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Errors(com.github.tomakehurst.wiremock.common.Errors) Test(org.junit.jupiter.api.Test)

Example 3 with WireMockResponse

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

the class AdminApiTest method getLoggedRequestsWithInvalidSinceDateReturnsBadRequest.

@Test
public void getLoggedRequestsWithInvalidSinceDateReturnsBadRequest() throws Exception {
    WireMockResponse response = testClient.get("/__admin/requests?since=foo");
    assertThat(response.statusCode(), is(400));
    assertThat(response.firstHeader("Content-Type"), is("application/json"));
    JsonVerifiable check = JsonAssertion.assertThat(response.content());
    JsonVerifiable error = check.field("errors").elementWithIndex(0);
    error.field("code").isEqualTo(10);
    error.field("source").field("pointer").isEqualTo("since");
    error.field("title").isEqualTo("foo is not a valid ISO8601 date");
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) JsonVerifiable(com.toomuchcoding.jsonassert.JsonVerifiable) Test(org.junit.jupiter.api.Test)

Example 4 with WireMockResponse

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

the class AdminApiTest method treatsEmptyOrNullUuidFieldsAsNotPresent.

@Test
public void treatsEmptyOrNullUuidFieldsAsNotPresent() {
    WireMockResponse response = testClient.postJson("/__admin/mappings/import", EMPTY_UUID_IMPORT_JSON);
    assertThat(response.statusCode(), is(200));
    List<StubMapping> stubs = wireMockServer.listAllStubMappings().getMappings();
    assertThat(stubs, everyItem(hasIdAndUuid()));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) StubMapping(com.github.tomakehurst.wiremock.stubbing.StubMapping) Test(org.junit.jupiter.api.Test)

Example 5 with WireMockResponse

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

the class AdminApiTest method listStubFiles.

@Test
public void listStubFiles() throws Exception {
    FileSource fileSource = wireMockServer.getOptions().filesRoot().child(FILES_ROOT);
    fileSource.createIfNecessary();
    fileSource.writeTextFile("bar.txt", "contents");
    fileSource.writeTextFile("zoo.txt", "contents");
    WireMockResponse response = testClient.get("/__admin/files");
    assertEquals(200, response.statusCode());
    String pathSeparatorRegex = File.separator;
    if (File.separator.equals("\\")) {
        pathSeparatorRegex = "\\\\";
    }
    assertThat(new String(response.binaryContent()), matches("\\[ \".*" + pathSeparatorRegex + "bar.txt\", \".*zoo.*txt\" ]"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) FileSource(com.github.tomakehurst.wiremock.common.FileSource) 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