Class FakeHttpLayer

java.lang.Object
org.robolectric.shadows.httpclient.FakeHttpLayer

public class FakeHttpLayer
extends Object
  • Constructor Details

  • Method Details

    • getLastSentHttpRequestInfo

      public HttpRequestInfo getLastSentHttpRequestInfo()
    • addPendingHttpResponse

      public void addPendingHttpResponse​(int statusCode, String responseBody, org.apache.http.Header... headers)
    • addPendingHttpResponse

      public void addPendingHttpResponse​(org.apache.http.HttpResponse httpResponse)
    • addPendingHttpResponse

      public void addPendingHttpResponse​(HttpResponseGenerator httpResponseGenerator)
    • addHttpResponseRule

      public void addHttpResponseRule​(String method, String uri, org.apache.http.HttpResponse response)
    • addHttpResponseRule

      public void addHttpResponseRule​(String uri, org.apache.http.HttpResponse response)
    • addHttpResponseRule

      public void addHttpResponseRule​(String uri, String response)
    • addHttpResponseRule

      public void addHttpResponseRule​(RequestMatcher requestMatcher, org.apache.http.HttpResponse response)
    • addHttpResponseRule

      public void addHttpResponseRule​(RequestMatcher requestMatcher, List<? extends org.apache.http.HttpResponse> responses)
      Add a response rule.
      Parameters:
      requestMatcher - Request matcher
      responses - A list of responses that are returned to matching requests in order from first to last.
    • addHttpResponseRule

      public void addHttpResponseRule​(HttpEntityStub.ResponseRule responseRule)
    • setDefaultHttpResponse

      public void setDefaultHttpResponse​(org.apache.http.HttpResponse defaultHttpResponse)
    • setDefaultHttpResponse

      public void setDefaultHttpResponse​(int statusCode, String responseBody)
    • emulateRequest

      public org.apache.http.HttpResponse emulateRequest​(org.apache.http.HttpHost httpHost, org.apache.http.HttpRequest httpRequest, org.apache.http.protocol.HttpContext httpContext, org.apache.http.client.RequestDirector requestDirector) throws org.apache.http.HttpException, IOException
      Throws:
      org.apache.http.HttpException
      IOException
    • hasPendingResponses

      public boolean hasPendingResponses()
    • hasRequestInfos

      public boolean hasRequestInfos()
    • clearRequestInfos

      public void clearRequestInfos()
    • addRequestInfo

      public void addRequestInfo​(HttpRequestInfo requestInfo)
      This method is not supposed to be consumed by tests. This exists solely for the purpose of logging real HTTP requests, so that functional/integration tests can verify if those were made, without messing with the fake http layer to actually perform the http call, instead of returning a mocked response. If you are just using mocked http calls, you should not even notice this method here.
      Parameters:
      requestInfo - Request info object to add.
    • hasResponseRules

      public boolean hasResponseRules()
    • hasRequestMatchingRule

      public boolean hasRequestMatchingRule​(RequestMatcher rule)
    • getSentHttpRequestInfo

      public HttpRequestInfo getSentHttpRequestInfo​(int index)
    • getNextSentHttpRequestInfo

      public HttpRequestInfo getNextSentHttpRequestInfo()
    • logHttpRequests

      public void logHttpRequests()
    • silence

      public void silence()
    • getSentHttpRequestInfos

      public List<HttpRequestInfo> getSentHttpRequestInfos()
    • clearHttpResponseRules

      public void clearHttpResponseRules()
    • clearPendingHttpResponses

      public void clearPendingHttpResponses()
    • getHttpResponses

      public List<org.apache.http.HttpResponse> getHttpResponses()
      This method return a list containing all the HTTP responses logged by the fake http layer, be it mocked http responses, be it real http calls (if {code}interceptHttpRequests{/code} is set to false). It doesn't make much sense to call this method if said property is set to true, as you yourself are providing the response, but it's here nonetheless.
      Returns:
      List of all HTTP Responses logged by the fake http layer.
    • addHttpResponse

      public void addHttpResponse​(org.apache.http.HttpResponse response)
      As a consumer of the fake http call, you should never call this method. This should be used solely by components that exercises http calls.
      Parameters:
      response - The final response received by the server
    • addHttpResponseContent

      public void addHttpResponseContent​(byte[] content)
    • getHttpResposeContentList

      public List<byte[]> getHttpResposeContentList()
    • getLastHttpResponse

      public org.apache.http.HttpResponse getLastHttpResponse()
      Helper method that returns the latest received response from the server.
      Returns:
      The latest HTTP response or null, if no responses are available
    • clearHttpResponses

      public void clearHttpResponses()
      Call this method if you want to ensure that there's no http responses logged from this point until the next response arrives. Helpful to ensure that the state is "clear" before actions are executed.
    • interceptHttpRequests

      public void interceptHttpRequests​(boolean interceptHttpRequests)
      You can disable Robolectric's fake HTTP layer temporarily by calling this method.
      Parameters:
      interceptHttpRequests - whether all HTTP requests should be intercepted (true by default)
    • isInterceptingHttpRequests

      public boolean isInterceptingHttpRequests()
    • interceptResponseContent

      public void interceptResponseContent​(boolean interceptResponseContent)
    • isInterceptingResponseContent

      public boolean isInterceptingResponseContent()