Class ComplianceKit
java.lang.Object
ca.marcusdunn.jsonlens.testkit.ComplianceKit
Runs the test suites of RFC 9535 and RFC 6902 on a model, as JUnit dynamic tests.
jsonPath(JsonModel, Function)runs each valid query of the JSONPath Compliance Test Suite, and compares the values and the Normalized Paths of the results.jsonPatchInPlace(JsonModel, Function)andjsonPatchToCopy(JsonModel, Function)run each test of the JSON Patch test suite (json-patch-tests): in place, and to a copy. A patch that must fail must leave the document as it was.
The model reads each document from its JSON text, with the parser of its own library. The suites are in the JAR, with their licenses: the JSONPath Compliance Test Suite (BSD-2), and the JSON Patch tests (Apache-2.0).
// The suites as JUnit dynamic tests, for example in a test class that is not a contract test.
@TestFactory
Stream<DynamicTest> jsonPathSuite() {
return ComplianceKit.jsonPath(new CollectionsModel(), TestkitSnippets::parse);
}
-
Method Summary
Modifier and TypeMethodDescriptionstatic <N, M extends JsonModel<N> & JsonFactory<N> & JsonEditor<N>>
Stream<org.junit.jupiter.api.DynamicTest> jsonPatchInPlace(M model, Function<String, N> parser) Returns a test for each test of the JSON Patch test suite, in place.static <N, M extends JsonModel<N> & JsonFactory<N>>
Stream<org.junit.jupiter.api.DynamicTest> jsonPatchToCopy(M model, Function<String, N> parser) Returns a test for each test of the JSON Patch test suite, to a copy.static <N> Stream<org.junit.jupiter.api.DynamicTest> Returns a test for each valid query of the JSONPath Compliance Test Suite.
-
Method Details
-
jsonPath
public static <N> Stream<org.junit.jupiter.api.DynamicTest> jsonPath(JsonModel<N> model, Function<String, N> parser) Returns a test for each valid query of the JSONPath Compliance Test Suite.- Type Parameters:
N- the node type of the model- Parameters:
model- the model under testparser- reads a JSON text into a node of the model- Returns:
- the tests
-
jsonPatchInPlace
public static <N, M extends JsonModel<N> & JsonFactory<N> & JsonEditor<N>> Stream<org.junit.jupiter.api.DynamicTest> jsonPatchInPlace(M model, Function<String, N> parser) Returns a test for each test of the JSON Patch test suite, in place.- Type Parameters:
N- the node type of the modelM- the type of the model- Parameters:
model- the model under testparser- reads a JSON text into a node of the model- Returns:
- the tests
-
jsonPatchToCopy
public static <N, M extends JsonModel<N> & JsonFactory<N>> Stream<org.junit.jupiter.api.DynamicTest> jsonPatchToCopy(M model, Function<String, N> parser) Returns a test for each test of the JSON Patch test suite, to a copy. Use it for a model that builds values but does not change them.- Type Parameters:
N- the node type of the modelM- the type of the model- Parameters:
model- the model under testparser- reads a JSON text into a node of the model- Returns:
- the tests
-