Class JsonAssert

Object
JsonAssert

public class JsonAssert extends Object
The class provides assertion functionalities to validate JSON documents against a JSchema or JSON document.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Initializes a new instance of the JsonAssert class for the specified JSchema string.
    JsonAssert(String expected, TreeType type)
    Initializes a new instance of the JsonAssert class for the specified expected string, which can be either a JSchema or a JSON representation.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    areEqual(String expected, String actual)
    Tests if the provided JSON strings are logically equivalent, meaning their structural composition and internal data are identical.
     
     
    void
    Tests whether the input JSON string conforms to the expected JSchema or JSON specified in the JsonAssert constructor.
    static void
    isValid(String schema, String json)
    Tests whether the specified JSON string conforms to the given JSchema string and throws an exception if the JSON string does not conform to the JSchema.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JsonAssert

      public JsonAssert(String schema)
      Initializes a new instance of the JsonAssert class for the specified JSchema string.
      Parameters:
      schema - A JSchema string for validation or conformation
    • JsonAssert

      public JsonAssert(String expected, TreeType type)
      Initializes a new instance of the JsonAssert class for the specified expected string, which can be either a JSchema or a JSON representation.
      Parameters:
      expected - An expected JSchema or JSON string for validation or conformation
      type - The type of string provided by expected, indicating whether it represents a JSchema or JSON. Use TreeType.SCHEMA_TREE for JSchema and TreeType.JSON_TREE for JSON.
  • Method Details

    • isValid

      public void isValid(String json)
      Tests whether the input JSON string conforms to the expected JSchema or JSON specified in the JsonAssert constructor.
      Parameters:
      json - The actual input JSON to conform or validate
    • isValid

      public static void isValid(String schema, String json)
      Tests whether the specified JSON string conforms to the given JSchema string and throws an exception if the JSON string does not conform to the JSchema.
      Parameters:
      schema - The expected JSchema to conform or validate
      json - The actual JSON to conform or validate
    • areEqual

      public static void areEqual(String expected, String actual)
      Tests if the provided JSON strings are logically equivalent, meaning their structural composition and internal data are identical. If the JSON strings are not equivalent, an exception is thrown.
      Parameters:
      expected - The expected JSON to compare
      actual - The actual JSON to compare
    • getRuntime

      public RuntimeContext getRuntime()
    • getExpectedTree

      public DataTree getExpectedTree()