Class MockClientHttpRequest
- java.lang.Object
- org.springframework.mock.http.MockHttpOutputMessage
- org.springframework.mock.http.client.MockClientHttpRequest
- All Implemented Interfaces:
ClientHttpRequest
,HttpMessage
,HttpOutputMessage
,HttpRequest
- Direct Known Subclasses:
MockAsyncClientHttpRequest
public class MockClientHttpRequest extends MockHttpOutputMessage implements ClientHttpRequest
Mock implementation ofClientHttpRequest
.- Since:
- 3.2
- Author:
- Rossen Stoyanchev, Sam Brannen
Constructor Summary
Constructors Constructor Description MockClientHttpRequest()
Default constructor.MockClientHttpRequest(HttpMethod httpMethod, URI uri)
Create an instance with the given HttpMethod and URI.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ClientHttpResponse
execute()
protected ClientHttpResponse
executeInternal()
The default implementation returns the configuredresponse
.HttpMethod
getMethod()
Return the HTTP method of the request.URI
getURI()
Return the URI of the request (including a query string if any, but only if it is well-formed for a URI representation).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.HttpMessage
getHeaders
Methods inherited from interface org.springframework.http.HttpOutputMessage
getBody
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
setMethod
public void setMethod(HttpMethod httpMethod)
getMethod
public HttpMethod getMethod()
Description copied from interface:HttpRequest
Return the HTTP method of the request.- Specified by:
getMethod
in interfaceHttpRequest
- Returns:
- the HTTP method as an HttpMethod enum value, or
null
if not resolvable (e.g. in case of a non-standard HTTP method)
getURI
public URI getURI()
Description copied from interface:HttpRequest
Return the URI of the request (including a query string if any, but only if it is well-formed for a URI representation).- Specified by:
getURI
in interfaceHttpRequest
- Returns:
- the URI of the request (never
null
)
setResponse
public void setResponse(ClientHttpResponse clientHttpResponse)
isExecuted
public boolean isExecuted()
execute
public final ClientHttpResponse execute() throws IOException
- Specified by:
execute
in interfaceClientHttpRequest
- 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 configuredresponse
.Override this method to execute the request and provide a response, potentially different than the configured response.
- Throws:
IOException