org.springframework.mock.http.client

## Class MockClientHttpResponse

- java.lang.Object
- - org.springframework.mock.http.MockHttpInputMessage
  - - org.springframework.mock.http.client.MockClientHttpResponse

- All Implemented Interfaces:
    Closeable, AutoCloseable, ClientHttpResponse, HttpInputMessage, HttpMessage

      public class MockClientHttpResponse
      extends MockHttpInputMessage
      implements ClientHttpResponse

  Mock implementation of `ClientHttpResponse`.
  Since:
    3.2
  Author:
    Rossen Stoyanchev

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `MockClientHttpResponse(byte[] body, HttpStatus statusCode)` Constructor with response body as a byte array.
    `MockClientHttpResponse(byte[] body, int statusCode)` Variant of `MockClientHttpResponse(byte[], HttpStatus)` with a custom HTTP status code.
    `MockClientHttpResponse(InputStream body, HttpStatus statusCode)` Constructor with response body as InputStream.
    `MockClientHttpResponse(InputStream body, int statusCode)` Variant of `MockClientHttpResponse(InputStream, HttpStatus)` with a custom HTTP status code.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Close this response, freeing any resources created.
    `int` | `getRawStatusCode()` Get the HTTP status code (potentially non-standard and not resolvable through the `HttpStatus` enum) as an integer.
    `HttpStatus` | `getStatusCode()` Get the HTTP status code as an `HttpStatus` enum value.
    `String` | `getStatusText()` Get the HTTP status text of the response.

    - ### Methods inherited from class org.springframework.mock.http.MockHttpInputMessage

      `getBody, getHeaders`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.springframework.http.HttpInputMessage

      `getBody`

    - ### Methods inherited from interface org.springframework.http.HttpMessage

      `getHeaders`

- - ### Constructor Detail

    - #### MockClientHttpResponse

          public MockClientHttpResponse(byte[] body,
                                        HttpStatus statusCode)

      Constructor with response body as a byte array.

    - #### MockClientHttpResponse

          public MockClientHttpResponse(byte[] body,
                                        int statusCode)

      Variant of `MockClientHttpResponse(byte[], HttpStatus)` with a custom HTTP status code.
      Since:
        5.3.17

    - #### MockClientHttpResponse

          public MockClientHttpResponse(InputStream body,
                                        HttpStatus statusCode)

      Constructor with response body as InputStream.

    - #### MockClientHttpResponse

          public MockClientHttpResponse(InputStream body,
                                        int statusCode)

      Variant of `MockClientHttpResponse(InputStream, HttpStatus)` with a custom HTTP status code.
      Since:
        5.3.17

  - ### Method Detail

    - #### getStatusCode

          public HttpStatus getStatusCode()

      Description copied from interface: `ClientHttpResponse`
      Get the HTTP status code as an `HttpStatus` enum value.

      For status codes not supported by `HttpStatus`, use `ClientHttpResponse.getRawStatusCode()` instead.

      Specified by:
        `getStatusCode` in interface `ClientHttpResponse`
      Returns:
        the HTTP status as an HttpStatus enum value (never `null`)
      See Also:
        `HttpStatus.valueOf(int)`

    - #### getRawStatusCode

          public int getRawStatusCode()

      Description copied from interface: `ClientHttpResponse`
      Get the HTTP status code (potentially non-standard and not resolvable through the `HttpStatus` enum) as an integer.
      Specified by:
        `getRawStatusCode` in interface `ClientHttpResponse`
      Returns:
        the HTTP status as an integer value
      See Also:
        `ClientHttpResponse.getStatusCode()`, `HttpStatus.resolve(int)`

    - #### getStatusText

          public String getStatusText()

      Description copied from interface: `ClientHttpResponse`
      Get the HTTP status text of the response.
      Specified by:
        `getStatusText` in interface `ClientHttpResponse`
      Returns:
        the HTTP status text

    - #### close

          public void close()

      Description copied from interface: `ClientHttpResponse`
      Close this response, freeing any resources created.
      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Specified by:
        `close` in interface `ClientHttpResponse`