Class CompareAssert
- java.lang.Object
-
- org.assertj.core.api.AbstractAssert<SELF,ACTUAL>
-
- org.xmlunit.assertj3.CustomAbstractAssert<CompareAssert,java.lang.Object>
-
- org.xmlunit.assertj3.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 comparison.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\"NodeAssertFactory></b></a>"; assertThat(test).and(control).areIdentical(); assertThat(test).and(control).areNotSimilar();
- Since:
- XMLUnit 2.8.1
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classCompareAssert.ComparisonContext
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringCOMPARISON_FAILURE_PATTERNprivate ComparisonControllercustomComparisonControllerprivate DiffBuilderdiffBuilderprivate static java.lang.StringEXPECTING_NOT_NULLprivate ComparisonFormatterformatterprivate booleanformatXmlprivate static DifferenceEvaluatorIgnoreNodeListSequence
-
Constructor Summary
Constructors Modifier Constructor Description privateCompareAssert(java.lang.Object actual, DiffBuilder diffBuilder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CompareAssertareIdentical()Check if actual and control XMLs are identical.CompareAssertareNotIdentical()Check if actual and control XMLs are not identical.CompareAssertareNotSimilar()Check if actual and control XMLs are not similar.CompareAssertareSimilar()Check if actual and control XMLs are similar.private voidcompare(CompareAssert.ComparisonContext context)(package private) static CompareAssertcreate(java.lang.Object actual, java.lang.Object control, XmlAssertConfig config)private voidfailComparison(java.lang.String type, java.lang.String controlSystemId, java.lang.String testSystemId, Comparison difference, ComparisonFormatter formatter, boolean formatXml)CompareAssertignoreChildNodesOrder()Equivalent forCompareAssertignoreComments()Will remove all comment-Tags "<!-- Comment -->" from test- and control-XML before comparing.CompareAssertignoreCommentsUsingXSLTVersion(java.lang.String xsltVersion)Will remove all comment-Tags "<!-- Comment -->" from test- and control-XML before comparing.CompareAssertignoreElementContentWhitespace()Ignore element content whitespace by removing all text nodes solely consisting of whitespace.CompareAssertignoreWhitespace()Ignore whitespace by removing all empty text nodes and trimming the non-empty ones.CompareAssertnormalizeWhitespace()Normalize Text-Elements by removing all empty text nodes and normalizing the non-empty ones.CompareAssertwithAttributeFilter(Predicate<org.w3c.dom.Attr> attributeFilter)Registers a filter for attributes.CompareAssertwithComparisonController(ComparisonController comparisonController)Replace theComparisonControllers.Defaultwith your own ComparisonController.CompareAssertwithComparisonFormatter(ComparisonFormatter formatter)Sets a non-default formatter for the differences found.CompareAssertwithComparisonListeners(ComparisonListener... comparisonListeners)Registers listeners that are notified of each comparison.CompareAssertwithDifferenceEvaluator(DifferenceEvaluator differenceEvaluator)Provide your own customDifferenceEvaluatorimplementation.CompareAssertwithDifferenceListeners(ComparisonListener... comparisonListeners)Registers listeners that are notified of each comparison with outcome other thanComparisonResult.EQUAL.CompareAssertwithDocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory f)Sets theDocumentBuilderFactoryto use when creating aDocumentfrom theSources to compare.CompareAssertwithNamespaceContext(java.util.Map<java.lang.String,java.lang.String> prefix2Uri)Establish a namespace context that will be used inComparison.Detail#getXPath.CompareAssertwithNodeFilter(Predicate<org.w3c.dom.Node> nodeFilter)Registers a filter for nodes.CompareAssertwithNodeMatcher(NodeMatcher nodeMatcher)Sets the strategy for selecting nodes to compare.-
Methods inherited from class org.xmlunit.assertj3.CustomAbstractAssert
isElementOfCustomAssert
-
Methods inherited from class org.assertj.core.api.AbstractAssert
actual, areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, doesNotMatch, doesNotMatch, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, 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, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, usingEquals, usingEquals, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparison, withFailMessage, 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 final DifferenceEvaluator IgnoreNodeListSequence
-
diffBuilder
private final DiffBuilder diffBuilder
-
customComparisonController
private ComparisonController customComparisonController
-
formatXml
private boolean formatXml
-
formatter
private ComparisonFormatter formatter
-
COMPARISON_FAILURE_PATTERN
private static final java.lang.String COMPARISON_FAILURE_PATTERN
- See Also:
- Constant Field Values
-
-
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, XmlAssertConfig config)
-
withNodeMatcher
public CompareAssert withNodeMatcher(NodeMatcher nodeMatcher)
Sets the strategy for selecting nodes to compare.Example with
DefaultNodeMatcher:.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))
This overwrites any
NodeMatcherset via earlier invocations ofwithNodeMatcher.- Specified by:
withNodeMatcherin interfaceDifferenceEngineConfigurer<CompareAssert>- Parameters:
nodeMatcher- the NodeMatcher to use- Returns:
- this
- See Also:
DiffBuilder.withNodeMatcher(NodeMatcher)
-
withDifferenceEvaluator
public CompareAssert withDifferenceEvaluator(DifferenceEvaluator differenceEvaluator)
Provide your own customDifferenceEvaluatorimplementation.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())) ....This overwrites any
DifferenceEvaluatorset via earlier invocations ofwithDifferenceEvaluator.- Specified by:
withDifferenceEvaluatorin interfaceDifferenceEngineConfigurer<CompareAssert>- Parameters:
differenceEvaluator- the DifferenceEvaluator to use- Returns:
- this
- See Also:
DiffBuilder.withDifferenceEvaluator(DifferenceEvaluator)
-
withComparisonController
public CompareAssert withComparisonController(ComparisonController comparisonController)
Replace theComparisonControllers.Defaultwith your own ComparisonController.Example use:
.withComparisonController(ComparisonControllers.StopWhenDifferent)This overwrites any
ComparisonControllerset via earlier invocations ofwithComparisonController.- Specified by:
withComparisonControllerin interfaceDifferenceEngineConfigurer<CompareAssert>- Parameters:
comparisonController- ComparisonController to use- Returns:
- this
- See Also:
DiffBuilder.withComparisonController(ComparisonController)
-
withComparisonListeners
public CompareAssert withComparisonListeners(ComparisonListener... comparisonListeners)
Registers listeners that are notified of each comparison.- Specified by:
withComparisonListenersin interfaceDifferenceEngineConfigurer<CompareAssert>- Parameters:
comparisonListeners- ComparisonListeners to use- Returns:
- this
- See Also:
DiffBuilder.withComparisonListeners(ComparisonListener...)
-
withDifferenceListeners
public CompareAssert withDifferenceListeners(ComparisonListener... comparisonListeners)
Registers listeners that are notified of each comparison with outcome other thanComparisonResult.EQUAL.This overwrites any
ComparisonListeners set via earlier invocations ofwithDifferenceListeners.- Specified by:
withDifferenceListenersin interfaceDifferenceEngineConfigurer<CompareAssert>- Parameters:
comparisonListeners- ComparisonListeners to use- Returns:
- this
- 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.
This overwrites any
Mapset via earlier invocations ofwithNamespaceContext.- Specified by:
withNamespaceContextin interfaceDifferenceEngineConfigurer<CompareAssert>- Parameters:
prefix2Uri- mapping between prefix and namespace URI- Returns:
- this
- 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.This overwrites any
Predicateset via earlier invocations ofwithAttributeFilter.- Specified by:
withAttributeFilterin interfaceDifferenceEngineConfigurer<CompareAssert>- Parameters:
attributeFilter- attribute filter to use- Returns:
- this
- 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.
This overwrites any
Predicateset via earlier invocations ofwithNodeFilter.- Specified by:
withNodeFilterin interfaceDifferenceEngineConfigurer<CompareAssert>- Parameters:
nodeFilter- node filter to use- Returns:
- this
- See Also:
DiffBuilder.withNodeFilter(Predicate)
-
withComparisonFormatter
public CompareAssert withComparisonFormatter(ComparisonFormatter formatter)
Sets a non-default formatter for the differences found.This overwrites any
ComparisonFormatterset via earlier invocations ofwithComparisonFormatter.- Specified by:
withComparisonFormatterin interfaceDifferenceEngineConfigurer<CompareAssert>- Parameters:
formatter- formatter to use- Returns:
- this
- See Also:
DiffBuilder.withComparisonFormatter(ComparisonFormatter)
-
withDocumentBuilderFactory
public CompareAssert withDocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory f)
Sets theDocumentBuilderFactoryto use when creating aDocumentfrom theSources to compare.- Parameters:
f- the DocumentBuilderFactory to use- Returns:
- this
- See Also:
DiffBuilder.withDocumentBuilderFactory(DocumentBuilderFactory)
-
ignoreWhitespace
public CompareAssert ignoreWhitespace()
Ignore whitespace by removing all empty text nodes and trimming the non-empty ones.- Returns:
- this
- See Also:
DiffBuilder.ignoreWhitespace()
-
normalizeWhitespace
public CompareAssert normalizeWhitespace()
Normalize Text-Elements by removing all empty text nodes and normalizing the non-empty ones.- Returns:
- this
- See Also:
DiffBuilder.normalizeWhitespace()
-
ignoreElementContentWhitespace
public CompareAssert ignoreElementContentWhitespace()
Ignore element content whitespace by removing all text nodes solely consisting of whitespace.- Returns:
- this
- See Also:
DiffBuilder.ignoreElementContentWhitespace()
-
ignoreComments
public CompareAssert ignoreComments()
Will remove all comment-Tags "<!-- Comment -->" from test- and control-XML before comparing.- Returns:
- this
- See Also:
DiffBuilder.ignoreComments()
-
ignoreCommentsUsingXSLTVersion
public CompareAssert ignoreCommentsUsingXSLTVersion(java.lang.String xsltVersion)
Will remove all comment-Tags "<!-- Comment -->" from test- and control-XML before comparing.- Parameters:
xsltVersion- use this version for the stylesheet- Returns:
- this
- See Also:
DiffBuilder.ignoreCommentsUsingXSLTVersion(String)
-
ignoreChildNodesOrder
public CompareAssert ignoreChildNodesOrder()
Equivalent for.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)) .withDifferenceEvaluator( chain( Default, DifferenceEvaluators.downgradeDifferencesToEqual(ComparisonType.CHILD_NODELIST_SEQUENCE)));- Returns:
- this
- 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.StopWhenSimilaris used.- Returns:
- this
- 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.StopWhenSimilaris used.- Returns:
- this
- 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.StopWhenDifferentis used.- Returns:
- this
- 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.StopWhenDifferentis used.- Returns:
- this
- 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)
-
failComparison
private void failComparison(java.lang.String type, java.lang.String controlSystemId, java.lang.String testSystemId, Comparison difference, ComparisonFormatter formatter, boolean formatXml)
-
-