Uses of Class
com.shri.restinpeace.mock.MockRestServer
Packages that use MockRestServer
-
Uses of MockRestServer in com.shri.restinpeace.mock
Methods in com.shri.restinpeace.mock that return MockRestServerModifier and TypeMethodDescriptionMockRestServer.enqueue(MockResponse response) Queues a response for the next request that doesn't match any route registered viaon(com.shri.restinpeace.constant.HTTPMethod, java.lang.String, com.shri.restinpeace.mock.MockResponse)- a route always wins over this queue for a request it matches, so this only ever answers a path with no matching route at all.MockRestServer.enqueueFor(HTTPMethod httpMethod, String pathTemplate, MockResponse response) Scripts a one-time response for a route already registered viaon(HTTPMethod, String, MockResponse), consumed - in the order queued - before that route's sticky response, the way to combine a scripted failure sequence with a sticky final answer for the same path (e.g. a503then a200, to prove@Retryrecovers, while every request after that still gets the200the route was registered with).MockRestServer.enqueueFor(HTTPMethod httpMethod, String pathTemplate, Map<String, String> requiredQueryParams, MockResponse response) Same asenqueueFor(HTTPMethod, String, MockResponse), for a route registered viaon(HTTPMethod, String, Map, MockResponse)with the samerequiredQueryParams.MockRestServerExtension.getServer()Returns the server for the current test class - only meaningful oncebeforeAllhas run.MockRestServer.on(HTTPMethod httpMethod, String pathTemplate, MockResponse response) Registers a response for every request matchinghttpMethodandpathTemplate- unlikeenqueue(com.shri.restinpeace.mock.MockResponse), this doesn't get consumed; it keeps answering every matching request the same way.MockRestServer.on(HTTPMethod httpMethod, String pathTemplate, Predicate<RecordedRequest> matcher, MockResponse response) Same ason(HTTPMethod, String, MockResponse), but only matches a request for whichmatcheralso returnstrue- for matching on a request header or the request body, neither of which therequiredQueryParamsoverload covers, e.g.MockRestServer.on(HTTPMethod httpMethod, String pathTemplate, Map<String, String> requiredQueryParams, MockResponse response) Same ason(HTTPMethod, String, MockResponse), but only matches a request whose query params contain every entry inrequiredQueryParamswith an equal value - any other query params the request carries are ignored.MockRestServer.onFlaky(HTTPMethod httpMethod, String pathTemplate, int failuresBeforeSuccess, MockResponse failureResponse, MockResponse successResponse) Registers a route that failsfailuresBeforeSuccesstimes withfailureResponsebefore settling intosuccessResponsefor every request after that - sugar for callingon(HTTPMethod, String, MockResponse)withsuccessResponseand thenenqueueFor(com.shri.restinpeace.constant.HTTPMethod, java.lang.String, com.shri.restinpeace.mock.MockResponse)withfailureResponsefailuresBeforeSuccesstimes.MockRestServer.onPages(HTTPMethod httpMethod, String pathTemplate, MockResponse... responses) Scripts an ordered sequence of responses for a route - the 1st matching request getsresponses[0], the 2nd getsresponses[1], and so on, with the last response answering every request after the sequence is exhausted.MockRestServer.onPages(HTTPMethod httpMethod, String pathTemplate, Map<String, String> requiredQueryParams, MockResponse... responses) Same asonPages(HTTPMethod, String, MockResponse...), but only matches a request whose query params contain every entry inrequiredQueryParams- for a path also serving other, non-paginated traffic that a bareonPages(HTTPMethod, String, MockResponse...)route would otherwise intercept too.MockRestServer.reset()Clears every queued response, registered route, and recorded request, so the same server can be reused across multiple tests instead of paying to start a new one for each - e.g. from a@BeforeEachmethod, with the server itself started once in a@BeforeAll.static MockRestServerMockRestServer.start()Starts a new server on an OS-assigned loopback port.