HttpRequest |
HttpRequest.withBody(Body body)
The body match rules on such as using one of the Body subclasses as follows:
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 |