Class MockClientHttpRequest

java.lang.Object
org.springframework.mock.http.MockHttpOutputMessage
org.springframework.mock.http.client.MockClientHttpRequest
All Implemented Interfaces:
org.springframework.http.client.ClientHttpRequest, org.springframework.http.HttpMessage, org.springframework.http.HttpOutputMessage, org.springframework.http.HttpRequest

public class MockClientHttpRequest extends MockHttpOutputMessage implements org.springframework.http.client.ClientHttpRequest
Mock implementation of ClientHttpRequest.
Since:
3.2
Author:
Rossen Stoyanchev, Brian Clozel, Sam Brannen
  • Constructor Details

    • MockClientHttpRequest

      public MockClientHttpRequest()
      Create a MockClientHttpRequest with GET as the HTTP request method and "/" as the URI.
    • MockClientHttpRequest

      public MockClientHttpRequest(org.springframework.http.HttpMethod httpMethod, String uriTemplate, Object... vars)
      Create a MockClientHttpRequest with the given HttpMethod, URI template, and URI template variable values.
      Since:
      6.0.3
    • MockClientHttpRequest

      public MockClientHttpRequest(org.springframework.http.HttpMethod httpMethod, URI uri)
      Create a MockClientHttpRequest with the given HttpMethod and URI.
  • Method Details

    • setMethod

      public void setMethod(org.springframework.http.HttpMethod httpMethod)
      Set the HTTP method of the request.
    • getMethod

      public org.springframework.http.HttpMethod getMethod()
      Specified by:
      getMethod in interface org.springframework.http.HttpRequest
    • setURI

      public void setURI(URI uri)
      Set the URI of the request.
    • getURI

      public URI getURI()
      Specified by:
      getURI in interface org.springframework.http.HttpRequest
    • setResponse

      public void setResponse(org.springframework.http.client.ClientHttpResponse clientHttpResponse)
      Set the ClientHttpResponse to be used as the result of executing the this request.
      See Also:
    • isExecuted

      public boolean isExecuted()
      Get the executed flag.
      See Also:
    • getAttributes

      public Map<String,Object> getAttributes()
      Specified by:
      getAttributes in interface org.springframework.http.HttpRequest
    • execute

      public final org.springframework.http.client.ClientHttpResponse execute() throws IOException
      Set the executed flag to true and return the configured response.
      Specified by:
      execute in interface org.springframework.http.client.ClientHttpRequest
      Throws:
      IOException
      See Also:
    • executeInternal

      protected org.springframework.http.client.ClientHttpResponse executeInternal() throws IOException
      The default implementation returns the configured response.

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

      Throws:
      IOException
    • toString

      public String toString()
      Overrides:
      toString in class Object