Package com.azure.android.core.test.http
Class MockHttpResponse
- java.lang.Object
-
- com.azure.android.core.http.HttpResponse
-
- com.azure.android.core.test.http.MockHttpResponse
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class MockHttpResponse extends com.azure.android.core.http.HttpResponse
An HTTP response that is created to simulate a HTTP request.
-
-
Constructor Summary
Constructors Constructor Description MockHttpResponse(com.azure.android.core.http.HttpRequest request, int statusCode)
Creates a HTTP response associated with arequest
, returns thestatusCode
, and has an empty response body.MockHttpResponse(com.azure.android.core.http.HttpRequest request, int statusCode, byte[] bodyBytes)
Creates an HTTP response associated with arequest
, returns thestatusCode
, and response body ofbodyBytes
.MockHttpResponse(com.azure.android.core.http.HttpRequest request, int statusCode, com.azure.android.core.http.HttpHeaders headers)
Creates an HTTP response associated with arequest
, returns thestatusCode
, and http headers.MockHttpResponse(com.azure.android.core.http.HttpRequest request, int statusCode, com.azure.android.core.http.HttpHeaders headers, byte[] bodyBytes)
Creates an HTTP response associated with arequest
, returns thestatusCode
, contains theheaders
, and response body ofbodyBytes
.MockHttpResponse(com.azure.android.core.http.HttpRequest request, int statusCode, com.azure.android.core.http.HttpHeaders headers, java.lang.Object serializable)
Creates an HTTP response associated with arequest
, returns thestatusCode
, contains the givenheaders
, and response body that is JSON serialized fromserializable
.MockHttpResponse(com.azure.android.core.http.HttpRequest request, int statusCode, java.lang.Object serializable)
Creates an HTTP response associated with arequest
, returns thestatusCode
, and response body that is JSON serialized fromserializable
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MockHttpResponse
addHeader(java.lang.String name, java.lang.String value)
Adds the headername
andvalue
to the existing set of HTTP headers.java.io.InputStream
getBody()
byte[]
getBodyAsByteArray()
java.lang.String
getBodyAsString()
java.lang.String
getBodyAsString(java.nio.charset.Charset charset)
com.azure.android.core.http.HttpHeaders
getHeaders()
java.lang.String
getHeaderValue(java.lang.String name)
int
getStatusCode()
-
-
-
Constructor Detail
-
MockHttpResponse
public MockHttpResponse(com.azure.android.core.http.HttpRequest request, int statusCode)
Creates a HTTP response associated with arequest
, returns thestatusCode
, and has an empty response body.- Parameters:
request
- HttpRequest associated with the response.statusCode
- Status code of the response.
-
MockHttpResponse
public MockHttpResponse(com.azure.android.core.http.HttpRequest request, int statusCode, byte[] bodyBytes)
Creates an HTTP response associated with arequest
, returns thestatusCode
, and response body ofbodyBytes
.- Parameters:
request
- HttpRequest associated with the response.statusCode
- Status code of the response.bodyBytes
- Contents of the response.
-
MockHttpResponse
public MockHttpResponse(com.azure.android.core.http.HttpRequest request, int statusCode, com.azure.android.core.http.HttpHeaders headers)
Creates an HTTP response associated with arequest
, returns thestatusCode
, and http headers.- Parameters:
request
- HttpRequest associated with the response.statusCode
- Status code of the response.headers
- Headers of the response.
-
MockHttpResponse
public MockHttpResponse(com.azure.android.core.http.HttpRequest request, int statusCode, com.azure.android.core.http.HttpHeaders headers, byte[] bodyBytes)
Creates an HTTP response associated with arequest
, returns thestatusCode
, contains theheaders
, and response body ofbodyBytes
.- Parameters:
request
- HttpRequest associated with the response.statusCode
- Status code of the response.headers
- HttpHeaders of the response.bodyBytes
- Contents of the response.
-
MockHttpResponse
public MockHttpResponse(com.azure.android.core.http.HttpRequest request, int statusCode, com.azure.android.core.http.HttpHeaders headers, java.lang.Object serializable)
Creates an HTTP response associated with arequest
, returns thestatusCode
, contains the givenheaders
, and response body that is JSON serialized fromserializable
.- Parameters:
request
- HttpRequest associated with the response.headers
- HttpHeaders of the response.statusCode
- Status code of the response.serializable
- Contents to be serialized into JSON for the response.
-
MockHttpResponse
public MockHttpResponse(com.azure.android.core.http.HttpRequest request, int statusCode, java.lang.Object serializable)
Creates an HTTP response associated with arequest
, returns thestatusCode
, and response body that is JSON serialized fromserializable
.- Parameters:
request
- HttpRequest associated with the response.statusCode
- Status code of the response.serializable
- Contents to be serialized into JSON for the response.
-
-
Method Detail
-
getStatusCode
public int getStatusCode()
- Specified by:
getStatusCode
in classcom.azure.android.core.http.HttpResponse
-
getHeaderValue
public java.lang.String getHeaderValue(java.lang.String name)
- Specified by:
getHeaderValue
in classcom.azure.android.core.http.HttpResponse
-
getHeaders
public com.azure.android.core.http.HttpHeaders getHeaders()
- Specified by:
getHeaders
in classcom.azure.android.core.http.HttpResponse
-
getBodyAsByteArray
public byte[] getBodyAsByteArray()
- Specified by:
getBodyAsByteArray
in classcom.azure.android.core.http.HttpResponse
-
getBody
public java.io.InputStream getBody()
- Specified by:
getBody
in classcom.azure.android.core.http.HttpResponse
-
getBodyAsString
public java.lang.String getBodyAsString()
- Specified by:
getBodyAsString
in classcom.azure.android.core.http.HttpResponse
-
getBodyAsString
public java.lang.String getBodyAsString(java.nio.charset.Charset charset)
- Specified by:
getBodyAsString
in classcom.azure.android.core.http.HttpResponse
-
addHeader
public MockHttpResponse addHeader(java.lang.String name, java.lang.String value)
Adds the headername
andvalue
to the existing set of HTTP headers.- Parameters:
name
- The header to addvalue
- The header value.- Returns:
- The updated response object.
-
-