Class MockClientHttpResponse
- java.lang.Object
- org.springframework.mock.http.MockHttpInputMessage
- org.springframework.mock.http.client.MockClientHttpResponse
- All Implemented Interfaces:
Closeable,AutoCloseable,ClientHttpResponse,HttpInputMessage,HttpMessage
public class MockClientHttpResponse extends MockHttpInputMessage implements ClientHttpResponse
Mock implementation ofClientHttpResponse.- Since:
- 3.2
- Author:
- Rossen Stoyanchev
Constructor Summary
Constructors Constructor Description MockClientHttpResponse(byte[] body, HttpStatus statusCode)Constructor with response body as a byte array.MockClientHttpResponse(InputStream body, HttpStatus statusCode)Constructor with response body as InputStream.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close this response, freeing any resources created.intgetRawStatusCode()Get the HTTP status code (potentially non-standard and not resolvable through theHttpStatusenum) as an integer.HttpStatusgetStatusCode()Get the HTTP status code as anHttpStatusenum value.StringgetStatusText()Get the HTTP status text of the response.Methods inherited from class org.springframework.mock.http.MockHttpInputMessage
getBody, getHeaders
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.http.HttpInputMessage
getBody
Methods inherited from interface org.springframework.http.HttpMessage
getHeaders
Constructor Detail
MockClientHttpResponse
public MockClientHttpResponse(byte[] body, HttpStatus statusCode)
Constructor with response body as a byte array.
MockClientHttpResponse
public MockClientHttpResponse(InputStream body, HttpStatus statusCode)
Constructor with response body as InputStream.
Method Detail
getStatusCode
public HttpStatus getStatusCode() throws IOException
Description copied from interface:ClientHttpResponseGet the HTTP status code as anHttpStatusenum value.For status codes not supported by
HttpStatus, useClientHttpResponse.getRawStatusCode()instead.- Specified by:
getStatusCodein interfaceClientHttpResponse- Returns:
- the HTTP status as an HttpStatus enum value (never
null) - Throws:
IOException- in case of I/O errors- See Also:
HttpStatus.valueOf(int)
getRawStatusCode
public int getRawStatusCode() throws IOException
Description copied from interface:ClientHttpResponseGet the HTTP status code (potentially non-standard and not resolvable through theHttpStatusenum) as an integer.- Specified by:
getRawStatusCodein interfaceClientHttpResponse- Returns:
- the HTTP status as an integer value
- Throws:
IOException- in case of I/O errors- See Also:
ClientHttpResponse.getStatusCode(),HttpStatus.resolve(int)
getStatusText
public String getStatusText() throws IOException
Description copied from interface:ClientHttpResponseGet the HTTP status text of the response.- Specified by:
getStatusTextin interfaceClientHttpResponse- Returns:
- the HTTP status text
- Throws:
IOException- in case of I/O errors
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