Search in sources :

Example 1 with JsonVerifiable

use of com.toomuchcoding.jsonassert.JsonVerifiable 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 2 with JsonVerifiable

use of com.toomuchcoding.jsonassert.JsonVerifiable 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)

Example 3 with JsonVerifiable

use of com.toomuchcoding.jsonassert.JsonVerifiable in project wiremock by wiremock.

the class AdminApiTest method getLoggedRequestsWithLimit.

@Test
public void getLoggedRequestsWithLimit() throws Exception {
    dsl.stubFor(get(urlPathEqualTo("/received-request/7")).willReturn(aResponse().withStatus(200).withBody("This was matched")));
    for (int i = 1; i <= 7; i++) {
        testClient.get("/received-request/" + i);
    }
    String body = testClient.get("/__admin/requests?limit=2").content();
    JsonVerifiable check = JsonAssertion.assertThat(body);
    check.field("meta").field("total").isEqualTo(7);
    check.field("requests").elementWithIndex(0).field("request").field("url").isEqualTo("/received-request/7");
    check.field("requests").elementWithIndex(1).field("request").field("url").isEqualTo("/received-request/6");
    check.field("requests").hasSize(2);
}
Also used : JsonVerifiable(com.toomuchcoding.jsonassert.JsonVerifiable) Test(org.junit.jupiter.api.Test)

Example 4 with JsonVerifiable

use of com.toomuchcoding.jsonassert.JsonVerifiable in project wiremock by wiremock.

the class AdminApiTest method getLoggedRequestsWithLimitLargerThanResults.

@Test
public void getLoggedRequestsWithLimitLargerThanResults() throws Exception {
    for (int i = 1; i <= 3; i++) {
        testClient.get("/received-request/" + i);
    }
    String body = testClient.get("/__admin/requests?limit=3000").content();
    JsonVerifiable check = JsonAssertion.assertThat(body);
    check.field("meta").field("total").isEqualTo(3);
    check.field("requests").hasSize(3);
}
Also used : JsonVerifiable(com.toomuchcoding.jsonassert.JsonVerifiable) Test(org.junit.jupiter.api.Test)

Example 5 with JsonVerifiable

use of com.toomuchcoding.jsonassert.JsonVerifiable in project wiremock by wiremock.

the class AdminApiTest method getLoggedRequests.

@Test
public void getLoggedRequests() throws Exception {
    dsl.stubFor(get(urlPathEqualTo("/received-request/4")).willReturn(aResponse()));
    for (int i = 1; i <= 5; i++) {
        testClient.get("/received-request/" + i);
    }
    String body = testClient.get("/__admin/requests").content();
    System.out.println(body);
    JsonVerifiable check = JsonAssertion.assertThat(body);
    check.field("meta").field("total").isEqualTo(5);
    check.field("requests").elementWithIndex(2).field("request").field("url").isEqualTo("/received-request/3");
    check.field("requests").hasSize(5);
    check.field("requests").elementWithIndex(1).field("wasMatched").isEqualTo(true);
    check.field("requests").elementWithIndex(3).field("wasMatched").isEqualTo(false);
}
Also used : JsonVerifiable(com.toomuchcoding.jsonassert.JsonVerifiable) Test(org.junit.jupiter.api.Test)

Aggregations

JsonVerifiable (com.toomuchcoding.jsonassert.JsonVerifiable)6 Test (org.junit.jupiter.api.Test)6 WireMockResponse (com.github.tomakehurst.wiremock.testsupport.WireMockResponse)2 ISO8601DateFormat (com.fasterxml.jackson.databind.util.ISO8601DateFormat)1 ServeEvent (com.github.tomakehurst.wiremock.stubbing.ServeEvent)1 Date (java.util.Date)1 UUID (java.util.UUID)1