Class AbstractRequestMatching<T extends RequestMatching<T>>
- java.lang.Object
-
- net.jadler.AbstractRequestMatching<T>
-
- Type Parameters:
T- type (either class or interface) of the class extending this abstract class. This type will be returned by all methods introduced inRequestMatchingimplemented by this class so fluid request matching is possible.
- All Implemented Interfaces:
RequestMatching<T>
public abstract class AbstractRequestMatching<T extends RequestMatching<T>> extends Object implements RequestMatching<T>
A base implementation of theRequestMatchinginterface. Collects all request predicates to a protected collection available in extending classes.
-
-
Field Summary
Fields Modifier and Type Field Description protected List<org.hamcrest.Matcher<? super Request>>predicates
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractRequestMatching()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ThavingBody(org.hamcrest.Matcher<? super String> predicate)Adds a request body predicate.ThavingBodyEqualTo(String requestBody)Adds a request body predicate.ThavingHeader(String name)Adds a request header existence predicate.ThavingHeader(String name, org.hamcrest.Matcher<? super List<String>> predicate)Adds a request header predicate.ThavingHeaderEqualTo(String name, String value)Adds a request header predicate.ThavingHeaders(String... names)Adds a request headers existence predicate.ThavingMethod(org.hamcrest.Matcher<? super String> predicate)Adds a request method predicate.ThavingMethodEqualTo(String method)Adds a request method predicate.ThavingParameter(String name)Adds a request parameter existence predicate.ThavingParameter(String name, org.hamcrest.Matcher<? super List<String>> predicate)Adds a request parameter predicate.ThavingParameterEqualTo(String name, String value)Adds a request parameter predicate.ThavingParameters(String... names)Adds a request parameters existence predicate.ThavingPath(org.hamcrest.Matcher<? super String> predicate)Adds a request path predicate.ThavingPathEqualTo(String path)Adds a request path predicate.ThavingQueryString(org.hamcrest.Matcher<? super String> predicate)Adds a query string predicate.ThavingQueryStringEqualTo(String queryString)Adds a query string predicate.ThavingRawBodyEqualTo(byte[] requestBody)Adds a request body predicate.Tthat(org.hamcrest.Matcher<? super Request> predicate)Adds a request predicate to this request matching.
-
-
-
Method Detail
-
that
public T that(org.hamcrest.Matcher<? super Request> predicate)
Adds a request predicate to this request matching.- Specified by:
thatin interfaceRequestMatching<T extends RequestMatching<T>>- Parameters:
predicate- request predicate to be added to this request matching (cannot benull)- Returns:
- this ongoing request matching
-
havingMethodEqualTo
public T havingMethodEqualTo(String method)
Adds a request method predicate. The request method must be equal (case insensitive) to the given value.- Specified by:
havingMethodEqualToin interfaceRequestMatching<T extends RequestMatching<T>>- Parameters:
method- expected http method of the incoming http request- Returns:
- this ongoing request matching
-
havingMethod
public T havingMethod(org.hamcrest.Matcher<? super String> predicate)
Adds a request method predicate.- Specified by:
havingMethodin interfaceRequestMatching<T extends RequestMatching<T>>- Parameters:
predicate- request method predicate (cannot benull)- Returns:
- this ongoing request matching
-
havingBodyEqualTo
public T havingBodyEqualTo(String requestBody)
Adds a request body predicate. The request body must be equal to the given value. An empty request body is represented by an empty string (not anullvalue) and therefore it can be matched by following invocation:havingBodyEqualTo("").- Specified by:
havingBodyEqualToin interfaceRequestMatching<T extends RequestMatching<T>>- Parameters:
requestBody- expected body of the incoming http request- Returns:
- this ongoing request matching
-
havingBody
public T havingBody(org.hamcrest.Matcher<? super String> predicate)
Adds a request body predicate. An empty request body is represented by an empty string (not anullvalue) and therefore it can be matched for example byhavingBody(equalTo("")).- Specified by:
havingBodyin interfaceRequestMatching<T extends RequestMatching<T>>- Parameters:
predicate- request body predicate (cannot benull)- Returns:
- this ongoing request matching
-
havingRawBodyEqualTo
public T havingRawBodyEqualTo(byte[] requestBody)
Adds a request body predicate. The request body must be equal to the given value. An empty request body is represented as an empty array (not anullvalue) and therefore it can be matched byhavingRawBodyEqualTo(new byte[0]).- Specified by:
havingRawBodyEqualToin interfaceRequestMatching<T extends RequestMatching<T>>- Parameters:
requestBody- expected body of the incoming http request- Returns:
- this ongoing request matching
-
havingPathEqualTo
public T havingPathEqualTo(String path)
Adds a request path predicate. The request path must be equal to the given value. A root path can be matched byhavingPathEqualTo("/"). Please note the path value doesn't contain a query string portion and is percent-encoded.- Specified by:
havingPathEqualToin interfaceRequestMatching<T extends RequestMatching<T>>- Parameters:
path- expected path of the incoming http request- Returns:
- this ongoing request matching
-
havingPath
public T havingPath(org.hamcrest.Matcher<? super String> predicate)
Adds a request path predicate. A root path can be matched byhavingPath(equalTo("/"))for example. Please note the path value doesn't contain a query string portion and is percent-encoded.- Specified by:
havingPathin interfaceRequestMatching<T extends RequestMatching<T>>- Parameters:
predicate- request path predicate (cannot benull)- Returns:
- this ongoing request matching
-
havingQueryStringEqualTo
public T havingQueryStringEqualTo(String queryString)
Adds a query string predicate. The query string must be equal to the given value. Examples:-
havingQueryStringEqualTo(null)matches a request without a query string (no ? character in URI,http://localhost/a/b). -
havingQueryStringEqualTo("")matches a request with an empty query string (http://localhost/?) -
havingQueryStringEqualTo("a=b")matches a request with the exact query string (http://localhost/?a=b)
- Specified by:
havingQueryStringEqualToin interfaceRequestMatching<T extends RequestMatching<T>>- Parameters:
queryString- expected query string of the incoming http request- Returns:
- this ongoing request matching
-
-
havingQueryString
public T havingQueryString(org.hamcrest.Matcher<? super String> predicate)
Adds a query string predicate. Examples:-
havingQueryString(nullValue())matches a request without a query string (no ? character in URI,http://localhost/a/b). -
havingQueryString(isEmptyString())matches a request with an empty query string (http://localhost/?) -
havingQueryString(equalTo("a=b"))matches a request with the exact query string (http://localhost/?a=b)
Please note the query string is percent-encoded.
- Specified by:
havingQueryStringin interfaceRequestMatching<T extends RequestMatching<T>>- Parameters:
predicate- query string predicate (cannot benull)- Returns:
- this ongoing request matching
-
-
havingParameterEqualTo
public T havingParameterEqualTo(String name, String value)
Adds a request parameter predicate. The given http parameter must be present in the incoming request and at least one of its values must be equal to the given value. Both the name and the value are percent-encoded.
Parameters are key=value pairs contained in the query string or in the request body (the
content-typeheader must beapplication/x-www-form-urlencodedin this case)- Specified by:
havingParameterEqualToin interfaceRequestMatching<T extends RequestMatching<T>>- Parameters:
name- case sensitive parameter name (cannot be empty)value- expected parameter value (cannot benull)- Returns:
- this ongoing request matching
-
havingParameter
public T havingParameter(String name, org.hamcrest.Matcher<? super List<String>> predicate)
Adds a request parameter predicate. Parameters are key=value pairs contained in the query string or in the request body (the
content-typeheader must beapplication/x-www-form-urlencodedin this case)Since a request parameter can have more than one value, the predicate is on a list of values. Examples:
havingParameter("unknown-param", nullValue())matches a request without anunknown-paramhavingParameter("existing-param", not(empty()))matches a request which contains at least oneexisting-paramhavingParameter("existing-param", hasItem("value"))matches a request which contains at least oneexisting-paramwith the valuevalue
- Specified by:
havingParameterin interfaceRequestMatching<T extends RequestMatching<T>>- Parameters:
name- case sensitive parameter name (cannot be empty)predicate- parameter predicate (cannot be null)- Returns:
- this ongoing request matching
-
havingParameter
public T havingParameter(String name)
Adds a request parameter existence predicate. The given http parameter must be present in the request body.
Parameters are key=value pairs contained in the query string or in the request body (the
content-typeheader must beapplication/x-www-form-urlencodedin this case)- Specified by:
havingParameterin interfaceRequestMatching<T extends RequestMatching<T>>- Parameters:
name- case sensitive parameter name (cannot be empty)- Returns:
- this ongoing request matching
-
havingParameters
public T havingParameters(String... names)
Adds a request parameters existence predicate. All of the given http parameters must be present in the request body.
Parameters are key=value pairs contained in the query string or in the request body (the
content-typeheader must beapplication/x-www-form-urlencodedin this case)- Specified by:
havingParametersin interfaceRequestMatching<T extends RequestMatching<T>>- Parameters:
names- case sensitive parameter names- Returns:
- this ongoing request matching
-
havingHeaderEqualTo
public T havingHeaderEqualTo(String name, String value)
Adds a request header predicate. The given http header must be present in the request body and at least one of its values must be equal to the given value.- Specified by:
havingHeaderEqualToin interfaceRequestMatching<T extends RequestMatching<T>>- Parameters:
name- case insensitive header name (cannot be empty)value- expected header value (cannot benull)- Returns:
- this ongoing request matching
-
havingHeader
public T havingHeader(String name, org.hamcrest.Matcher<? super List<String>> predicate)
Adds a request header predicate. Since a request header can have more than one value, the predicate is on a list of values. Examples:havingHeader("unknown-header", nullValue())matches a request without anunknown-headerhavingHeader("existing-header", not(empty()))matches a request which contains at least oneexisting-headerhavingHeader("existing-header", hasItem("value"))matches a request which contains at least oneexisting-headerwith the valuevalue
- Specified by:
havingHeaderin interfaceRequestMatching<T extends RequestMatching<T>>- Parameters:
name- case insensitive header name (cannot be empty)predicate- header predicate (cannot benull)- Returns:
- this ongoing request matching
-
havingHeader
public T havingHeader(String name)
Adds a request header existence predicate. The given http header must be present in the request body- Specified by:
havingHeaderin interfaceRequestMatching<T extends RequestMatching<T>>- Parameters:
name- case insensitive header name (cannot be empty)- Returns:
- this ongoing request matching
-
havingHeaders
public T havingHeaders(String... names)
Adds a request headers existence predicate. All of the given http headers must be present in the request body.- Specified by:
havingHeadersin interfaceRequestMatching<T extends RequestMatching<T>>- Parameters:
names- case insensitive headers names- Returns:
- this ongoing request matching
-
-