public class JsonPathExpectationsHelper
extends java.lang.Object
Based on the JsonPath project: requiring version 0.9+, with 1.1+ strongly recommended.
Constructor and Description |
---|
JsonPathExpectationsHelper(java.lang.String expression,
java.lang.Object... args)
Construct a new
JsonPathExpectationsHelper . |
Modifier and Type | Method and Description |
---|---|
<T> void |
assertValue(java.lang.String content,
Matcher<T> matcher)
Evaluate the JSON path expression against the supplied
content
and assert the resulting value with the given Matcher . |
<T> void |
assertValue(java.lang.String content,
Matcher<T> matcher,
java.lang.Class<T> targetType)
An overloaded variant of
assertValue(String, Matcher) that also
accepts a target type for the resulting value. |
void |
assertValue(java.lang.String content,
java.lang.Object expectedValue)
Evaluate the JSON path expression against the supplied
content
and assert that the result is equal to the expected value. |
void |
assertValueIsArray(java.lang.String content)
Evaluate the JSON path expression against the supplied
content
and assert that the resulting value is an array. |
void |
assertValueIsBoolean(java.lang.String content)
Evaluate the JSON path expression against the supplied
content
and assert that the resulting value is a Boolean . |
void |
assertValueIsEmpty(java.lang.String content)
Evaluate the JSON path expression against the supplied
content
and assert that an empty value exists at the given path. |
void |
assertValueIsMap(java.lang.String content)
Evaluate the JSON path expression against the supplied
content
and assert that the resulting value is a Map . |
void |
assertValueIsNotEmpty(java.lang.String content)
Evaluate the JSON path expression against the supplied
content
and assert that a non-empty value exists at the given path. |
void |
assertValueIsNumber(java.lang.String content)
Evaluate the JSON path expression against the supplied
content
and assert that the resulting value is a Number . |
void |
assertValueIsString(java.lang.String content)
Evaluate the JSON path expression against the supplied
content
and assert that the resulting value is a String . |
void |
doesNotExist(java.lang.String content)
Evaluate the JSON path expression against the supplied
content
and assert that a value does not exist at the given path. |
void |
exists(java.lang.String content)
Evaluate the JSON path expression against the supplied
content
and assert that a non-null value exists at the given path. |
public JsonPathExpectationsHelper(java.lang.String expression, java.lang.Object... args)
JsonPathExpectationsHelper
.expression
- the JsonPath
expression; never null
or emptyargs
- arguments to parameterize the JsonPath
expression with,
using formatting specifiers defined in String.format(String, Object...)
public <T> void assertValue(java.lang.String content, Matcher<T> matcher)
content
and assert the resulting value with the given Matcher
.content
- the JSON contentmatcher
- the matcher with which to assert the resultpublic <T> void assertValue(java.lang.String content, Matcher<T> matcher, java.lang.Class<T> targetType)
assertValue(String, Matcher)
that also
accepts a target type for the resulting value. This can be useful for
matching numbers reliably for example coercing an integer into a double.content
- the JSON contentmatcher
- the matcher with which to assert the resulttargetType
- a the expected type of the resulting valuepublic void assertValue(java.lang.String content, java.lang.Object expectedValue)
content
and assert that the result is equal to the expected value.content
- the JSON contentexpectedValue
- the expected valuepublic void assertValueIsString(java.lang.String content)
content
and assert that the resulting value is a String
.content
- the JSON contentpublic void assertValueIsBoolean(java.lang.String content)
content
and assert that the resulting value is a Boolean
.content
- the JSON contentpublic void assertValueIsNumber(java.lang.String content)
content
and assert that the resulting value is a Number
.content
- the JSON contentpublic void assertValueIsArray(java.lang.String content)
content
and assert that the resulting value is an array.content
- the JSON contentpublic void assertValueIsMap(java.lang.String content)
content
and assert that the resulting value is a Map
.content
- the JSON contentpublic void exists(java.lang.String content)
content
and assert that a non-null value exists at the given path.
If the JSON path expression is not definite, this method asserts that the value at the given path is not empty.
content
- the JSON contentpublic void doesNotExist(java.lang.String content)
content
and assert that a value does not exist at the given path.
If the JSON path expression is not definite, this method asserts that the value at the given path is empty.
content
- the JSON contentpublic void assertValueIsEmpty(java.lang.String content)
content
and assert that an empty value exists at the given path.
For the semantics of empty, consult the Javadoc for
ObjectUtils.isEmpty(Object)
.
content
- the JSON contentpublic void assertValueIsNotEmpty(java.lang.String content)
content
and assert that a non-empty value exists at the given path.
For the semantics of empty, consult the Javadoc for
ObjectUtils.isEmpty(Object)
.
content
- the JSON content