Class FakeHttpLayer
java.lang.Object
org.robolectric.shadows.httpclient.FakeHttpLayer
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic classstatic classstatic class
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddHttpResponse(org.apache.http.HttpResponse response) As a consumer of the fake http call, you should never call this method.voidaddHttpResponseContent(byte[] content) voidaddHttpResponseRule(String uri, String response) voidaddHttpResponseRule(String method, String uri, org.apache.http.HttpResponse response) voidaddHttpResponseRule(String uri, org.apache.http.HttpResponse response) voidaddHttpResponseRule(HttpEntityStub.ResponseRule responseRule) voidaddHttpResponseRule(RequestMatcher requestMatcher, List<? extends org.apache.http.HttpResponse> responses) Add a response rule.voidaddHttpResponseRule(RequestMatcher requestMatcher, org.apache.http.HttpResponse response) voidaddPendingHttpResponse(int statusCode, String responseBody, org.apache.http.Header... headers) voidaddPendingHttpResponse(org.apache.http.HttpResponse httpResponse) voidaddPendingHttpResponse(HttpResponseGenerator httpResponseGenerator) voidaddRequestInfo(HttpRequestInfo requestInfo) This method is not supposed to be consumed by tests.voidvoidCall this method if you want to ensure that there's no http responses logged from this point until the next response arrives.voidvoidorg.apache.http.HttpResponseemulateRequest(org.apache.http.HttpHost httpHost, org.apache.http.HttpRequest httpRequest, org.apache.http.protocol.HttpContext httpContext, org.apache.http.client.RequestDirector requestDirector) List<org.apache.http.HttpResponse> 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).List<byte[]> org.apache.http.HttpResponseHelper method that returns the latest received response from the server.getSentHttpRequestInfo(int index) booleanbooleanbooleanbooleanvoidinterceptHttpRequests(boolean interceptHttpRequests) You can disable Robolectric's fake HTTP layer temporarily by calling this method.voidinterceptResponseContent(boolean interceptResponseContent) booleanbooleanvoidvoidsetDefaultHttpResponse(int statusCode, String responseBody) voidsetDefaultHttpResponse(org.apache.http.HttpResponse defaultHttpResponse) voidsilence()
- 
Constructor Details- 
FakeHttpLayerpublic FakeHttpLayer()
 
- 
- 
Method Details- 
getLastSentHttpRequestInfo
- 
addPendingHttpResponsepublic void addPendingHttpResponse(int statusCode, String responseBody, org.apache.http.Header... headers) 
- 
addPendingHttpResponsepublic void addPendingHttpResponse(org.apache.http.HttpResponse httpResponse) 
- 
addPendingHttpResponse
- 
addHttpResponseRule
- 
addHttpResponseRule
- 
addHttpResponseRule
- 
addHttpResponseRulepublic void addHttpResponseRule(RequestMatcher requestMatcher, org.apache.http.HttpResponse response) 
- 
addHttpResponseRulepublic 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
- 
setDefaultHttpResponsepublic void setDefaultHttpResponse(org.apache.http.HttpResponse defaultHttpResponse) 
- 
setDefaultHttpResponse
- 
emulateRequestpublic 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
 
- 
hasPendingResponsespublic boolean hasPendingResponses()
- 
hasRequestInfospublic boolean hasRequestInfos()
- 
clearRequestInfospublic void clearRequestInfos()
- 
addRequestInfoThis 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.
 
- 
hasResponseRulespublic boolean hasResponseRules()
- 
hasRequestMatchingRule
- 
getSentHttpRequestInfo
- 
getNextSentHttpRequestInfo
- 
logHttpRequestspublic void logHttpRequests()
- 
silencepublic void silence()
- 
getSentHttpRequestInfos
- 
clearHttpResponseRulespublic void clearHttpResponseRules()
- 
clearPendingHttpResponsespublic void clearPendingHttpResponses()
- 
getHttpResponsesThis 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.
 
- 
addHttpResponsepublic 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
 
- 
addHttpResponseContentpublic void addHttpResponseContent(byte[] content) 
- 
getHttpResposeContentList
- 
getLastHttpResponsepublic 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
 
- 
clearHttpResponsespublic 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.
- 
interceptHttpRequestspublic 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)
 
- 
isInterceptingHttpRequestspublic boolean isInterceptingHttpRequests()
- 
interceptResponseContentpublic void interceptResponseContent(boolean interceptResponseContent) 
- 
isInterceptingResponseContentpublic boolean isInterceptingResponseContent()
 
-