Package com.shri.restinpeace.mock
Class RecordedRequest
java.lang.Object
com.shri.restinpeace.mock.RecordedRequest
A single request
MockRestServer actually received, for a test to
assert against after making a call through a @RestClient
interface.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classOne part of a decodedmultipart/form-datarequest body, as returned bygetParts(). -
Method Summary
Modifier and TypeMethodDescriptiongetBody()Returns the raw request body, decoded as UTF-8 - for a binary body (a@Multipartrequest in particular, whose parts may not be text at all), decoding as a single UTF-8 string is lossy; usegetRawBody()orgetParts()instead.Decodes anapplication/x-www-form-urlencodedbody into its field name/value pairs, for asserting on what a@FormUrlEncodedmethod actually sent - a repeated key (from a@FieldMapentry, or aCollection-valued@Field) collects every value, in the order sent.Returns the first value of a request header, matched case-insensitively.Returns the request headers, keyed by name (case-insensitively).Returns the HTTP method of the request.getParts()Decodes amultipart/form-databody into its individual parts, for asserting on what a@Multipartmethod actually sent - each@Part/@PartMapentry becomes oneRecordedRequest.Part, with its name, optional file name, optional content type, and content.getPath()Returns the request path, without the query string.getQueryParam(String name) Returns the first value of a query param, since most are only ever sent once.getQueryParams(String name) Returns every value of a query param, matched case-sensitively (query param names, unlike headers, are case-sensitive per the URL spec).byte[]Returns the raw request body bytes, exactly as received - unlikegetBody(), safe for a binary body.Returns when this request was fully received - the way to verify timing-sensitive behavior like@Retry'sdelayMillis/backoffMultiplieractually growing the wait between attempts, rather than only counting how many attempts were made.
-
Method Details
-
getHttpMethod
Returns the HTTP method of the request.- Returns:
- the HTTP method
-
getPath
Returns the request path, without the query string.- Returns:
- the path
-
getReceivedAt
Returns when this request was fully received - the way to verify timing-sensitive behavior like@Retry'sdelayMillis/backoffMultiplieractually growing the wait between attempts, rather than only counting how many attempts were made.- Returns:
- when this request was received
-
getQueryParams
Returns every value of a query param, matched case-sensitively (query param names, unlike headers, are case-sensitive per the URL spec).- Parameters:
name- the query param name- Returns:
- the query param's values, or an empty list if it wasn't sent
-
getQueryParam
Returns the first value of a query param, since most are only ever sent once.- Parameters:
name- the query param name- Returns:
- the query param's first value, or
nullif it wasn't sent
-
getHeaders
Returns the request headers, keyed by name (case-insensitively).- Returns:
- the headers
-
getHeader
Returns the first value of a request header, matched case-insensitively.- Parameters:
name- the header name- Returns:
- the header's first value, or
nullif it wasn't sent
-
getBody
Returns the raw request body, decoded as UTF-8 - for a binary body (a@Multipartrequest in particular, whose parts may not be text at all), decoding as a single UTF-8 string is lossy; usegetRawBody()orgetParts()instead.- Returns:
- the request body, or an empty string if none was sent
-
getRawBody
public byte[] getRawBody()Returns the raw request body bytes, exactly as received - unlikegetBody(), safe for a binary body.- Returns:
- the raw request body bytes, or an empty array if none was sent
-
getParts
Decodes amultipart/form-databody into its individual parts, for asserting on what a@Multipartmethod actually sent - each@Part/@PartMapentry becomes oneRecordedRequest.Part, with its name, optional file name, optional content type, and content.- Returns:
- the decoded parts, in the order they were sent
- Throws:
IllegalStateException- if this request'sContent-Typeisn'tmultipart/*, or has noboundary
-
getFormFields
Decodes anapplication/x-www-form-urlencodedbody into its field name/value pairs, for asserting on what a@FormUrlEncodedmethod actually sent - a repeated key (from a@FieldMapentry, or aCollection-valued@Field) collects every value, in the order sent.- Returns:
- the decoded form fields, keyed by name in the order first seen
- Throws:
IllegalStateException- if this request'sContent-Typeisn'tapplication/x-www-form-urlencoded
-