Class CompareAssert
- java.lang.Object
-
- org.assertj.core.api.AbstractAssert<SELF,ACTUAL>
-
- org.xmlunit.assertj.CustomAbstractAssert<CompareAssert,java.lang.Object>
-
- org.xmlunit.assertj.CompareAssert
-
- All Implemented Interfaces:
org.assertj.core.api.Assert<CompareAssert,java.lang.Object>
,org.assertj.core.api.Descriptable<CompareAssert>
,org.assertj.core.api.ExtensionPoints<CompareAssert,java.lang.Object>
,DifferenceEngineConfigurer<CompareAssert>
public class CompareAssert extends CustomAbstractAssert<CompareAssert,java.lang.Object> implements DifferenceEngineConfigurer<CompareAssert>
Assertion methods for XMLs comparision.Simple Example
import static org.xmlunit.assertj.XmlAssert.assertThat; final String control = "<a><b attr=\"abc\"></b></a>"; final String test = "<a><b attr=\"xyz\"></b></a>"; assertThat(test).and(control).areIdentical(); assertThat(test).and(control).areNotSimilar();
- Since:
- XMLUnit 2.6.1
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
CompareAssert.ComparisonContext
-
Field Summary
Fields Modifier and Type Field Description private ComparisonController
customComparisonController
private DiffBuilder
diffBuilder
private static java.lang.String
EXPECTING_NOT_NULL
private ComparisonFormatter
formatter
private boolean
formatXml
private static DifferenceEvaluator
IgnoreNodeListSequence
-
Constructor Summary
Constructors Modifier Constructor Description private
CompareAssert(java.lang.Object actual, DiffBuilder diffBuilder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CompareAssert
areIdentical()
Check if actual and control XMLs are identical.CompareAssert
areNotIdentical()
Check if actual and control XMLs are not identical.CompareAssert
areNotSimilar()
Check if actual and control XMLs are not similar.CompareAssert
areSimilar()
Check if actual and control XMLs are similar.private void
compare(CompareAssert.ComparisonContext context)
(package private) static CompareAssert
create(java.lang.Object actual, java.lang.Object control, java.util.Map<java.lang.String,java.lang.String> prefix2Uri, javax.xml.parsers.DocumentBuilderFactory dbf)
CompareAssert
ignoreChildNodesOrder()
Equivalent forCompareAssert
ignoreComments()
CompareAssert
ignoreCommentsUsingXSLTVersion(java.lang.String xsltVersion)
CompareAssert
ignoreElementContentWhitespace()
CompareAssert
ignoreWhitespace()
CompareAssert
normalizeWhitespace()
CompareAssert
withAttributeFilter(Predicate<org.w3c.dom.Attr> attributeFilter)
Registers a filter for attributes.CompareAssert
withComparisonController(ComparisonController comparisonController)
Replace theComparisonControllers#Default
with your own ComparisonController.CompareAssert
withComparisonFormatter(ComparisonFormatter formatter)
Sets a non-default formatter for the differences found.CompareAssert
withComparisonListeners(ComparisonListener... comparisonListeners)
Registers listeners that are notified of each comparison.CompareAssert
withDifferenceEvaluator(DifferenceEvaluator differenceEvaluator)
Provide your own customDifferenceEvaluator
implementation.CompareAssert
withDifferenceListeners(ComparisonListener... comparisonListeners)
Registers listeners that are notified of each comparison with outcome other thanComparisonResult.EQUAL
.CompareAssert
withDocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory f)
CompareAssert
withNamespaceContext(java.util.Map<java.lang.String,java.lang.String> prefix2Uri)
Establish a namespace context that will be used inComparison.Detail#getXPath
.CompareAssert
withNodeFilter(Predicate<org.w3c.dom.Node> nodeFilter)
Registers a filter for nodes.CompareAssert
withNodeMatcher(NodeMatcher nodeMatcher)
Sets the strategy for selecting nodes to compare.-
Methods inherited from class org.xmlunit.assertj.CustomAbstractAssert
throwAssertionError
-
Methods inherited from class org.assertj.core.api.AbstractAssert
as, as, asInstanceOf, asList, asString, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, inBinary, inHexadecimal, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, setCustomRepresentation, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, withFailMessage, withRepresentation, withThreadDumpOnError
-
-
-
-
Field Detail
-
EXPECTING_NOT_NULL
private static final java.lang.String EXPECTING_NOT_NULL
- See Also:
- Constant Field Values
-
IgnoreNodeListSequence
private static DifferenceEvaluator IgnoreNodeListSequence
-
diffBuilder
private final DiffBuilder diffBuilder
-
customComparisonController
private ComparisonController customComparisonController
-
formatXml
private boolean formatXml
-
formatter
private ComparisonFormatter formatter
-
-
Constructor Detail
-
CompareAssert
private CompareAssert(java.lang.Object actual, DiffBuilder diffBuilder)
-
-
Method Detail
-
create
static CompareAssert create(java.lang.Object actual, java.lang.Object control, java.util.Map<java.lang.String,java.lang.String> prefix2Uri, javax.xml.parsers.DocumentBuilderFactory dbf)
-
withNodeMatcher
public CompareAssert withNodeMatcher(NodeMatcher nodeMatcher)
Sets the strategy for selecting nodes to compare.Example with
DefaultNodeMatcher
:.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))
- Specified by:
withNodeMatcher
in interfaceDifferenceEngineConfigurer<CompareAssert>
- See Also:
DiffBuilder.withNodeMatcher(NodeMatcher)
-
withDifferenceEvaluator
public CompareAssert withDifferenceEvaluator(DifferenceEvaluator differenceEvaluator)
Provide your own customDifferenceEvaluator
implementation.This overwrites the Default DifferenceEvaluator.
If you want use your custom DifferenceEvaluator in combination with the default or another DifferenceEvaluator you should use
DifferenceEvaluators.chain(DifferenceEvaluator...)
orDifferenceEvaluators.first(DifferenceEvaluator...)
to combine them:.withDifferenceEvaluator( DifferenceEvaluators.chain( DifferenceEvaluators.Default, new MyCustomDifferenceEvaluator())) ....
- Specified by:
withDifferenceEvaluator
in interfaceDifferenceEngineConfigurer<CompareAssert>
- See Also:
DiffBuilder.withDifferenceEvaluator(DifferenceEvaluator)
-
withComparisonController
public CompareAssert withComparisonController(ComparisonController comparisonController)
Replace theComparisonControllers#Default
with your own ComparisonController.Example use:
.withComparisonController(ComparisonControllers.StopWhenDifferent)
- Specified by:
withComparisonController
in interfaceDifferenceEngineConfigurer<CompareAssert>
- See Also:
DiffBuilder.withComparisonController(ComparisonController)
-
withComparisonListeners
public CompareAssert withComparisonListeners(ComparisonListener... comparisonListeners)
Registers listeners that are notified of each comparison.- Specified by:
withComparisonListeners
in interfaceDifferenceEngineConfigurer<CompareAssert>
- See Also:
DiffBuilder.withComparisonListeners(ComparisonListener...)
-
withDifferenceListeners
public CompareAssert withDifferenceListeners(ComparisonListener... comparisonListeners)
Registers listeners that are notified of each comparison with outcome other thanComparisonResult.EQUAL
.- Specified by:
withDifferenceListeners
in interfaceDifferenceEngineConfigurer<CompareAssert>
- See Also:
DiffBuilder.withDifferenceListeners(ComparisonListener...)
-
withNamespaceContext
public CompareAssert withNamespaceContext(java.util.Map<java.lang.String,java.lang.String> prefix2Uri)
Establish a namespace context that will be used inComparison.Detail#getXPath
.Without a namespace context (or with an empty context) the XPath expressions will only use local names for elements and attributes.
- Specified by:
withNamespaceContext
in interfaceDifferenceEngineConfigurer<CompareAssert>
- Parameters:
prefix2Uri
- mapping between prefix and namespace URI- See Also:
DiffBuilder.withNamespaceContext(Map)
-
withAttributeFilter
public CompareAssert withAttributeFilter(Predicate<org.w3c.dom.Attr> attributeFilter)
Registers a filter for attributes.Only attributes for which the predicate returns true are part of the comparison. By default all attributes are considered.
The "special" namespace, namespace-location and schema-instance-type attributes can not be ignored this way. If you want to suppress comparison of them you'll need to implement
DifferenceEvaluator
.- Specified by:
withAttributeFilter
in interfaceDifferenceEngineConfigurer<CompareAssert>
- See Also:
DiffBuilder.withAttributeFilter(Predicate)
-
withNodeFilter
public CompareAssert withNodeFilter(Predicate<org.w3c.dom.Node> nodeFilter)
Registers a filter for nodes.Only nodes for which the predicate returns true are part of the comparison. By default nodes that are not document types are considered.
- Specified by:
withNodeFilter
in interfaceDifferenceEngineConfigurer<CompareAssert>
- See Also:
DiffBuilder.withNodeFilter(Predicate)
-
withComparisonFormatter
public CompareAssert withComparisonFormatter(ComparisonFormatter formatter)
Sets a non-default formatter for the differences found.- Specified by:
withComparisonFormatter
in interfaceDifferenceEngineConfigurer<CompareAssert>
- See Also:
DiffBuilder.withComparisonFormatter(ComparisonFormatter)
-
withDocumentBuilderFactory
public CompareAssert withDocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory f)
-
ignoreWhitespace
public CompareAssert ignoreWhitespace()
- See Also:
DiffBuilder.ignoreWhitespace()
-
normalizeWhitespace
public CompareAssert normalizeWhitespace()
- See Also:
DiffBuilder.normalizeWhitespace()
-
ignoreElementContentWhitespace
public CompareAssert ignoreElementContentWhitespace()
-
ignoreComments
public CompareAssert ignoreComments()
- See Also:
DiffBuilder.ignoreComments()
-
ignoreCommentsUsingXSLTVersion
public CompareAssert ignoreCommentsUsingXSLTVersion(java.lang.String xsltVersion)
-
ignoreChildNodesOrder
public CompareAssert ignoreChildNodesOrder()
Equivalent for.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)) .withDifferenceEvaluator( chain( Default, DifferenceEvaluators.downgradeDifferencesToEqual(ComparisonType.CHILD_NODELIST_SEQUENCE)));
- See Also:
DiffBuilder.withNodeMatcher(NodeMatcher)
-
areIdentical
public CompareAssert areIdentical()
Check if actual and control XMLs are identical. If custom comparison controller wasn't defined thenComparisonControllers.StopWhenSimilar
is used.- Throws:
java.lang.AssertionError
- if the test value is invalidjava.lang.AssertionError
- if the control value is invalid- See Also:
DiffBuilder.checkForIdentical()
-
areNotIdentical
public CompareAssert areNotIdentical()
Check if actual and control XMLs are not identical. If custom comparison controller wasn't defined thenComparisonControllers.StopWhenSimilar
is used.- Throws:
java.lang.AssertionError
- if the test value is invalidjava.lang.AssertionError
- if the control value is invalid- See Also:
DiffBuilder.checkForSimilar()
-
areSimilar
public CompareAssert areSimilar()
Check if actual and control XMLs are similar. If custom comparison controller wasn't defined thenComparisonControllers.StopWhenDifferent
is used.- Throws:
java.lang.AssertionError
- if the test value is invalidjava.lang.AssertionError
- if the control value is invalid- See Also:
DiffBuilder.checkForSimilar()
-
areNotSimilar
public CompareAssert areNotSimilar()
Check if actual and control XMLs are not similar. If custom comparison controller wasn't defined thenComparisonControllers.StopWhenDifferent
is used.- Throws:
java.lang.AssertionError
- if the test value is invalidjava.lang.AssertionError
- if the control value is invalid- See Also:
DiffBuilder.checkForSimilar()
-
compare
private void compare(CompareAssert.ComparisonContext context)
-
-