public class FakeHttp extends Object
Collection of static methods used interact with HTTP requests / responses.
Constructor and Description |
---|
FakeHttp() |
Modifier and Type | Method and Description |
---|---|
static void |
addHttpResponseRule(RequestMatcher requestMatcher,
org.apache.http.HttpResponse response)
Adds an HTTP response rule.
|
static void |
addHttpResponseRule(RequestMatcher requestMatcher,
List<? extends org.apache.http.HttpResponse> responses)
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(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 |
addPendingHttpResponse(org.apache.http.HttpResponse httpResponse)
Sets up an HTTP response to be returned by calls to Apache’s
HttpClient implementers. |
static void |
addPendingHttpResponse(HttpResponseGenerator httpResponseGenerator)
Sets up an HTTP response to be returned by calls to Apache’s
HttpClient implementers. |
static void |
addPendingHttpResponse(int statusCode,
String responseBody,
org.apache.http.Header... headers)
Sets up an HTTP response to be returned by calls to Apache’s
HttpClient 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(org.apache.http.HttpResponse defaultHttpResponse) |
static void |
setDefaultHttpResponse(int statusCode,
String responseBody) |
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’s HttpClient
implementers.
statusCode
- the status code of the responseresponseBody
- the body of the responseheaders
- optional headers for the request@Deprecated public static void addPendingHttpResponseWithContentType(int statusCode, String responseBody, org.apache.http.Header contentType)
addPendingHttpResponse(int, String, org.apache.http.Header...)
insteadSets up an HTTP response to be returned by calls to Apache’s HttpClient
implementers.
statusCode
- the status code of the responseresponseBody
- the body of the responsecontentType
- the contentType of the responsepublic static void addPendingHttpResponse(org.apache.http.HttpResponse httpResponse)
Sets up an HTTP response to be returned by calls to Apache’s HttpClient
implementers.
httpResponse
- the responsepublic static void addPendingHttpResponse(HttpResponseGenerator httpResponseGenerator)
Sets up an HTTP response to be returned by calls to Apache’s HttpClient
implementers.
httpResponseGenerator
- an HttpResponseGenerator that will provide responsespublic 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.
index
- index of the request to retrieve.public static org.apache.http.HttpRequest getLatestSentHttpRequest()
public static boolean httpRequestWasMade()
Accessor to find out if HTTP requests were made during the current test.
public static boolean httpRequestWasMade(String uri)
public 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.
index
- index of the request to retrieve.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.
public static HttpRequestInfo getNextSentHttpRequestInfo()
Accessor to obtain metadata for an HTTP request made during the current test in the order in which they were made.
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.
method
- method to match.uri
- uri to match.response
- response to return when a match is found.public static void addHttpResponseRule(String uri, org.apache.http.HttpResponse response)
Adds an HTTP response rule with a default method of GET. The response will be returned when the rule is matched.
uri
- uri to match.response
- response to return when a match is found.public static void addHttpResponseRule(String uri, String response)
Adds an HTTP response rule. The response will be returned when the rule is matched.
uri
- uri to match.response
- response to return when a match is found.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.
requestMatcher
- custom RequestMatcher
.response
- response to return when a match is found.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.
requestMatcher
- custom RequestMatcher
.responses
- responses to return in order when a match is found.public static FakeHttpLayer getFakeHttpLayer()
public static void setDefaultHttpResponse(int statusCode, String responseBody)
public static void setDefaultHttpResponse(org.apache.http.HttpResponse defaultHttpResponse)
public static void clearHttpResponseRules()
public static void clearPendingHttpResponses()
public static void reset()