org.springframework.test.util

Class JsonExpectationsHelper

  • java.lang.Object
    • org.springframework.test.util.JsonExpectationsHelper


  • public class JsonExpectationsHelper
    extends java.lang.Object
    A helper class for assertions on JSON content.

    Use of this class requires the JSONassert library.

    Since:
    4.1
    Author:
    Sebastien Deleuze
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void assertJsonEqual(java.lang.String expected, java.lang.String actual)
      Parse the expected and actual strings as JSON and assert the two are "similar" - i.e.
      void assertJsonEqual(java.lang.String expected, java.lang.String actual, boolean strict)
      Parse the expected and actual strings as JSON and assert the two are "similar" - i.e.
      void assertJsonNotEqual(java.lang.String expected, java.lang.String actual)
      Parse the expected and actual strings as JSON and assert the two are "not similar" - i.e.
      void assertJsonNotEqual(java.lang.String expected, java.lang.String actual, boolean strict)
      Parse the expected and actual strings as JSON and assert the two are "not similar" - i.e.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JsonExpectationsHelper

        public JsonExpectationsHelper()
    • Method Detail

      • assertJsonEqual

        public void assertJsonEqual(java.lang.String expected,
                                    java.lang.String actual)
                             throws java.lang.Exception
        Parse the expected and actual strings as JSON and assert the two are "similar" - i.e. they contain the same attribute-value pairs regardless of formatting with a lenient checking (extensible, and non-strict array ordering).
        Parameters:
        expected - the expected JSON content
        actual - the actual JSON content
        Throws:
        java.lang.Exception
        Since:
        4.1
        See Also:
        assertJsonEqual(String, String, boolean)
      • assertJsonEqual

        public void assertJsonEqual(java.lang.String expected,
                                    java.lang.String actual,
                                    boolean strict)
                             throws java.lang.Exception
        Parse the expected and actual strings as JSON and assert the two are "similar" - i.e. they contain the same attribute-value pairs regardless of formatting.

        Can compare in two modes, depending on strict parameter value:

        • true: strict checking. Not extensible, and strict array ordering.
        • false: lenient checking. Extensible, and non-strict array ordering.
        Parameters:
        expected - the expected JSON content
        actual - the actual JSON content
        strict - enables strict checking
        Throws:
        java.lang.Exception
        Since:
        4.2
      • assertJsonNotEqual

        public void assertJsonNotEqual(java.lang.String expected,
                                       java.lang.String actual)
                                throws java.lang.Exception
        Parse the expected and actual strings as JSON and assert the two are "not similar" - i.e. they contain different attribute-value pairs regardless of formatting with a lenient checking (extensible, and non-strict array ordering).
        Parameters:
        expected - the expected JSON content
        actual - the actual JSON content
        Throws:
        java.lang.Exception
        Since:
        4.1
        See Also:
        assertJsonNotEqual(String, String, boolean)
      • assertJsonNotEqual

        public void assertJsonNotEqual(java.lang.String expected,
                                       java.lang.String actual,
                                       boolean strict)
                                throws java.lang.Exception
        Parse the expected and actual strings as JSON and assert the two are "not similar" - i.e. they contain different attribute-value pairs regardless of formatting.

        Can compare in two modes, depending on strict parameter value:

        • true: strict checking. Not extensible, and strict array ordering.
        • false: lenient checking. Extensible, and non-strict array ordering.
        Parameters:
        expected - the expected JSON content
        actual - the actual JSON content
        strict - enables strict checking
        Throws:
        java.lang.Exception
        Since:
        4.2