Tuesday, 26 May 2020

WireMock: Verifying requests

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.



Previous                                                    Next                                                    Home

No comments:

Post a Comment