Package net.jadler.stubbing
Class HttpStub
- java.lang.Object
-
- net.jadler.stubbing.HttpStub
-
public class HttpStub extends Object
An http stub is a WHEN-THEN pair (when an http request with specific properties arrives, then respond with a defined response).
The WHEN part is a list of predicates (in form of Hamcrest matchers) applicable to a request. All of these matchers must be evaluated to
truein order to apply the THEN part.The THEN part is defined by an instance of the
Responderinterface. This instance is capable of constructing stub http responses to be returned to the client.Instances of this class are thread-safe if and only if the provided
Responderinstance is thread-safe.One should never create new instances of this class directly,see
Jadlerfor explanation and tutorial.
-
-
Constructor Summary
Constructors Constructor Description HttpStub(Collection<org.hamcrest.Matcher<? super Request>> predicates, Responder responder)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringdescribeMismatch(Request request)Returns a reason why the given request doesn't match this rule.booleanmatches(Request request)StubResponsenextResponse(Request request)StringtoString()
-
-
-
Constructor Detail
-
HttpStub
public HttpStub(Collection<org.hamcrest.Matcher<? super Request>> predicates, Responder responder)
- Parameters:
predicates- list of predicates. Cannot benull, however can be empty (which means this rule will match every request)responder- an instance to provide stub http responses
-
-
Method Detail
-
matches
public boolean matches(Request request)
- Parameters:
request- an http request to be checked whether it matches this stub rule.- Returns:
trueif and only if all predicates defined in this rule were evaluated totrueby the given request.
-
nextResponse
public StubResponse nextResponse(Request request)
- Parameters:
request- an http request the stub response will be generated for- Returns:
- next http stub response as produced by the
Responderinstance provided inHttpStub(java.util.Collection, net.jadler.stubbing.Responder)
-
describeMismatch
public String describeMismatch(Request request)
Returns a reason why the given request doesn't match this rule. This method should be called if and only ifmatches(net.jadler.Request)would returnfalse. However, this is not checked.- Parameters:
request- an http request to describe the mismatch for- Returns:
- a human readable mismatch reason
-
-