MockClientHttpRequest (Spring Framework 3.2.1.RELEASE API)
Date: 2013-01-24

org.springframework.mock.http.client

## Class MockClientHttpRequest

- java.lang.Object
- - org.springframework.mock.http.MockHttpOutputMessage
  - - org.springframework.mock.http.client.MockClientHttpRequest

- All Implemented Interfaces:
    ClientHttpRequest, HttpMessage, HttpOutputMessage, HttpRequest

      public class MockClientHttpRequest
      extends MockHttpOutputMessage
      implements ClientHttpRequest

  Mock implementation of `ClientHttpRequest`.
  Since:
    3.2
  Author:
    Rossen Stoyanchev, Sam Brannen

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `MockClientHttpRequest()` Default constructor.
    `MockClientHttpRequest(HttpMethod httpMethod, URI uri)` Create an instance with the given HttpMethod and URI.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `ClientHttpResponse` | `execute()` Set the `executed` flag to `true` and return the configured `response`.
    `protected ClientHttpResponse` | `executeInternal()` The default implementation returns the configured `response`.
    `HttpMethod` | `getMethod()` Return the HTTP method of the request.
    `URI` | `getURI()` Return the URI of the request.
    `boolean` | `isExecuted()`
    `void` | `setMethod(HttpMethod httpMethod)`
    `void` | `setResponse(ClientHttpResponse clientHttpResponse)`
    `void` | `setURI(URI uri)`
    `String` | `toString()`

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

      `getBody, getBodyAsBytes, getBodyAsString, getBodyAsString, getHeaders`

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

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

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

      `getBody`

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

      `getHeaders`

- - ### Constructor Detail

    - #### MockClientHttpRequest

          public MockClientHttpRequest()

      Default constructor.

    - #### MockClientHttpRequest

          public MockClientHttpRequest(HttpMethod httpMethod,
                               URI uri)

      Create an instance with the given HttpMethod and URI.

  - ### Method Detail

    - #### getURI

          public URI getURI()

      Description copied from interface: `HttpRequest`
      Return the URI of the request.
      Specified by:
        `getURI` in interface `HttpRequest`
      Returns:
        the URI of the request

    - #### setURI

          public void setURI(URI uri)

    - #### getMethod

          public HttpMethod getMethod()

      Description copied from interface: `HttpRequest`
      Return the HTTP method of the request.
      Specified by:
        `getMethod` in interface `HttpRequest`
      Returns:
        the HTTP method as an HttpMethod enum value

    - #### setMethod

          public void setMethod(HttpMethod httpMethod)

    - #### setResponse

          public void setResponse(ClientHttpResponse clientHttpResponse)

    - #### isExecuted

          public boolean isExecuted()

    - #### execute

          public final ClientHttpResponse execute()
                                           throws IOException

      Set the `executed` flag to `true` and return the configured `response`.
      Specified by:
        `execute` in interface `ClientHttpRequest`
      Returns:
        the response result of the execution
      Throws:
        `IOException` - in case of I/O errors
      See Also:
        `executeInternal()`

    - #### executeInternal

          protected ClientHttpResponse executeInternal()
                                                throws IOException

      The default implementation returns the configured `response`.

      Override this method to execute the request and provide a response, potentially different than the configured response.

      Throws:
        `IOException`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`