WireMock provides a facility to verify that a request matching a specific pattern was received, and also to fetch the requests’ details.
Example
verify(exactly(1),getRequestedFor(urlPathEqualTo("/api/v1/employees")));
verify(exactly(1),getRequestedFor(urlPathEqualTo("/api/v1/employees")));
verify(exactly(1),getRequestedFor(urlPathMatching("/api/v1/employees/3")));
verify(exactly(1),getRequestedFor(urlPathMatching("/api/v1/employees/" + empId)));
verify(exactly(1),getRequestedFor(urlPathMatching("/api/v1/employees/" + empId)));
verify(exactly(1),postRequestedFor(urlPathEqualTo("/api/v1/employees")));
verify(exactly(1),postRequestedFor(urlPathEqualTo("/api/v1/employees")));
verify(exactly(1),postRequestedFor(urlPathEqualTo("/api/v1/employees")));
verify(exactly(1),postRequestedFor(urlPathEqualTo("/api/v1/employees")));
verify(exactly(1),putRequestedFor(urlPathEqualTo("/api/v1/employees/" + empId)));
verify(exactly(1),deleteRequestedFor(urlPathEqualTo("/api/v1/employees/" + empId)));
You can even check whether given API is called more than n times or not using moreThan function.
verify(moreThan(5),getRequestedFor(urlPathEqualTo("/api/v1/employees/")));
You can download the complete working application from this link.
No comments:
Post a Comment