Class MockClientHttpResponse
java.lang.Object
org.springframework.mock.http.MockHttpInputMessage
org.springframework.mock.http.client.MockClientHttpResponse
- All Implemented Interfaces:
Closeable, AutoCloseable, ClientHttpResponse, HttpInputMessage, HttpMessage
Mock implementation of
ClientHttpResponse.- Since:
- 3.2
- Author:
- Rossen Stoyanchev, Sam Brannen
-
Constructor Summary
ConstructorsConstructorDescriptionCreate aMockClientHttpResponsewith an empty response body and HTTP status codeOK.MockClientHttpResponse(byte[] body, int statusCode) Create aMockClientHttpResponsewith response body as a byte array and a custom HTTP status code.MockClientHttpResponse(byte[] body, HttpStatusCode statusCode) Create aMockClientHttpResponsewith response body as a byte array and the supplied HTTP status code.MockClientHttpResponse(InputStream body, int statusCode) Create aMockClientHttpResponsewith response body asInputStreamand a custom HTTP status code.MockClientHttpResponse(InputStream body, HttpStatusCode statusCode) Create aMockClientHttpResponsewith response body asInputStreamand the supplied HTTP status code. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close this response, freeing any resources created.Get the HTTP status code as anHttpStatusCode.Get the HTTP status text of the response.Methods inherited from class MockHttpInputMessage
getBody, getHeadersMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface HttpInputMessage
getBodyMethods inherited from interface HttpMessage
getHeaders
-
Constructor Details
-
MockClientHttpResponse
public MockClientHttpResponse()Create aMockClientHttpResponsewith an empty response body and HTTP status codeOK.- Since:
- 6.0.3
-
MockClientHttpResponse
Create aMockClientHttpResponsewith response body as a byte array and the supplied HTTP status code. -
MockClientHttpResponse
public MockClientHttpResponse(byte[] body, int statusCode) Create aMockClientHttpResponsewith response body as a byte array and a custom HTTP status code.- Since:
- 5.3.17
-
MockClientHttpResponse
Create aMockClientHttpResponsewith response body asInputStreamand the supplied HTTP status code. -
MockClientHttpResponse
Create aMockClientHttpResponsewith response body asInputStreamand a custom HTTP status code.- Since:
- 5.3.17
-
-
Method Details
-
getStatusCode
Description copied from interface:ClientHttpResponseGet the HTTP status code as anHttpStatusCode.- Specified by:
getStatusCodein interfaceClientHttpResponse- Returns:
- the HTTP status as
HttpStatusCodevalue (nevernull)
-
getStatusText
Description copied from interface:ClientHttpResponseGet the HTTP status text of the response.- Specified by:
getStatusTextin interfaceClientHttpResponse- Returns:
- the HTTP status text
-
close
public void close()Description copied from interface:ClientHttpResponseClose this response, freeing any resources created.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceClientHttpResponse- Specified by:
closein interfaceCloseable
-