Class 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 a request, returns the statusCode, and has an empty response body.
      MockHttpResponse​(com.azure.android.core.http.HttpRequest request, int statusCode, byte[] bodyBytes)
      Creates an HTTP response associated with a request, returns the statusCode, and response body of bodyBytes.
      MockHttpResponse​(com.azure.android.core.http.HttpRequest request, int statusCode, com.azure.android.core.http.HttpHeaders headers)
      Creates an HTTP response associated with a request, returns the statusCode, 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 a request, returns the statusCode, contains the headers, and response body of bodyBytes.
      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 a request, returns the statusCode, contains the given headers, and response body that is JSON serialized from serializable.
      MockHttpResponse​(com.azure.android.core.http.HttpRequest request, int statusCode, java.lang.Object serializable)
      Creates an HTTP response associated with a request, returns the statusCode, and response body that is JSON serialized from serializable.
    • 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 header name and value 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()
      • Methods inherited from class com.azure.android.core.http.HttpResponse

        buffer, close, getRequest
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MockHttpResponse

        public MockHttpResponse​(com.azure.android.core.http.HttpRequest request,
                                int statusCode)
        Creates a HTTP response associated with a request, returns the statusCode, 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 a request, returns the statusCode, and response body of bodyBytes.
        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 a request, returns the statusCode, 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 a request, returns the statusCode, contains the headers, and response body of bodyBytes.
        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 a request, returns the statusCode, contains the given headers, and response body that is JSON serialized from serializable.
        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 a request, returns the statusCode, and response body that is JSON serialized from serializable.
        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 class com.azure.android.core.http.HttpResponse
      • getHeaderValue

        public java.lang.String getHeaderValue​(java.lang.String name)
        Specified by:
        getHeaderValue in class com.azure.android.core.http.HttpResponse
      • getHeaders

        public com.azure.android.core.http.HttpHeaders getHeaders()
        Specified by:
        getHeaders in class com.azure.android.core.http.HttpResponse
      • getBodyAsByteArray

        public byte[] getBodyAsByteArray()
        Specified by:
        getBodyAsByteArray in class com.azure.android.core.http.HttpResponse
      • getBody

        public java.io.InputStream getBody()
        Specified by:
        getBody in class com.azure.android.core.http.HttpResponse
      • getBodyAsString

        public java.lang.String getBodyAsString()
        Specified by:
        getBodyAsString in class com.azure.android.core.http.HttpResponse
      • getBodyAsString

        public java.lang.String getBodyAsString​(java.nio.charset.Charset charset)
        Specified by:
        getBodyAsString in class com.azure.android.core.http.HttpResponse
      • addHeader

        public MockHttpResponse addHeader​(java.lang.String name,
                                          java.lang.String value)
        Adds the header name and value to the existing set of HTTP headers.
        Parameters:
        name - The header to add
        value - The header value.
        Returns:
        The updated response object.