类 JsonPathExpectationsHelper


  • public class JsonPathExpectationsHelper
    extends Object
    A helper class for applying assertions via JSON path expressions.

    Based on the JsonPath project: requiring version 0.9+, with 1.1+ strongly recommended.

    从以下版本开始:
    3.2
    作者:
    Rossen Stoyanchev, Juergen Hoeller, Craig Andrews, Sam Brannen
    • 构造器详细资料

    • 方法详细资料

      • assertValue

        public <T> void assertValue​(String content,
                                    Matcher<T> matcher)
        Evaluate the JSON path expression against the supplied content and assert the resulting value with the given Matcher.
        参数:
        content - the JSON content
        matcher - the matcher with which to assert the result
      • assertValue

        public <T> void assertValue​(String content,
                                    Matcher<T> matcher,
                                    Class<T> targetType)
        An overloaded variant of 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 content
        matcher - the matcher with which to assert the result
        targetType - a the expected type of the resulting value
        从以下版本开始:
        4.3.3
      • assertValue

        public void assertValue​(String content,
                                Object expectedValue)
        Evaluate the JSON path expression against the supplied content and assert that the result is equal to the expected value.
        参数:
        content - the JSON content
        expectedValue - the expected value
      • assertValueIsString

        public void assertValueIsString​(String content)
        Evaluate the JSON path expression against the supplied content and assert that the resulting value is a String.
        参数:
        content - the JSON content
        从以下版本开始:
        4.2.1
      • assertValueIsBoolean

        public void assertValueIsBoolean​(String content)
        Evaluate the JSON path expression against the supplied content and assert that the resulting value is a Boolean.
        参数:
        content - the JSON content
        从以下版本开始:
        4.2.1
      • assertValueIsNumber

        public void assertValueIsNumber​(String content)
        Evaluate the JSON path expression against the supplied content and assert that the resulting value is a Number.
        参数:
        content - the JSON content
        从以下版本开始:
        4.2.1
      • assertValueIsArray

        public void assertValueIsArray​(String content)
        Evaluate the JSON path expression against the supplied content and assert that the resulting value is an array.
        参数:
        content - the JSON content
      • assertValueIsMap

        public void assertValueIsMap​(String content)
        Evaluate the JSON path expression against the supplied content and assert that the resulting value is a Map.
        参数:
        content - the JSON content
        从以下版本开始:
        4.2.1
      • exists

        public void exists​(String content)
        Evaluate the JSON path expression against the supplied 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 content
      • doesNotExist

        public void doesNotExist​(String content)
        Evaluate the JSON path expression against the supplied 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 content
      • assertValueIsEmpty

        public void assertValueIsEmpty​(String content)
        Evaluate the JSON path expression against the supplied 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 content
      • assertValueIsNotEmpty

        public void assertValueIsNotEmpty​(String content)
        Evaluate the JSON path expression against the supplied 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