@ThreadSafe public class StubPlan extends Object implements TestPlan
This test plan implements stub test object that
feeds the system under test with responses. The test plan chooses a response
based on the features of the request sent by the system under test. For
example, user can configure HTTP Spy to respond on all requests having body
<html>Hello<html> with the status code 200.
When looking for the matching response, the test plan follows the order of
request expectations specified in the constructor StubPlan(java.util.Collection<com.github.tashoyan.httpspy.RequestExpectation>, java.util.Collection<com.github.tashoyan.httpspy.HttpResponse>). In other
words, the first specified request expectation has the highest priority and
evaluated first.
If none request expectations matched for a request, then the test plan
replies with a special response with Internal server error status
code. Verification in this case will fail and failure explanation will list
all unmatched requests.
| Constructor and Description |
|---|
StubPlan(Collection<RequestExpectation> requestExpectations,
Collection<HttpResponse> responses)
Creates new test plan with request expectations and responses for them.
|
| Modifier and Type | Method and Description |
|---|---|
protected HttpResponse |
createUnmatchedRequestResponse(HttpRequest actualRequest)
Creates a special response when a request does not match all
expectations.
|
HttpResponse |
getResponse(HttpRequest actualRequest)
Gets a response for an actual request.
|
boolean |
isMultithreaded()
Checks if this test plan supports multiple service threads.
|
protected void |
recordUnmatchedRequest(HttpRequest actualRequest)
Records a request unmatched with all expectations.
|
void |
verify()
Verifies actual requests against request expectations.
|
public StubPlan(Collection<RequestExpectation> requestExpectations, Collection<HttpResponse> responses)
Each request expectation has a corresponding response at the same index
in the list. Method getResponse(com.github.tashoyan.httpspy.HttpRequest) will look for a matching
expectation (and a corresponding response) in the order specified by the
arguments.
requestExpectations - The ordered collection of request
expectations.responses - The ordered collection of responses on actual requests.NullPointerException - requestExpectations is null, responses is
null.IllegalArgumentException - requestExpectations is empty, responses
is empty, requestExpectations.size != responses.size.public HttpResponse getResponse(HttpRequest actualRequest)
TestPlangetResponse in interface TestPlanactualRequest - A request that has been received from the system
under test.protected void recordUnmatchedRequest(HttpRequest actualRequest)
This implementation simply stores the request for the verification.
actualRequest - Actual request.NullPointerException - actualRequest is null.protected HttpResponse createUnmatchedRequestResponse(HttpRequest actualRequest)
This implementation responds with Internal server error status
code.
actualRequest - Actual request.NullPointerException - actualRequest is null.public void verify()
TestPlanpublic boolean isMultithreaded()
TestPlanisMultithreaded in interface TestPlantrue if multiple service threads can work with this test
plan.Copyright © 2016. All rights reserved.