Class AbstractJsonContentAssert<SELF extends AbstractJsonContentAssert<SELF>>
- Type Parameters:
SELF
- the type of assertions
- All Implemented Interfaces:
org.assertj.core.api.Assert<SELF,
,String> org.assertj.core.api.Descriptable<SELF>
,org.assertj.core.api.EnumerableAssert<SELF,
,Character> org.assertj.core.api.ExtensionPoints<SELF,
String>
- Direct Known Subclasses:
JsonContentAssert
Supports evaluating JSON path expressions and extracting a part of the document for further assertions on the value.
Also supports comparing the JSON document against a target, using
JSON Assert. Resources that are loaded from
the classpath can be relative if a class is provided. By default, UTF-8
is used to load resources,
but this can be overridden using withCharset(Charset)
.
- Since:
- 6.2
- Author:
- Stephane Nicoll, Phillip Webb, Andy Wilkinson, Diego Berrueta, Camille Vienot
-
Field Summary
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself, objects, throwUnsupportedExceptionOnEquals
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractJsonContentAssert
(String json, GenericHttpMessageConverter<Object> jsonMessageConverter, Class<?> selfType) Create an assert for the given JSON document. -
Method Summary
Modifier and TypeMethodDescriptiondoesNotHavePath
(String path) Verify that the given JSONpath
does not match.extractingPath
(String path) Verify that the given JSONpath
is present, and extract the JSON value for further assertions.Verify that the given JSONpath
matches.hasPathSatisfying
(String path, Consumer<org.assertj.core.api.AssertProvider<JsonPathValueAssert>> valueRequirements) Verify that the given JSONpath
is present with a JSON value satisfying the givenvalueRequirements
.isEqualTo
(CharSequence expected, org.skyscreamer.jsonassert.comparator.JSONComparator comparator) Verify that the actual value is equal to the given JSON.isEqualTo
(CharSequence expected, org.skyscreamer.jsonassert.JSONCompareMode compareMode) Verify that the actual value is equal to the given JSON.Verify that the actual value is equal to the given JSONResource
.Verify that the actual value is equal to the given JSONResource
.isLenientlyEqualTo
(CharSequence expected) Verify that the actual value isleniently
equal to the given JSON.isLenientlyEqualTo
(Resource expected) Verify that the actual value isleniently
equal to the given JSONResource
.isNotEqualTo
(CharSequence expected, org.skyscreamer.jsonassert.comparator.JSONComparator comparator) Verify that the actual value is not equal to the given JSON.isNotEqualTo
(CharSequence expected, org.skyscreamer.jsonassert.JSONCompareMode compareMode) Verify that the actual value is not equal to the given JSON.isNotEqualTo
(Resource expected, org.skyscreamer.jsonassert.comparator.JSONComparator comparator) Verify that the actual value is not equal to the given JSONResource
.isNotEqualTo
(Resource expected, org.skyscreamer.jsonassert.JSONCompareMode compareMode) Verify that the actual value is not equal to the given JSONResource
.isNotLenientlyEqualTo
(CharSequence expected) Verify that the actual value is notleniently
equal to the given JSON.isNotLenientlyEqualTo
(Resource expected) Verify that the actual value is notleniently
equal to the given JSONResource
.isNotStrictlyEqualTo
(CharSequence expected) Verify that the actual value is notstrictly
equal to the given JSON.isNotStrictlyEqualTo
(Resource expected) Verify that the actual value is notstrictly
equal to the given JSONResource
.isStrictlyEqualTo
(CharSequence expected) Verify that the actual value isstrictly
equal to the given JSON.isStrictlyEqualTo
(Resource expected) Verify that the actual value isstrictly
equal to the given JSONResource
.withCharset
(Charset charset) Override theCharset
to use to load resources.withResourceLoadClass
(Class<?> resourceLoadClass) Override the class used to load resources.Methods inherited from class org.assertj.core.api.AbstractStringAssert
asBase64Decoded, asBoolean, asByte, asDouble, asFloat, asInt, asLong, asShort, decodedAsBase64, isBase64, isBetween, isEqualTo, isEqualTo, isGreaterThan, isGreaterThanOrEqualTo, isLessThan, isLessThanOrEqualTo, isStrictlyBetween, usingComparator, usingComparator, usingDefaultComparator
Methods inherited from class org.assertj.core.api.AbstractCharSequenceAssert
contains, contains, containsAnyOf, containsIgnoringCase, containsIgnoringNewLines, containsIgnoringWhitespaces, containsOnlyDigits, containsOnlyOnce, containsOnlyWhitespaces, containsPattern, containsPattern, containsPatternSatisfying, containsPatternSatisfying, containsSequence, containsSequence, containsSubsequence, containsSubsequence, containsWhitespaces, doesNotContain, doesNotContain, doesNotContainAnyWhitespaces, doesNotContainIgnoringCase, doesNotContainOnlyWhitespaces, doesNotContainPattern, doesNotContainPattern, doesNotEndWith, doesNotEndWithIgnoringCase, doesNotMatch, doesNotMatch, doesNotStartWith, doesNotStartWithIgnoringCase, endsWith, endsWithIgnoringCase, hasLineCount, hasSameSizeAs, hasSameSizeAs, hasSameSizeAs, hasSize, hasSizeBetween, hasSizeGreaterThan, hasSizeGreaterThanOrEqualTo, hasSizeLessThan, hasSizeLessThanOrEqualTo, inHexadecimal, inUnicode, isAlphabetic, isAlphanumeric, isASCII, isBlank, isEmpty, isEqualToIgnoringCase, isEqualToIgnoringNewLines, isEqualToIgnoringWhitespace, isEqualToNormalizingNewlines, isEqualToNormalizingPunctuationAndWhitespace, isEqualToNormalizingUnicode, isEqualToNormalizingWhitespace, isHexadecimal, isJavaBlank, isLowerCase, isMixedCase, isNotBlank, isNotEmpty, isNotEqualToIgnoringCase, isNotEqualToIgnoringWhitespace, isNotEqualToNormalizingWhitespace, isNotJavaBlank, isNullOrEmpty, isPrintable, isSubstringOf, isUpperCase, isVisible, isXmlEqualTo, isXmlEqualToContentOf, matches, matches, matchesSatisfying, matchesSatisfying, startsWith, startsWithIgnoringCase, usingDefaultElementComparator, usingElementComparator
Methods inherited from class org.assertj.core.api.AbstractAssert
areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, hasToString, inBinary, is, isElementOfCustomAssert, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparison, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnError
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.assertj.core.api.Descriptable
as, as, as, describedAs, describedAs
-
Constructor Details
-
AbstractJsonContentAssert
protected AbstractJsonContentAssert(@Nullable String json, @Nullable GenericHttpMessageConverter<Object> jsonMessageConverter, Class<?> selfType) Create an assert for the given JSON document.Path can be converted to a value object using the given JSON message converter.
- Parameters:
json
- the JSON document to assertjsonMessageConverter
- the converter to useselfType
- the implementation type of this assert
-
-
Method Details
-
extractingPath
Verify that the given JSONpath
is present, and extract the JSON value for further assertions.- Parameters:
path
- theJsonPath
expression- See Also:
-
hasPathSatisfying
public SELF hasPathSatisfying(String path, Consumer<org.assertj.core.api.AssertProvider<JsonPathValueAssert>> valueRequirements) Verify that the given JSONpath
is present with a JSON value satisfying the givenvalueRequirements
.- Parameters:
path
- theJsonPath
expressionvalueRequirements
- aConsumer
of the assertion object
-
hasPath
Verify that the given JSONpath
matches. For paths with an operator, this validates that the path expression is valid, but does not validate that it yield any results.- Parameters:
path
- theJsonPath
expression
-
doesNotHavePath
Verify that the given JSONpath
does not match.- Parameters:
path
- theJsonPath
expression
-
isEqualTo
public SELF isEqualTo(@Nullable CharSequence expected, org.skyscreamer.jsonassert.JSONCompareMode compareMode) Verify that the actual value is equal to the given JSON. Theexpected
value can contain the JSON itself or, if it ends with.json
, the name of a resource to be loaded from the classpath.- Parameters:
expected
- the expected JSON or the name of a resource containing the expected JSONcompareMode
- the compare mode used when checking
-
isEqualTo
Verify that the actual value is equal to the given JSONResource
.The resource abstraction allows to provide several input types:
- a
byte
array, usingByteArrayResource
- a
classpath
resource, usingClassPathResource
- a
File
orPath
, usingFileSystemResource
- an
InputStream
, usingInputStreamResource
- Parameters:
expected
- a resource containing the expected JSONcompareMode
- the compare mode used when checking
- a
-
isEqualTo
public SELF isEqualTo(@Nullable CharSequence expected, org.skyscreamer.jsonassert.comparator.JSONComparator comparator) Verify that the actual value is equal to the given JSON. Theexpected
value can contain the JSON itself or, if it ends with.json
, the name of a resource to be loaded from the classpath.- Parameters:
expected
- the expected JSON or the name of a resource containing the expected JSONcomparator
- the comparator used when checking
-
isEqualTo
public SELF isEqualTo(Resource expected, org.skyscreamer.jsonassert.comparator.JSONComparator comparator) Verify that the actual value is equal to the given JSONResource
.The resource abstraction allows to provide several input types:
- a
byte
array, usingByteArrayResource
- a
classpath
resource, usingClassPathResource
- a
File
orPath
, usingFileSystemResource
- an
InputStream
, usingInputStreamResource
- Parameters:
expected
- a resource containing the expected JSONcomparator
- the comparator used when checking
- a
-
isLenientlyEqualTo
Verify that the actual value isleniently
equal to the given JSON. Theexpected
value can contain the JSON itself or, if it ends with.json
, the name of a resource to be loaded from the classpath.- Parameters:
expected
- the expected JSON or the name of a resource containing the expected JSON
-
isLenientlyEqualTo
Verify that the actual value isleniently
equal to the given JSONResource
.The resource abstraction allows to provide several input types:
- a
byte
array, usingByteArrayResource
- a
classpath
resource, usingClassPathResource
- a
File
orPath
, usingFileSystemResource
- an
InputStream
, usingInputStreamResource
- Parameters:
expected
- a resource containing the expected JSON
- a
-
isStrictlyEqualTo
Verify that the actual value isstrictly
equal to the given JSON. Theexpected
value can contain the JSON itself or, if it ends with.json
, the name of a resource to be loaded from the classpath.- Parameters:
expected
- the expected JSON or the name of a resource containing the expected JSON
-
isStrictlyEqualTo
Verify that the actual value isstrictly
equal to the given JSONResource
.The resource abstraction allows to provide several input types:
- a
byte
array, usingByteArrayResource
- a
classpath
resource, usingClassPathResource
- a
File
orPath
, usingFileSystemResource
- an
InputStream
, usingInputStreamResource
- Parameters:
expected
- a resource containing the expected JSON
- a
-
isNotEqualTo
public SELF isNotEqualTo(@Nullable CharSequence expected, org.skyscreamer.jsonassert.JSONCompareMode compareMode) Verify that the actual value is not equal to the given JSON. Theexpected
value can contain the JSON itself or, if it ends with.json
, the name of a resource to be loaded from the classpath.- Parameters:
expected
- the expected JSON or the name of a resource containing the expected JSONcompareMode
- the compare mode used when checking
-
isNotEqualTo
Verify that the actual value is not equal to the given JSONResource
.The resource abstraction allows to provide several input types:
- a
byte
array, usingByteArrayResource
- a
classpath
resource, usingClassPathResource
- a
File
orPath
, usingFileSystemResource
- an
InputStream
, usingInputStreamResource
- Parameters:
expected
- a resource containing the expected JSONcompareMode
- the compare mode used when checking
- a
-
isNotEqualTo
public SELF isNotEqualTo(@Nullable CharSequence expected, org.skyscreamer.jsonassert.comparator.JSONComparator comparator) Verify that the actual value is not equal to the given JSON. Theexpected
value can contain the JSON itself or, if it ends with.json
, the name of a resource to be loaded from the classpath.- Parameters:
expected
- the expected JSON or the name of a resource containing the expected JSONcomparator
- the comparator used when checking
-
isNotEqualTo
public SELF isNotEqualTo(Resource expected, org.skyscreamer.jsonassert.comparator.JSONComparator comparator) Verify that the actual value is not equal to the given JSONResource
.The resource abstraction allows to provide several input types:
- a
byte
array, usingByteArrayResource
- a
classpath
resource, usingClassPathResource
- a
File
orPath
, usingFileSystemResource
- an
InputStream
, usingInputStreamResource
- Parameters:
expected
- a resource containing the expected JSONcomparator
- the comparator used when checking
- a
-
isNotLenientlyEqualTo
Verify that the actual value is notleniently
equal to the given JSON. Theexpected
value can contain the JSON itself or, if it ends with.json
, the name of a resource to be loaded from the classpath.- Parameters:
expected
- the expected JSON or the name of a resource containing the expected JSON
-
isNotLenientlyEqualTo
Verify that the actual value is notleniently
equal to the given JSONResource
.The resource abstraction allows to provide several input types:
- a
byte
array, usingByteArrayResource
- a
classpath
resource, usingClassPathResource
- a
File
orPath
, usingFileSystemResource
- an
InputStream
, usingInputStreamResource
- Parameters:
expected
- a resource containing the expected JSON
- a
-
isNotStrictlyEqualTo
Verify that the actual value is notstrictly
equal to the given JSON. Theexpected
value can contain the JSON itself or, if it ends with.json
, the name of a resource to be loaded from the classpath.- Parameters:
expected
- the expected JSON or the name of a resource containing the expected JSON
-
isNotStrictlyEqualTo
Verify that the actual value is notstrictly
equal to the given JSONResource
.The resource abstraction allows to provide several input types:
- a
byte
array, usingByteArrayResource
- a
classpath
resource, usingClassPathResource
- a
File
orPath
, usingFileSystemResource
- an
InputStream
, usingInputStreamResource
- Parameters:
expected
- a resource containing the expected JSON
- a
-
withResourceLoadClass
Override the class used to load resources.Resources can be loaded from an absolute location or relative to the specified class. For instance, specifying
com.example.MyClass
as the resource class allows you to use "my-file.json" to load/com/example/my-file.json
.- Parameters:
resourceLoadClass
- the class used to load resources, ornull
to only use absolute paths
-
withCharset
Override theCharset
to use to load resources.By default, resources are loaded using
UTF-8
.- Parameters:
charset
- the charset to use, ornull
to use the default
-