Package kong.unirest.core
Class MockRawResponse
- java.lang.Object
-
- kong.unirest.core.MockRawResponse
-
- All Implemented Interfaces:
RawResponse
public class MockRawResponse extends java.lang.Object implements RawResponse
-
-
Field Summary
Fields Modifier and Type Field Description private Configconfigprivate java.lang.Stringresponseprivate HeadersresponseHeadersprivate intstatusprivate java.lang.StringstatusMessageprivate HttpRequestSummarysummary
-
Constructor Summary
Constructors Constructor Description MockRawResponse(java.lang.String responseBody, Headers responseHeaders, int status, java.lang.String statusMessage, Config config, HttpRequestSummary summary)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ConfiggetConfig()Returns the current config for this request/responsejava.io.InputStreamgetContent()Returns the body content of the response as a InputStream.byte[]getContentAsBytes()Returns the body as bytes.java.lang.StringgetContentAsString()Returns the body as UTF-8 String.java.lang.StringgetContentAsString(java.lang.String charset)Returns the body as UTF-8 String.java.io.InputStreamReadergetContentReader()Returns the body content of the response as a InputStreamReader.java.lang.StringgetContentType()Returns the mime type of the response content as indicated by the Content-Type header or a empty string if none is supplied (e.g.java.lang.StringgetEncoding()Returns the encoding of the response as indicated by the Content-Encoding header or returns a empty string if none provided.HeadersgetHeaders()Returns the received response headers.HttpRequestSummarygetRequestSummary()returns a lightweight read only summary of the request.intgetStatus()Returns the status code for this response.java.lang.StringgetStatusText()Returns the status text for this response.booleanhasContent()Indicates that the response has contentHttpResponseSummarytoSummary()returns a lightweight read only summary of the response.private java.nio.charset.CharsettryGetCharset(java.lang.String charset)
-
-
-
Field Detail
-
response
private final java.lang.String response
-
responseHeaders
private final Headers responseHeaders
-
status
private final int status
-
statusMessage
private final java.lang.String statusMessage
-
config
private final Config config
-
summary
private final HttpRequestSummary summary
-
-
Constructor Detail
-
MockRawResponse
public MockRawResponse(java.lang.String responseBody, Headers responseHeaders, int status, java.lang.String statusMessage, Config config, HttpRequestSummary summary)
-
-
Method Detail
-
getStatus
public int getStatus()
Description copied from interface:RawResponseReturns the status code for this response.- Specified by:
getStatusin interfaceRawResponse- Returns:
- the response code
-
getStatusText
public java.lang.String getStatusText()
Description copied from interface:RawResponseReturns the status text for this response.- Specified by:
getStatusTextin interfaceRawResponse- Returns:
- the response text
-
getHeaders
public Headers getHeaders()
Description copied from interface:RawResponseReturns the received response headers.- Specified by:
getHeadersin interfaceRawResponse- Returns:
- the response headers
-
getContent
public java.io.InputStream getContent()
Description copied from interface:RawResponseReturns the body content of the response as a InputStream. Like most InputStreams it can only be read once. If you read the response though some other method like getContentAsBytes() or getBodyAsString() it will read this method and consume the InputStream- Specified by:
getContentin interfaceRawResponse- Returns:
- the content
-
getContentAsBytes
public byte[] getContentAsBytes()
Description copied from interface:RawResponseReturns the body as bytes. This consumes the entire InputStream. Warning: Calling this on very large responses will place all data in memory and could create OutOfMemory errors- Specified by:
getContentAsBytesin interfaceRawResponse- Returns:
- the content as bytes
-
getContentAsString
public java.lang.String getContentAsString()
Description copied from interface:RawResponseReturns the body as UTF-8 String. This consumes the entire InputStream. Warning: Calling this on very large responses will place all data in memory and could create OutOfMemory errors Using this method with a binary response will make you sad- Specified by:
getContentAsStringin interfaceRawResponse- Returns:
- the content as a UTF-8 String
-
getContentAsString
public java.lang.String getContentAsString(java.lang.String charset)
Description copied from interface:RawResponseReturns the body as UTF-8 String. This consumes the entire InputStream. Warning: Calling this on very large responses will place all data in memory and could create OutOfMemory errors Using this method with a binary response will make you sad- Specified by:
getContentAsStringin interfaceRawResponse- Parameters:
charset- the charset for the String- Returns:
- the content as a string in the provided charset.
-
tryGetCharset
private java.nio.charset.Charset tryGetCharset(java.lang.String charset)
-
getContentReader
public java.io.InputStreamReader getContentReader()
Description copied from interface:RawResponseReturns the body content of the response as a InputStreamReader. Like most InputStreams it can only be read once. If you read the response though some other method like getContentAsBytes() or getBodyAsString() it will read this method and consume the InputStream- Specified by:
getContentReaderin interfaceRawResponse- Returns:
- the content
-
hasContent
public boolean hasContent()
Description copied from interface:RawResponseIndicates that the response has content- Specified by:
hasContentin interfaceRawResponse- Returns:
- boolean indicating that the response has content.
-
getContentType
public java.lang.String getContentType()
Description copied from interface:RawResponseReturns the mime type of the response content as indicated by the Content-Type header or a empty string if none is supplied (e.g. application/json)- Specified by:
getContentTypein interfaceRawResponse- Returns:
- the Content-Type
-
getEncoding
public java.lang.String getEncoding()
Description copied from interface:RawResponseReturns the encoding of the response as indicated by the Content-Encoding header or returns a empty string if none provided.- Specified by:
getEncodingin interfaceRawResponse- Returns:
- the encoding
-
getConfig
public Config getConfig()
Description copied from interface:RawResponseReturns the current config for this request/response- Specified by:
getConfigin interfaceRawResponse- Returns:
- the config
-
toSummary
public HttpResponseSummary toSummary()
Description copied from interface:RawResponsereturns a lightweight read only summary of the response.- Specified by:
toSummaryin interfaceRawResponse- Returns:
- the response summary
-
getRequestSummary
public HttpRequestSummary getRequestSummary()
Description copied from interface:RawResponsereturns a lightweight read only summary of the request.- Specified by:
getRequestSummaryin interfaceRawResponse- Returns:
- the request summary
-
-