Uses of Class
com.shri.restinpeace.mock.MockResponse
Packages that use MockResponse
-
Uses of MockResponse in com.shri.restinpeace.mock
Methods in com.shri.restinpeace.mock that return MockResponseModifier and TypeMethodDescriptionstatic MockResponseMockResponse.connectionFailure()Simulates a transport-level failure - the connection is closed before any response is sent, instead of returning an HTTP status - so a test can exercise RIP's "no response at all" error path (akong.unirest.UnirestExceptionthrown directly, not wrapped inRestInPeaceHttpException, and always retried by@Retryregardless ofretryOnStatus) instead of only ever seeing a non-2xx status.MockResponse.delay(long delayMillis) Delays sending this response bydelayMillis, to simulate a slow server - the way to prove@Timeout(readMillis = ...)(orRipClientConfig.readTimeoutMillis(...)) actually fires, rather than assuming it does because the annotation is present.Adds a response header.static MockResponseA200 OKresponse, serializingbodywith the same UnirestObjectMapperRIP itself delegates to (the oneRIP.setObjectMapper(kong.unirest.ObjectMapper)sets) - so a test can hand this a plain object instead of hand-writing a JSON string.static MockResponseMockResponse.noContent()A204 No Contentresponse.static MockResponseMockResponse.notModified()A304 Not Modifiedresponse, for a test simulating a cache revalidation hit - RIP's response cache sendsIf-None-Match/If-Modified-Sinceautomatically once a cachedGETentry goes stale, and expects exactly this status back to keep serving the previously-cached body instead of treating the response as a fresh one.static MockResponseA200 OKresponse with a body, defaultingContent-Typetoapplication/json- override viaheader(java.lang.String, java.lang.String)for a plain-text/other body.static MockResponseMockResponse.status(int status, byte[] body) A response with the given status and raw bytes, for a binary (byte[]/File-returning) call.static MockResponseA response with the given status and a raw body, no default headers.Methods in com.shri.restinpeace.mock with parameters of type MockResponseModifier and TypeMethodDescriptionMockRestServer.enqueue(MockResponse response) Queues a response for the next request that doesn't match any route registered viaMockRestServer.on(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 viaMockRestServer.on(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 asMockRestServer.enqueueFor(HTTPMethod, String, MockResponse), for a route registered viaMockRestServer.on(HTTPMethod, String, Map, MockResponse)with the samerequiredQueryParams.MockRestServer.on(HTTPMethod httpMethod, String pathTemplate, MockResponse response) Registers a response for every request matchinghttpMethodandpathTemplate- unlikeMockRestServer.enqueue(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 asMockRestServer.on(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 asMockRestServer.on(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 callingMockRestServer.on(HTTPMethod, String, MockResponse)withsuccessResponseand thenMockRestServer.enqueueFor(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 asMockRestServer.onPages(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 bareMockRestServer.onPages(HTTPMethod, String, MockResponse...)route would otherwise intercept too.