public class FakeHttpLayer extends Object
Modifier and Type | Class and Description |
---|---|
static class |
FakeHttpLayer.DefaultRequestMatcher |
static class |
FakeHttpLayer.RequestMatcherBuilder |
static class |
FakeHttpLayer.RequestMatcherResponseRule |
static class |
FakeHttpLayer.UriRegexMatcher |
static class |
FakeHttpLayer.UriRequestMatcher |
Constructor and Description |
---|
FakeHttpLayer() |
Modifier and Type | Method and Description |
---|---|
void |
addHttpResponse(org.apache.http.HttpResponse response)
As a consumer of the fake http call, you should never call this method.
|
void |
addHttpResponseContent(byte[] content) |
void |
addHttpResponseRule(HttpEntityStub.ResponseRule responseRule) |
void |
addHttpResponseRule(RequestMatcher requestMatcher,
org.apache.http.HttpResponse response) |
void |
addHttpResponseRule(RequestMatcher requestMatcher,
List<? extends org.apache.http.HttpResponse> responses)
Add a response rule.
|
void |
addHttpResponseRule(String uri,
org.apache.http.HttpResponse response) |
void |
addHttpResponseRule(String uri,
String response) |
void |
addHttpResponseRule(String method,
String uri,
org.apache.http.HttpResponse response) |
void |
addPendingHttpResponse(org.apache.http.HttpResponse httpResponse) |
void |
addPendingHttpResponse(HttpResponseGenerator httpResponseGenerator) |
void |
addPendingHttpResponse(int statusCode,
String responseBody,
org.apache.http.Header... headers) |
void |
addRequestInfo(HttpRequestInfo requestInfo)
This method is not supposed to be consumed by tests.
|
void |
clearHttpResponseRules() |
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.
|
void |
clearPendingHttpResponses() |
void |
clearRequestInfos() |
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) |
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).
|
List<byte[]> |
getHttpResposeContentList() |
org.apache.http.HttpResponse |
getLastHttpResponse()
Helper method that returns the latest received response from the server.
|
HttpRequestInfo |
getLastSentHttpRequestInfo() |
HttpRequestInfo |
getNextSentHttpRequestInfo() |
HttpRequestInfo |
getSentHttpRequestInfo(int index) |
List<HttpRequestInfo> |
getSentHttpRequestInfos() |
boolean |
hasPendingResponses() |
boolean |
hasRequestInfos() |
boolean |
hasRequestMatchingRule(RequestMatcher rule) |
boolean |
hasResponseRules() |
void |
interceptHttpRequests(boolean interceptHttpRequests)
You can disable Robolectric’s fake HTTP layer temporarily by calling this method.
|
void |
interceptResponseContent(boolean interceptResponseContent) |
boolean |
isInterceptingHttpRequests() |
boolean |
isInterceptingResponseContent() |
void |
logHttpRequests() |
void |
setDefaultHttpResponse(org.apache.http.HttpResponse defaultHttpResponse) |
void |
setDefaultHttpResponse(int statusCode,
String responseBody) |
void |
silence() |
public HttpRequestInfo getLastSentHttpRequestInfo()
public void addPendingHttpResponse(int statusCode, String responseBody, org.apache.http.Header... headers)
public void addPendingHttpResponse(org.apache.http.HttpResponse httpResponse)
public void addPendingHttpResponse(HttpResponseGenerator httpResponseGenerator)
public void addHttpResponseRule(String method, String uri, org.apache.http.HttpResponse response)
public void addHttpResponseRule(String uri, org.apache.http.HttpResponse response)
public void addHttpResponseRule(RequestMatcher requestMatcher, org.apache.http.HttpResponse response)
public void addHttpResponseRule(RequestMatcher requestMatcher, List<? extends org.apache.http.HttpResponse> responses)
Add a response rule.
requestMatcher
- Request matcherresponses
- A list of responses that are returned to matching requests in order from first to last.public void addHttpResponseRule(HttpEntityStub.ResponseRule responseRule)
public void setDefaultHttpResponse(org.apache.http.HttpResponse defaultHttpResponse)
public void setDefaultHttpResponse(int statusCode, String responseBody)
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
org.apache.http.HttpException
IOException
public boolean hasPendingResponses()
public boolean hasRequestInfos()
public void clearRequestInfos()
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.
requestInfo
- Request info object to add.public boolean hasResponseRules()
public boolean hasRequestMatchingRule(RequestMatcher rule)
public HttpRequestInfo getSentHttpRequestInfo(int index)
public HttpRequestInfo getNextSentHttpRequestInfo()
public void logHttpRequests()
public void silence()
public List<HttpRequestInfo> getSentHttpRequestInfos()
public void clearHttpResponseRules()
public void clearPendingHttpResponses()
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.
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.
response
- The final response received by the serverpublic void addHttpResponseContent(byte[] content)
public List<byte[]> getHttpResposeContentList()
public org.apache.http.HttpResponse getLastHttpResponse()
Helper method that returns the latest received response from the server.
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.
public void interceptHttpRequests(boolean interceptHttpRequests)
You can disable Robolectric’s fake HTTP layer temporarily by calling this method.
interceptHttpRequests
- whether all HTTP requests should be intercepted (true by default)public boolean isInterceptingHttpRequests()
public void interceptResponseContent(boolean interceptResponseContent)
public boolean isInterceptingResponseContent()