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");
}
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");
}
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);
}
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);
}
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);
}
Aggregations