Class RecordedRequest

java.lang.Object
com.shri.restinpeace.mock.RecordedRequest

public final class RecordedRequest extends Object
A single request MockRestServer actually received, for a test to assert against after making a call through a @RestClient interface.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    One part of a decoded multipart/form-data request body, as returned by getParts().
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the raw request body, decoded as UTF-8 - for a binary body (a @Multipart request in particular, whose parts may not be text at all), decoding as a single UTF-8 string is lossy; use getRawBody() or getParts() instead.
    Decodes an application/x-www-form-urlencoded body into its field name/value pairs, for asserting on what a @FormUrlEncoded method actually sent - a repeated key (from a @FieldMap entry, or a Collection-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.
    Decodes a multipart/form-data body into its individual parts, for asserting on what a @Multipart method actually sent - each @Part/@PartMap entry becomes one RecordedRequest.Part, with its name, optional file name, optional content type, and content.
    Returns the request path, without the query string.
    Returns the first value of a query param, since most are only ever sent once.
    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 - unlike getBody(), safe for a binary body.
    Returns when this request was fully received - the way to verify timing-sensitive behavior like @Retry's delayMillis/ backoffMultiplier actually growing the wait between attempts, rather than only counting how many attempts were made.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getHttpMethod

      public HTTPMethod getHttpMethod()
      Returns the HTTP method of the request.
      Returns:
      the HTTP method
    • getPath

      public String getPath()
      Returns the request path, without the query string.
      Returns:
      the path
    • getReceivedAt

      public Instant getReceivedAt()
      Returns when this request was fully received - the way to verify timing-sensitive behavior like @Retry's delayMillis/ backoffMultiplier actually growing the wait between attempts, rather than only counting how many attempts were made.
      Returns:
      when this request was received
    • getQueryParams

      public List<String> 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).
      Parameters:
      name - the query param name
      Returns:
      the query param's values, or an empty list if it wasn't sent
    • getQueryParam

      public String getQueryParam(String name)
      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 null if it wasn't sent
    • getHeaders

      public Map<String,List<String>> getHeaders()
      Returns the request headers, keyed by name (case-insensitively).
      Returns:
      the headers
    • getHeader

      public String getHeader(String name)
      Returns the first value of a request header, matched case-insensitively.
      Parameters:
      name - the header name
      Returns:
      the header's first value, or null if it wasn't sent
    • getBody

      public String getBody()
      Returns the raw request body, decoded as UTF-8 - for a binary body (a @Multipart request in particular, whose parts may not be text at all), decoding as a single UTF-8 string is lossy; use getRawBody() or getParts() 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 - unlike getBody(), safe for a binary body.
      Returns:
      the raw request body bytes, or an empty array if none was sent
    • getParts

      public List<RecordedRequest.Part> getParts()
      Decodes a multipart/form-data body into its individual parts, for asserting on what a @Multipart method actually sent - each @Part/@PartMap entry becomes one RecordedRequest.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's Content-Type isn't multipart/*, or has no boundary
    • getFormFields

      public Map<String,List<String>> getFormFields()
      Decodes an application/x-www-form-urlencoded body into its field name/value pairs, for asserting on what a @FormUrlEncoded method actually sent - a repeated key (from a @FieldMap entry, or a Collection-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's Content-Type isn't application/x-www-form-urlencoded