T
- type (either class or interface) of the class extending this abstract class. This type will be returned
by all methods introduced in RequestMatching
implemented by this class so fluid request matching
is possible.public abstract class AbstractRequestMatching<T extends RequestMatching<T>> extends Object implements RequestMatching<T>
RequestMatching
interface. Collects all request predicates to a protected
collection available in extending classes.Modifier and Type | Field and Description |
---|---|
protected List<org.hamcrest.Matcher<? super Request>> |
predicates |
Modifier | Constructor and Description |
---|---|
protected |
AbstractRequestMatching() |
Modifier and Type | Method and Description |
---|---|
T |
havingBody(org.hamcrest.Matcher<? super String> predicate)
Adds a request body predicate.
|
T |
havingBodyEqualTo(String requestBody)
Adds a request body predicate.
|
T |
havingHeader(String name)
Adds a request header existence predicate.
|
T |
havingHeader(String name,
org.hamcrest.Matcher<? super List<String>> predicate)
Adds a request header predicate.
|
T |
havingHeaderEqualTo(String name,
String value)
Adds a request header predicate.
|
T |
havingHeaders(String... names)
Adds a request headers existence predicate.
|
T |
havingMethod(org.hamcrest.Matcher<? super String> predicate)
Adds a request method predicate.
|
T |
havingMethodEqualTo(String method)
Adds a request method predicate.
|
T |
havingParameter(String name)
Adds a request parameter existence predicate.
|
T |
havingParameter(String name,
org.hamcrest.Matcher<? super List<String>> predicate)
Adds a request parameter predicate.
|
T |
havingParameterEqualTo(String name,
String value)
Adds a request parameter predicate.
|
T |
havingParameters(String... names)
Adds a request parameters existence predicate.
|
T |
havingPath(org.hamcrest.Matcher<? super String> predicate)
Adds a request path predicate.
|
T |
havingPathEqualTo(String path)
Adds a request path predicate.
|
T |
havingQueryString(org.hamcrest.Matcher<? super String> predicate)
Adds a query string predicate.
|
T |
havingQueryStringEqualTo(String queryString)
Adds a query string predicate.
|
T |
havingRawBodyEqualTo(byte[] requestBody)
Adds a request body predicate.
|
T |
that(org.hamcrest.Matcher<? super Request> predicate)
Adds a request predicate to this request matching.
|
public T that(org.hamcrest.Matcher<? super Request> predicate)
that
in interface RequestMatching<T extends RequestMatching<T>>
predicate
- request predicate to be added to this request matching (cannot be null
)public T havingMethodEqualTo(String method)
havingMethodEqualTo
in interface RequestMatching<T extends RequestMatching<T>>
method
- expected http method of the incoming http requestpublic T havingMethod(org.hamcrest.Matcher<? super String> predicate)
havingMethod
in interface RequestMatching<T extends RequestMatching<T>>
predicate
- request method predicate (cannot be null
)public T havingBodyEqualTo(String requestBody)
null
value) and therefore it can be matched by following
invocation: havingBodyEqualTo("")
.havingBodyEqualTo
in interface RequestMatching<T extends RequestMatching<T>>
requestBody
- expected body of the incoming http requestpublic T havingBody(org.hamcrest.Matcher<? super String> predicate)
null
value)
and therefore it can be matched for example by havingBody(equalTo(""))
.havingBody
in interface RequestMatching<T extends RequestMatching<T>>
predicate
- request body predicate (cannot be null
)public T havingRawBodyEqualTo(byte[] requestBody)
null
value) and therefore it can be matched by
havingRawBodyEqualTo(new byte[0])
.havingRawBodyEqualTo
in interface RequestMatching<T extends RequestMatching<T>>
requestBody
- expected body of the incoming http requestpublic T havingPathEqualTo(String path)
havingPathEqualTo("/")
. Please note the path value doesn't contain a query string portion and is
percent-encoded.havingPathEqualTo
in interface RequestMatching<T extends RequestMatching<T>>
path
- expected path of the incoming http requestpublic T havingPath(org.hamcrest.Matcher<? super String> predicate)
havingPath(equalTo("/"))
for example.
Please note the path value doesn't contain a query string portion and is percent-encoded.havingPath
in interface RequestMatching<T extends RequestMatching<T>>
predicate
- request path predicate (cannot be null
)public T havingQueryStringEqualTo(String queryString)
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
)
havingQueryStringEqualTo
in interface RequestMatching<T extends RequestMatching<T>>
queryString
- expected query string of the incoming http requestpublic T havingQueryString(org.hamcrest.Matcher<? super String> predicate)
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
)
havingQueryString
in interface RequestMatching<T extends RequestMatching<T>>
predicate
- query string predicate (cannot be null
)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-type
header must be application/x-www-form-urlencoded
in this case)
havingParameterEqualTo
in interface RequestMatching<T extends RequestMatching<T>>
name
- case sensitive parameter name (cannot be empty)value
- expected parameter value (cannot be null
)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-type
header must be application/x-www-form-urlencoded
in 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 an unknown-param
havingParameter("existing-param", not(empty()))
matches a request which contains
at least one existing-param
havingParameter("existing-param", hasItem("value"))
matches a request which contains
at least one existing-param
with the value value
havingParameter
in interface RequestMatching<T extends RequestMatching<T>>
name
- case sensitive parameter name (cannot be empty)predicate
- parameter predicate (cannot be null)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-type
header must be application/x-www-form-urlencoded
in this case)
havingParameter
in interface RequestMatching<T extends RequestMatching<T>>
name
- case sensitive parameter name (cannot be empty)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-type
header must be application/x-www-form-urlencoded
in this case)
havingParameters
in interface RequestMatching<T extends RequestMatching<T>>
names
- case sensitive parameter namespublic T havingHeaderEqualTo(String name, String value)
havingHeaderEqualTo
in interface RequestMatching<T extends RequestMatching<T>>
name
- case insensitive header name (cannot be empty)value
- expected header value (cannot be null
)public T havingHeader(String name, org.hamcrest.Matcher<? super List<String>> predicate)
havingHeader("unknown-header", nullValue())
matches a request
without an unknown-header
havingHeader("existing-header", not(empty()))
matches a request which contains
at least one existing-header
havingHeader("existing-header", hasItem("value"))
matches a request which contains
at least one existing-header
with the value value
havingHeader
in interface RequestMatching<T extends RequestMatching<T>>
name
- case insensitive header name (cannot be empty)predicate
- header predicate (cannot be null
)public T havingHeader(String name)
havingHeader
in interface RequestMatching<T extends RequestMatching<T>>
name
- case insensitive header name (cannot be empty)public T havingHeaders(String... names)
havingHeaders
in interface RequestMatching<T extends RequestMatching<T>>
names
- case insensitive headers namesCopyright © 2016. All Rights Reserved.