public class HttpRequest extends Not implements HttpObject<HttpRequest,Body>
Constructor and Description |
---|
HttpRequest() |
Modifier and Type | Method and Description |
---|---|
HttpRequest |
clone() |
boolean |
containsHeader(String name)
Returns true if a header with the specified name has been added
|
boolean |
containsHeader(String name,
String value)
Returns true if a header with the specified name and value has been added
|
Body |
getBody() |
byte[] |
getBodyAsRawBytes() |
String |
getBodyAsString() |
List<Cookie> |
getCookieList() |
Cookies |
getCookies() |
String |
getFirstHeader(String name) |
String |
getFirstQueryStringParameter(String name) |
List<String> |
getHeader(String name) |
List<Header> |
getHeaderList() |
Headers |
getHeaders() |
NottableString |
getMethod() |
String |
getMethod(String defaultValue) |
NottableString |
getPath() |
List<Parameter> |
getQueryStringParameterList() |
Parameters |
getQueryStringParameters() |
SocketAddress |
getSocketAddress() |
boolean |
hasQueryStringParameter(NottableString name,
NottableString value) |
boolean |
hasQueryStringParameter(String name,
String value) |
Boolean |
isKeepAlive() |
Boolean |
isSecure() |
boolean |
matches(String method) |
boolean |
matches(String method,
String... paths) |
HttpRequest |
removeHeader(NottableString name) |
HttpRequest |
removeHeader(String name) |
HttpRequest |
replaceHeader(Header header)
Adds one header to match on as a Header object where the header values list can be a list of strings or regular expressions
(for more details of the supported regex syntax see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html)
|
static HttpRequest |
request() |
static HttpRequest |
request(String path) |
InetSocketAddress |
socketAddressFromHostHeader() |
HttpRequest |
update(HttpRequest replaceRequest) |
HttpRequest |
withBody(Body body)
The body match rules on such as using one of the Body subclasses as follows:
|
HttpRequest |
withBody(byte[] body)
The body to match on as binary data such as a pdf or image
|
HttpRequest |
withBody(String body)
The exact string body to match on such as "this is an exact string body"
|
HttpRequest |
withBody(String body,
Charset charset)
The exact string body to match on such as "this is an exact string body"
|
HttpRequest |
withContentType(MediaType mediaType) |
HttpRequest |
withCookie(Cookie cookie)
Adds one cookie to match on as a Cookie object where the cookie values list can be a list of strings or regular expressions
(for more details of the supported regex syntax see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html)
|
HttpRequest |
withCookie(NottableString name,
NottableString value)
Adds one cookie to match on or to not match on using the NottableString, each NottableString can either be a positive matching value,
such as string("match"), or a value to not match on, such as not("do not match"), the string values passed to the NottableString
can be a plain string or a regex (for more details of the supported regex syntax see
http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html)
|
HttpRequest |
withCookie(String name,
String value)
Adds one cookie to match on, which can specified using either plain strings or regular expressions
(for more details of the supported regex syntax see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html)
|
HttpRequest |
withCookies(Cookie... cookies)
The cookies to match on as a varags Cookie objects where the values or keys of each cookie can be either a string or a regex
(for more details of the supported regex syntax see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html)
|
HttpRequest |
withCookies(Cookies cookies) |
HttpRequest |
withCookies(List<Cookie> cookies)
The cookies to match on as a list of Cookie objects where the values or keys of each cookie can be either a string or a regex
(for more details of the supported regex syntax see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html)
|
HttpRequest |
withHeader(Header header)
Adds one header to match on as a Header object where the header values list can be a list of strings or regular expressions
(for more details of the supported regex syntax see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html)
|
HttpRequest |
withHeader(NottableString name,
NottableString... values)
Adds one header to match on or to not match on using the NottableString, each NottableString can either be a positive matching value,
such as string("match"), or a value to not match on, such as not("do not match"), the string values passed to the NottableString
can also be a plain string or a regex (for more details of the supported regex syntax
see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html)
|
HttpRequest |
withHeader(String name,
String... values)
Adds one header to match which can specified using plain strings or regular expressions
(for more details of the supported regex syntax see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html)
|
HttpRequest |
withHeaders(Header... headers)
The headers to match on as a varags of Header objects where the values or keys of each header can be either a string or a regex
(for more details of the supported regex syntax see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html)
|
HttpRequest |
withHeaders(Headers headers) |
HttpRequest |
withHeaders(List<Header> headers)
The headers to match on as a list of Header objects where the values or keys of each header can be either a string or a regex
(for more details of the supported regex syntax see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html)
|
HttpRequest |
withKeepAlive(Boolean isKeepAlive)
Match on whether the request was made using an HTTP persistent connection, also called HTTP keep-alive, or HTTP connection reuse
|
HttpRequest |
withMethod(NottableString method)
The HTTP method all method except a specific value using the "not" operator,
for example this allows operations such as not("GET")
|
HttpRequest |
withMethod(String method)
The HTTP method to match on such as "GET" or "POST"
|
HttpRequest |
withPath(NottableString path)
The path to not match on for example not("/some_mocked_path") with match any path not equal to "/some_mocked_path",
the servlet context path is ignored for matching and should not be specified here
regex values are also supported such as not(".*_path"), see
http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html for full details of the supported regex syntax
|
HttpRequest |
withPath(String path)
The path to match on such as "/some_mocked_path" any servlet context path is ignored for matching and should not be specified here
regex values are also supported such as ".*_path", see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html
for full details of the supported regex syntax
|
HttpRequest |
withQueryStringParameter(NottableString name,
NottableString... values)
Adds one query string parameter to match on or to not match on using the NottableString, each NottableString can either be a positive matching
value, such as string("match"), or a value to not match on, such as not("do not match"), the string values passed to the NottableString
can also be a plain string or a regex (for more details of the supported regex syntax
see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html)
|
HttpRequest |
withQueryStringParameter(Parameter parameter)
Adds one query string parameter to match on as a Parameter object where the parameter values list can be a list of strings or regular expressions
(for more details of the supported regex syntax see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html)
|
HttpRequest |
withQueryStringParameter(String name,
String... values)
Adds one query string parameter to match which can specified using plain strings or regular expressions
(for more details of the supported regex syntax see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html)
|
HttpRequest |
withQueryStringParameters(List<Parameter> parameters)
The query string parameters to match on as a list of Parameter objects where the values or keys of each parameter can be either a string or a regex
(for more details of the supported regex syntax see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html)
|
HttpRequest |
withQueryStringParameters(Map<String,List<String>> parameters)
The query string parameters to match on as a Map
|
HttpRequest |
withQueryStringParameters(Parameter... parameters)
The query string parameters to match on as a varags Parameter objects where the values or keys of each parameter can be either a string or a regex
(for more details of the supported regex syntax see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html)
|
HttpRequest |
withQueryStringParameters(Parameters parameters) |
HttpRequest |
withSecure(Boolean isSsl)
Match on whether the request was made over SSL (i.e.
|
HttpRequest |
withSocketAddress(SocketAddress socketAddress)
Specify remote address if the remote address can't be derived from the host header,
if no value is specified the host header will be used to determine remote address
|
HttpRequest |
withSocketAddress(String host,
Integer port,
SocketAddress.Scheme scheme)
Specify remote address if the remote address can't be derived from the host header,
if no value is specified the host header will be used to determine remote address
|
toString
equals, fieldsExcludedFromEqualsAndHashCode, hashCode
public static HttpRequest request()
public static HttpRequest request(String path)
public Boolean isKeepAlive()
public HttpRequest withKeepAlive(Boolean isKeepAlive)
isKeepAlive
- true if the request was made with an HTTP persistent connectionpublic Boolean isSecure()
public HttpRequest withSecure(Boolean isSsl)
isSsl
- true if the request was made with SSLpublic SocketAddress getSocketAddress()
public HttpRequest withSocketAddress(SocketAddress socketAddress)
socketAddress
- the remote address to send request topublic HttpRequest withSocketAddress(String host, Integer port, SocketAddress.Scheme scheme)
host
- the remote host or ip to send request toport
- the remote port to send request toscheme
- the scheme to use for remote socketpublic HttpRequest withMethod(String method)
method
- the HTTP method such as "GET" or "POST"public HttpRequest withMethod(NottableString method)
method
- the HTTP method to not match on not("GET") or not("POST")public NottableString getMethod()
public HttpRequest withPath(String path)
path
- the path such as "/some_mocked_path" or a regexpublic HttpRequest withPath(NottableString path)
path
- the path to not match on such as not("/some_mocked_path") or not(".*_path")public NottableString getPath()
public boolean matches(String method)
public Parameters getQueryStringParameters()
public HttpRequest withQueryStringParameters(Parameters parameters)
public HttpRequest withQueryStringParameters(List<Parameter> parameters)
parameters
- the list of Parameter objects where the values or keys of each parameter can be either a string or a regexpublic HttpRequest withQueryStringParameters(Parameter... parameters)
parameters
- the varags Parameter objects where the values or keys of each parameter can be either a string or a regexpublic HttpRequest withQueryStringParameters(Map<String,List<String>> parameters)
parameters
- the Mappublic HttpRequest withQueryStringParameter(Parameter parameter)
parameter
- the Parameter object which can have a values list of strings or regular expressionspublic HttpRequest withQueryStringParameter(String name, String... values)
name
- the parameter namevalues
- the parameter values which can be a varags of strings or regular expressionspublic HttpRequest withQueryStringParameter(NottableString name, NottableString... values)
name
- the parameter name as a NottableStringvalues
- the parameter values which can be a varags of NottableStringspublic boolean hasQueryStringParameter(NottableString name, NottableString value)
public HttpRequest withBody(String body)
withBody
in interface HttpObject<HttpRequest,Body>
body
- the body on such as "this is an exact string body"public HttpRequest withBody(String body, Charset charset)
withBody
in interface HttpObject<HttpRequest,Body>
body
- the body on such as "this is an exact string body"charset
- character set the string will be encoded inpublic HttpRequest withBody(byte[] body)
withBody
in interface HttpObject<HttpRequest,Body>
body
- a byte arraypublic HttpRequest withBody(Body body)
exact string match: - exact("this is an exact string body");
or
- new StringBody("this is an exact string body")
regular expression match: - regex("username[a-z]{4}");
or
- new RegexBody("username[a-z]{4}");
json match: - json("{username: 'foo', password: 'bar'}");
or
- json("{username: 'foo', password: 'bar'}", MatchType.STRICT);
or
- new JsonBody("{username: 'foo', password: 'bar'}");
json schema match: - jsonSchema("{type: 'object', properties: { 'username': { 'type': 'string' }, 'password': { 'type': 'string' } }, 'required': ['username', 'password']}");
or
- jsonSchemaFromResource("org/mockserver/model/loginSchema.json");
or
- new JsonSchemaBody("{type: 'object', properties: { 'username': { 'type': 'string' }, 'password': { 'type': 'string' } }, 'required': ['username', 'password']}");
xpath match: - xpath("/element[key = 'some_key' and value = 'some_value']");
or
- new XPathBody("/element[key = 'some_key' and value = 'some_value']");
body parameter match: - params( param("name_one", "value_one_one", "value_one_two") param("name_two", "value_two") );
or
- new ParameterBody( new Parameter("name_one", "value_one_one", "value_one_two") new Parameter("name_two", "value_two") );
binary match: - binary(IOUtils.readFully(getClass().getClassLoader().getResourceAsStream("example.pdf"), 1024));
or
- new BinaryBody(IOUtils.readFully(getClass().getClassLoader().getResourceAsStream("example.pdf"), 1024));
for more details of the supported regular expression syntax see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html for more details of the supported json syntax see http://jsonassert.skyscreamer.org for more details of the supported json schema syntax see http://json-schema.org/ for more detail of XPath syntax see http://saxon.sourceforge.net/saxon6.5.3/expressions.html
withBody
in interface HttpObject<HttpRequest,Body>
body
- an instance of one of the Body subclasses including StringBody, ParameterBody or BinaryBodypublic Body getBody()
getBody
in interface HttpObject<HttpRequest,Body>
public byte[] getBodyAsRawBytes()
getBodyAsRawBytes
in interface HttpObject<HttpRequest,Body>
public String getBodyAsString()
getBodyAsString
in interface HttpObject<HttpRequest,Body>
public Headers getHeaders()
getHeaders
in interface HttpObject<HttpRequest,Body>
public HttpRequest withHeaders(Headers headers)
withHeaders
in interface HttpObject<HttpRequest,Body>
public HttpRequest withHeaders(List<Header> headers)
withHeaders
in interface HttpObject<HttpRequest,Body>
headers
- the list of Header objects where the values or keys of each header can be either a string or a regexpublic HttpRequest withHeaders(Header... headers)
withHeaders
in interface HttpObject<HttpRequest,Body>
headers
- the varags of Header objects where the values or keys of each header can be either a string or a regexpublic HttpRequest withHeader(Header header)
withHeader
in interface HttpObject<HttpRequest,Body>
header
- the Header object which can have a values list of strings or regular expressionspublic HttpRequest withHeader(String name, String... values)
withHeader
in interface HttpObject<HttpRequest,Body>
name
- the header namevalues
- the header values which can be a varags of strings or regular expressionspublic HttpRequest withHeader(NottableString name, NottableString... values)
withHeader
in interface HttpObject<HttpRequest,Body>
name
- the header name as a NottableStringvalues
- the header values which can be a varags of NottableStringspublic HttpRequest withContentType(MediaType mediaType)
withContentType
in interface HttpObject<HttpRequest,Body>
public HttpRequest replaceHeader(Header header)
replaceHeader
in interface HttpObject<HttpRequest,Body>
header
- the Header object which can have a values list of strings or regular expressionspublic List<Header> getHeaderList()
getHeaderList
in interface HttpObject<HttpRequest,Body>
public List<String> getHeader(String name)
getHeader
in interface HttpObject<HttpRequest,Body>
public String getFirstHeader(String name)
getFirstHeader
in interface HttpObject<HttpRequest,Body>
public boolean containsHeader(String name)
containsHeader
in interface HttpObject<HttpRequest,Body>
name
- the header namepublic boolean containsHeader(String name, String value)
name
- the header namevalue
- the header valuepublic HttpRequest removeHeader(String name)
removeHeader
in interface HttpObject<HttpRequest,Body>
public HttpRequest removeHeader(NottableString name)
removeHeader
in interface HttpObject<HttpRequest,Body>
public Cookies getCookies()
getCookies
in interface HttpObject<HttpRequest,Body>
public HttpRequest withCookies(Cookies cookies)
withCookies
in interface HttpObject<HttpRequest,Body>
public HttpRequest withCookies(List<Cookie> cookies)
withCookies
in interface HttpObject<HttpRequest,Body>
cookies
- a list of Cookie objectspublic HttpRequest withCookies(Cookie... cookies)
withCookies
in interface HttpObject<HttpRequest,Body>
cookies
- a varargs of Cookie objectspublic HttpRequest withCookie(Cookie cookie)
withCookie
in interface HttpObject<HttpRequest,Body>
cookie
- a Cookie objectpublic HttpRequest withCookie(String name, String value)
withCookie
in interface HttpObject<HttpRequest,Body>
name
- the cookies namevalue
- the cookies valuepublic HttpRequest withCookie(NottableString name, NottableString value)
withCookie
in interface HttpObject<HttpRequest,Body>
name
- the cookies namevalue
- the cookies valuepublic List<Cookie> getCookieList()
getCookieList
in interface HttpObject<HttpRequest,Body>
public InetSocketAddress socketAddressFromHostHeader()
public HttpRequest clone()
public HttpRequest update(HttpRequest replaceRequest)
Copyright © 2020. All rights reserved.