Class FakeHttp
java.lang.Object
org.robolectric.shadows.httpclient.FakeHttp
Collection of static methods used interact with HTTP requests / responses.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddHttpResponseRule(String uri, String response) Adds an HTTP response rule.static voidaddHttpResponseRule(String method, String uri, org.apache.http.HttpResponse response) Adds an HTTP response rule.static voidaddHttpResponseRule(String uri, org.apache.http.HttpResponse response) Adds an HTTP response rule with a default method of GET.static voidaddHttpResponseRule(RequestMatcher requestMatcher, List<? extends org.apache.http.HttpResponse> responses) Adds an HTTP response rule.static voidaddHttpResponseRule(RequestMatcher requestMatcher, org.apache.http.HttpResponse response) Adds an HTTP response rule.static voidaddPendingHttpResponse(int statusCode, String responseBody, org.apache.http.Header... headers) Sets up an HTTP response to be returned by calls to Apache'sHttpClientimplementers.static voidaddPendingHttpResponse(org.apache.http.HttpResponse httpResponse) Sets up an HTTP response to be returned by calls to Apache'sHttpClientimplementers.static voidaddPendingHttpResponse(HttpResponseGenerator httpResponseGenerator) Sets up an HTTP response to be returned by calls to Apache'sHttpClientimplementers.static final voidaddPendingHttpResponseWithContentType(int statusCode, String responseBody, org.apache.http.Header contentType) Deprecated.static voidstatic voidstatic FakeHttpLayerstatic org.apache.http.HttpRequeststatic org.apache.http.HttpRequestAccessor to obtain HTTP requests made during the current test in the order in which they were made.static HttpRequestInfoAccessor to obtain metadata for an HTTP request made during the current test in the order in which they were made.static org.apache.http.HttpRequestgetSentHttpRequest(int index) Accessor to obtain HTTP requests made during the current test in the order in which they were made.static HttpRequestInfogetSentHttpRequestInfo(int index) Accessor to obtain metadata for an HTTP request made during the current test in the order in which they were made.static booleanAccessor to find out if HTTP requests were made during the current test.static booleanhttpRequestWasMade(String uri) static voidreset()static voidsetDefaultHttpResponse(int statusCode, String responseBody) static voidsetDefaultHttpResponse(org.apache.http.HttpResponse defaultHttpResponse)
-
Constructor Details
-
FakeHttp
public FakeHttp()
-
-
Method Details
-
addPendingHttpResponse
public static void addPendingHttpResponse(int statusCode, String responseBody, org.apache.http.Header... headers) Sets up an HTTP response to be returned by calls to Apache'sHttpClientimplementers.- Parameters:
statusCode- the status code of the responseresponseBody- the body of the responseheaders- optional headers for the request
-
addPendingHttpResponseWithContentType
@Deprecated @InlineMe(replacement="FakeHttp.getFakeHttpLayer().addPendingHttpResponse(statusCode, responseBody, contentType)", imports="org.robolectric.shadows.httpclient.FakeHttp") public static final void addPendingHttpResponseWithContentType(int statusCode, String responseBody, org.apache.http.Header contentType) Deprecated.Sets up an HTTP response to be returned by calls to Apache'sHttpClientimplementers.- Parameters:
statusCode- the status code of the responseresponseBody- the body of the responsecontentType- the contentType of the response
-
addPendingHttpResponse
public static void addPendingHttpResponse(org.apache.http.HttpResponse httpResponse) Sets up an HTTP response to be returned by calls to Apache'sHttpClientimplementers.- Parameters:
httpResponse- the response
-
addPendingHttpResponse
Sets up an HTTP response to be returned by calls to Apache'sHttpClientimplementers.- Parameters:
httpResponseGenerator- an HttpResponseGenerator that will provide responses
-
getSentHttpRequest
public static org.apache.http.HttpRequest getSentHttpRequest(int index) Accessor to obtain HTTP requests made during the current test in the order in which they were made.- Parameters:
index- index of the request to retrieve.- Returns:
- the requested request.
-
getLatestSentHttpRequest
public static org.apache.http.HttpRequest getLatestSentHttpRequest() -
httpRequestWasMade
public static boolean httpRequestWasMade()Accessor to find out if HTTP requests were made during the current test.- Returns:
- whether a request was made.
-
httpRequestWasMade
-
getSentHttpRequestInfo
Accessor to obtain metadata for an HTTP request made during the current test in the order in which they were made.- Parameters:
index- index of the request to retrieve.- Returns:
- the requested request metadata.
-
getNextSentHttpRequest
public static org.apache.http.HttpRequest getNextSentHttpRequest()Accessor to obtain HTTP requests made during the current test in the order in which they were made.- Returns:
- the requested request or null if there are none.
-
getNextSentHttpRequestInfo
Accessor to obtain metadata for an HTTP request made during the current test in the order in which they were made.- Returns:
- the requested request metadata or null if there are none.
-
addHttpResponseRule
public static void addHttpResponseRule(String method, String uri, org.apache.http.HttpResponse response) Adds an HTTP response rule. The response will be returned when the rule is matched.- Parameters:
method- method to match.uri- uri to match.response- response to return when a match is found.
-
addHttpResponseRule
Adds an HTTP response rule with a default method of GET. The response will be returned when the rule is matched.- Parameters:
uri- uri to match.response- response to return when a match is found.
-
addHttpResponseRule
Adds an HTTP response rule. The response will be returned when the rule is matched.- Parameters:
uri- uri to match.response- response to return when a match is found.
-
addHttpResponseRule
public static void addHttpResponseRule(RequestMatcher requestMatcher, org.apache.http.HttpResponse response) Adds an HTTP response rule. The response will be returned when the rule is matched.- Parameters:
requestMatcher- customRequestMatcher.response- response to return when a match is found.
-
addHttpResponseRule
public static void addHttpResponseRule(RequestMatcher requestMatcher, List<? extends org.apache.http.HttpResponse> responses) Adds an HTTP response rule. For each time the rule is matched, responses will be shifted off the list and returned. When all responses have been given and the rule is matched again, an exception will be thrown.- Parameters:
requestMatcher- customRequestMatcher.responses- responses to return in order when a match is found.
-
getFakeHttpLayer
-
setDefaultHttpResponse
-
setDefaultHttpResponse
public static void setDefaultHttpResponse(org.apache.http.HttpResponse defaultHttpResponse) -
clearHttpResponseRules
public static void clearHttpResponseRules() -
clearPendingHttpResponses
public static void clearPendingHttpResponses() -
reset
public static void reset()
-
addPendingHttpResponse(int, String, org.apache.http.Header...)instead