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 Summary

    Constructors
    Constructor
    Description
    Create a MockClientHttpRequest with GET as the HTTP request method and "/" as the URI.
    MockClientHttpRequest(org.springframework.http.HttpMethod httpMethod, String uriTemplate, Object... vars)
    Create a MockClientHttpRequest with the given HttpMethod, URI template, and URI template variable values.
    MockClientHttpRequest(org.springframework.http.HttpMethod httpMethod, URI uri)
    Create a MockClientHttpRequest with the given HttpMethod and URI.
  • Method Summary

    Modifier and Type
    Method
    Description
    final org.springframework.http.client.ClientHttpResponse
    Set the executed flag to true and return the configured response.
    protected org.springframework.http.client.ClientHttpResponse
    The default implementation returns the configured response.
    org.springframework.http.HttpMethod
     
     
    boolean
    Get the executed flag.
    void
    setMethod(org.springframework.http.HttpMethod httpMethod)
    Set the HTTP method of the request.
    void
    setResponse(org.springframework.http.client.ClientHttpResponse clientHttpResponse)
    Set the ClientHttpResponse to be used as the result of executing the this request.
    void
    setURI(URI uri)
    Set the URI of the request.
     

    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.HttpMessage

    getHeaders

    Methods inherited from interface org.springframework.http.HttpOutputMessage

    getBody
  • 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:
    • 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