Class FakeHttp
java.lang.Object
org.robolectric.shadows.httpclient.FakeHttp
public class FakeHttp extends Object
Collection of static methods used interact with HTTP requests / responses.
-
Constructor Summary
Constructors Constructor Description FakeHttp()
-
Method Summary
Modifier and Type Method Description static void
addHttpResponseRule(String uri, String response)
Adds an HTTP response rule.static void
addHttpResponseRule(String method, String uri, org.apache.http.HttpResponse response)
Adds an HTTP response rule.static void
addHttpResponseRule(String uri, org.apache.http.HttpResponse response)
Adds an HTTP response rule with a default method of GET.static void
addHttpResponseRule(RequestMatcher requestMatcher, List<? extends org.apache.http.HttpResponse> responses)
Adds an HTTP response rule.static void
addHttpResponseRule(RequestMatcher requestMatcher, org.apache.http.HttpResponse response)
Adds an HTTP response rule.static void
addPendingHttpResponse(int statusCode, String responseBody, org.apache.http.Header... headers)
Sets up an HTTP response to be returned by calls to Apache'sHttpClient
implementers.static void
addPendingHttpResponse(org.apache.http.HttpResponse httpResponse)
Sets up an HTTP response to be returned by calls to Apache'sHttpClient
implementers.static void
addPendingHttpResponse(HttpResponseGenerator httpResponseGenerator)
Sets up an HTTP response to be returned by calls to Apache'sHttpClient
implementers.static void
addPendingHttpResponseWithContentType(int statusCode, String responseBody, org.apache.http.Header contentType)
Deprecated.static void
clearHttpResponseRules()
static void
clearPendingHttpResponses()
static FakeHttpLayer
getFakeHttpLayer()
static org.apache.http.HttpRequest
getLatestSentHttpRequest()
static org.apache.http.HttpRequest
getNextSentHttpRequest()
Accessor to obtain HTTP requests made during the current test in the order in which they were made.static HttpRequestInfo
getNextSentHttpRequestInfo()
Accessor to obtain metadata for an HTTP request made during the current test in the order in which they were made.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.static HttpRequestInfo
getSentHttpRequestInfo(int index)
Accessor to obtain metadata for an HTTP request made during the current test in the order in which they were made.static boolean
httpRequestWasMade()
Accessor to find out if HTTP requests were made during the current test.static boolean
httpRequestWasMade(String uri)
static void
reset()
static void
setDefaultHttpResponse(int statusCode, String responseBody)
static void
setDefaultHttpResponse(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'sHttpClient
implementers.- Parameters:
statusCode
- the status code of the responseresponseBody
- the body of the responseheaders
- optional headers for the request
-
addPendingHttpResponseWithContentType
@Deprecated public static void addPendingHttpResponseWithContentType(int statusCode, String responseBody, org.apache.http.Header contentType)Deprecated.Sets up an HTTP response to be returned by calls to Apache'sHttpClient
implementers.- 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'sHttpClient
implementers.- Parameters:
httpResponse
- the response
-
addPendingHttpResponse
Sets up an HTTP response to be returned by calls to Apache'sHttpClient
implementers.- 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()
-