Search in sources :

Example 11 with WireMockResponse

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

the class AdminApiTest method returnsBadEntityStatusWhenInvalidMatchOperatorManyBodyPatterns.

@Test
public void returnsBadEntityStatusWhenInvalidMatchOperatorManyBodyPatterns() {
    WireMockResponse response = testClient.postJson("/__admin/mappings", "{\n" + "    \"request\": {\n" + "        \"bodyPatterns\": [\n" + "            {\n" + "                \"equalTo\": \"fine\"\n" + "            },\n" + "            {\n" + "                \"matching\": \"somebad]]][[stuff\"\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/1"));
    assertThat(errors.first().getDetail(), is("{\"matching\":\"somebad]]][[stuff\"} is not a valid match operation"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Errors(com.github.tomakehurst.wiremock.common.Errors) Test(org.junit.jupiter.api.Test)

Example 12 with WireMockResponse

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

the class AdminApiTest method importMultipleStubsWithDefaultParameters.

@Test
public void importMultipleStubsWithDefaultParameters() {
    WireMockResponse response = testClient.postJson("/__admin/mappings/import", STUB_IMPORT_JSON);
    assertThat(response.statusCode(), is(200));
    List<StubMapping> allStubs = wm.getStubMappings();
    assertThat(allStubs.size(), is(2));
    assertThat(allStubs.get(0).getRequest().getUrl(), is("/one"));
    assertThat(allStubs.get(1).getRequest().getUrl(), is("/two"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) StubMapping(com.github.tomakehurst.wiremock.stubbing.StubMapping) Test(org.junit.jupiter.api.Test)

Example 13 with WireMockResponse

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

the class AdminApiTest method returnsBadEntityStatusWhenEqualToOperandIsWrongType.

@Test
public void returnsBadEntityStatusWhenEqualToOperandIsWrongType() {
    WireMockResponse response = testClient.postJson("/__admin/mappings", "{\n" + "    \"request\": {\n" + "        \"bodyPatterns\": [\n" + "            {\n" + "                \"equalTo\": 12\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("equalTo 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 14 with WireMockResponse

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

the class AdminApiTest method servesSwaggerSpec.

@Test
public void servesSwaggerSpec() {
    WireMockResponse response = testClient.get("/__admin/docs/swagger");
    assertThat(response.statusCode(), is(200));
    assertThat(response.content(), containsString("\"openapi\": \"3.0.0\""));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 15 with WireMockResponse

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

the class AdminApiTest method getLoggedRequestById.

@Test
public void getLoggedRequestById() throws Exception {
    for (int i = 1; i <= 3; i++) {
        testClient.get("/received-request/" + i);
    }
    List<ServeEvent> serveEvents = dsl.getAllServeEvents();
    UUID servedStubId = serveEvents.get(1).getId();
    WireMockResponse response = testClient.get("/__admin/requests/" + servedStubId);
    String body = response.content();
    System.out.println("BODY:" + body);
    assertThat(response.statusCode(), is(200));
    JsonVerifiable check = JsonAssertion.assertThat(body);
    check.field("id").isEqualTo(servedStubId);
    check.field("request").field("url").isEqualTo("/received-request/2");
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) ServeEvent(com.github.tomakehurst.wiremock.stubbing.ServeEvent) UUID(java.util.UUID) JsonVerifiable(com.toomuchcoding.jsonassert.JsonVerifiable) 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