Package org.custommonkey.xmlunit
Class DifferenceEngine
- java.lang.Object
-
- org.custommonkey.xmlunit.DifferenceEngine
-
- All Implemented Interfaces:
DifferenceConstants,DifferenceEngineContract
public class DifferenceEngine extends Object implements DifferenceConstants, DifferenceEngineContract
Class that has responsibility for comparing Nodes and notifying a DifferenceListener of any differences or dissimilarities that are found. Knows how to compare namespaces and nested child nodes, but currently only compares nodes of type ELEMENT_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_TYPE_NODE, PROCESSING_INSTRUCTION_NODE and TEXT_NODE. Nodes of other types (eg ENTITY_NODE) will be skipped.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classDifferenceEngine.DifferenceFoundExceptionMarker exception thrown by the protected compare() method and passed upwards through the call stack to the public compare() method.
-
Field Summary
-
Fields inherited from interface org.custommonkey.xmlunit.DifferenceConstants
ATTR_NAME_NOT_FOUND, ATTR_NAME_NOT_FOUND_ID, ATTR_SEQUENCE, ATTR_SEQUENCE_ID, ATTR_VALUE, ATTR_VALUE_EXPLICITLY_SPECIFIED, ATTR_VALUE_EXPLICITLY_SPECIFIED_ID, ATTR_VALUE_ID, CDATA_VALUE, CDATA_VALUE_ID, CHILD_NODE_NOT_FOUND, CHILD_NODE_NOT_FOUND_ID, CHILD_NODELIST_LENGTH, CHILD_NODELIST_LENGTH_ID, CHILD_NODELIST_SEQUENCE, CHILD_NODELIST_SEQUENCE_ID, COMMENT_VALUE, COMMENT_VALUE_ID, DOCTYPE_NAME, DOCTYPE_NAME_ID, DOCTYPE_PUBLIC_ID, DOCTYPE_PUBLIC_ID_ID, DOCTYPE_SYSTEM_ID, DOCTYPE_SYSTEM_ID_ID, ELEMENT_NUM_ATTRIBUTES, ELEMENT_NUM_ATTRIBUTES_ID, ELEMENT_TAG_NAME, ELEMENT_TAG_NAME_ID, HAS_CHILD_NODES, HAS_CHILD_NODES_ID, HAS_DOCTYPE_DECLARATION, HAS_DOCTYPE_DECLARATION_ID, NAMESPACE_PREFIX, NAMESPACE_PREFIX_ID, NAMESPACE_URI, NAMESPACE_URI_ID, NO_NAMESPACE_SCHEMA_LOCATION, NO_NAMESPACE_SCHEMA_LOCATION_ID, NODE_TYPE, NODE_TYPE_ID, PROCESSING_INSTRUCTION_DATA, PROCESSING_INSTRUCTION_DATA_ID, PROCESSING_INSTRUCTION_TARGET, PROCESSING_INSTRUCTION_TARGET_ID, SCHEMA_LOCATION, SCHEMA_LOCATION_ID, TEXT_VALUE, TEXT_VALUE_ID
-
-
Constructor Summary
Constructors Constructor Description DifferenceEngine(ComparisonController controller)Simple constructor that uses no MatchTracker at all.DifferenceEngine(ComparisonController controller, MatchTracker matchTracker)Simple constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcompare(Object expected, Object actual, Node control, Node test, DifferenceListener listener, Difference difference)If the expected and actual values are unequal then inform the listener of a difference and throw a DifferenceFoundException.protected voidcompare(Object expected, Object actual, Node control, Node test, DifferenceListener listener, Difference difference, XpathNodeTracker controlLoc, XpathNodeTracker testLoc)If the expected and actual values are unequal then inform the listener of a difference and throw a DifferenceFoundException.voidcompare(Node control, Node test, DifferenceListener listener, ElementQualifier elementQualifier)Entry point for Node comparison testing.protected voidcompareAttribute(Attr control, Attr test, DifferenceListener listener)Compare two attributesprotected voidcompareCDataSection(CDATASection control, CDATASection test, DifferenceListener listener)Compare two CDATA sections - unused, kept for backwards compatibilityprotected voidcompareComment(Comment control, Comment test, DifferenceListener listener)Compare two commentsprotected voidcompareDocument(Document control, Document test, DifferenceListener listener, ElementQualifier elementQualifier)Compare two Documents for doctype and then element differencesprotected voidcompareDocumentType(DocumentType control, DocumentType test, DifferenceListener listener)Compare two DocumentType nodesprotected voidcompareElement(Element control, Element test, DifferenceListener listener)Compare 2 elements and their attributesprotected voidcompareHasChildNodes(Node control, Node test, DifferenceListener listener)Compare the number of children, and if the same, compare the actual children via their NodeLists.protected voidcompareNode(Node control, Node test, DifferenceListener listener, ElementQualifier elementQualifier)First point of call: if nodes are comparable it compares node values then recurses to compare node children.protected booleancompareNodeBasics(Node control, Node test, DifferenceListener listener)Compares node type and node namespace characteristics: basically determines if nodes are comparable furtherprotected voidcompareNodeChildren(Node control, Node test, DifferenceListener listener, ElementQualifier elementQualifier)Compare the number of children, and if the same, compare the actual children via their NodeLists.protected voidcompareNodeList(List<Node> controlChildren, List<Node> testChildren, int numNodes, DifferenceListener listener, ElementQualifier elementQualifier)Compare the contents of two node list one by one, assuming that order of children is NOT important: matching begins at same position in test list as control list.protected voidcompareProcessingInstruction(ProcessingInstruction control, ProcessingInstruction test, DifferenceListener listener)Compare two processing instructionsprotected voidcompareRecognizedXMLSchemaInstanceAttribute(Attr control, Attr test, DifferenceListener listener)Compare two attributesprotected voidcompareText(CharacterData control, CharacterData test, DifferenceListener listener)Compare textprotected voidcompareText(Text control, Text test, DifferenceListener listener)Compare text - unused, kept for backwards compatibilityvoidsetMatchTracker(MatchTracker matchTracker)
-
-
-
Constructor Detail
-
DifferenceEngine
public DifferenceEngine(ComparisonController controller)
Simple constructor that uses no MatchTracker at all.- Parameters:
controller- the instance used to determine whether a Difference detected by this class should halt further comparison or not- See Also:
ComparisonController.haltComparison(Difference)
-
DifferenceEngine
public DifferenceEngine(ComparisonController controller, MatchTracker matchTracker)
Simple constructor- Parameters:
controller- the instance used to determine whether a Difference detected by this class should halt further comparison or notmatchTracker- the instance that is notified on each successful match. May be null.- See Also:
ComparisonController.haltComparison(Difference),MatchTracker.matchFound(Difference)
-
-
Method Detail
-
setMatchTracker
public void setMatchTracker(MatchTracker matchTracker)
- Specified by:
setMatchTrackerin interfaceDifferenceEngineContract- Parameters:
matchTracker- the instance that is notified on each successful match. May be null.
-
compare
public void compare(Node control, Node test, DifferenceListener listener, ElementQualifier elementQualifier)
Entry point for Node comparison testing.- Specified by:
comparein interfaceDifferenceEngineContract- Parameters:
control- Control XML to comparetest- Test XML to comparelistener- Notified of anydifferencesdetected during node comparison testingelementQualifier- Used to determine which elements qualify for comparison e.g. when a node has repeated child elements that may occur in any sequence and that sequence is not considered important.
-
compareNode
protected void compareNode(Node control, Node test, DifferenceListener listener, ElementQualifier elementQualifier) throws DifferenceEngine.DifferenceFoundException
First point of call: if nodes are comparable it compares node values then recurses to compare node children.- Parameters:
control- control nodetest- test nodelistener- difference listenerelementQualifier- element qualifier- Throws:
DifferenceEngine.DifferenceFoundException- if a difference has been found
-
compareDocument
protected void compareDocument(Document control, Document test, DifferenceListener listener, ElementQualifier elementQualifier) throws DifferenceEngine.DifferenceFoundException
Compare two Documents for doctype and then element differences- Parameters:
control- control documenttest- test documentlistener- difference listenerelementQualifier- element qualifier- Throws:
DifferenceEngine.DifferenceFoundException- if a difference has been found
-
compareNodeBasics
protected boolean compareNodeBasics(Node control, Node test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException
Compares node type and node namespace characteristics: basically determines if nodes are comparable further- Parameters:
control- control nodetest- test nodelistener- difference listener- Returns:
- true if the nodes are comparable further, false otherwise
- Throws:
DifferenceEngine.DifferenceFoundException- if a difference has been found
-
compareHasChildNodes
protected void compareHasChildNodes(Node control, Node test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException
Compare the number of children, and if the same, compare the actual children via their NodeLists.- Parameters:
control- control nodetest- test nodelistener- difference listener- Throws:
DifferenceEngine.DifferenceFoundException- if a difference has been found
-
compareNodeChildren
protected void compareNodeChildren(Node control, Node test, DifferenceListener listener, ElementQualifier elementQualifier) throws DifferenceEngine.DifferenceFoundException
Compare the number of children, and if the same, compare the actual children via their NodeLists.- Parameters:
control- control nodetest- test nodelistener- difference listenerelementQualifier- element qualifier- Throws:
DifferenceEngine.DifferenceFoundException- if a difference has been found
-
compareNodeList
protected void compareNodeList(List<Node> controlChildren, List<Node> testChildren, int numNodes, DifferenceListener listener, ElementQualifier elementQualifier) throws DifferenceEngine.DifferenceFoundException
Compare the contents of two node list one by one, assuming that order of children is NOT important: matching begins at same position in test list as control list.- Parameters:
controlChildren- children of the control nodetestChildren- children of the test nodenumNodes- convenience parameter because the calling method should know the value alreadylistener- difference listenerelementQualifier- used to determine which of the child elements in the test NodeList should be compared to the current child element in the control NodeList.- Throws:
DifferenceEngine.DifferenceFoundException- if a difference has been found
-
compareElement
protected void compareElement(Element control, Element test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException
Compare 2 elements and their attributes- Parameters:
control- elementtest- test elementlistener- difference listener- Throws:
DifferenceEngine.DifferenceFoundException- if a difference has been found
-
compareRecognizedXMLSchemaInstanceAttribute
protected void compareRecognizedXMLSchemaInstanceAttribute(Attr control, Attr test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException
Compare two attributes- Parameters:
control- control attributetest- test attributelistener- difference listener- Throws:
DifferenceEngine.DifferenceFoundException- if a difference has been found
-
compareAttribute
protected void compareAttribute(Attr control, Attr test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException
Compare two attributes- Parameters:
control- control attributetest- test attributelistener- difference listener- Throws:
DifferenceEngine.DifferenceFoundException- if a difference has been found
-
compareCDataSection
protected void compareCDataSection(CDATASection control, CDATASection test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException
Compare two CDATA sections - unused, kept for backwards compatibility- Parameters:
control- control cdatatest- test cdatalistener- difference listener- Throws:
DifferenceEngine.DifferenceFoundException- if a difference has been found
-
compareComment
protected void compareComment(Comment control, Comment test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException
Compare two comments- Parameters:
control- control commenttest- test commentlistener- difference listener- Throws:
DifferenceEngine.DifferenceFoundException- if a difference has been found
-
compareDocumentType
protected void compareDocumentType(DocumentType control, DocumentType test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException
Compare two DocumentType nodes- Parameters:
control- control document typetest- test document typelistener- difference listener- Throws:
DifferenceEngine.DifferenceFoundException- if a difference has been found
-
compareProcessingInstruction
protected void compareProcessingInstruction(ProcessingInstruction control, ProcessingInstruction test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException
Compare two processing instructions- Parameters:
control- control processing instructiontest- test processing instructionlistener- difference listener- Throws:
DifferenceEngine.DifferenceFoundException- if a difference has been found
-
compareText
protected void compareText(Text control, Text test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException
Compare text - unused, kept for backwards compatibility- Parameters:
control- control texttest- test textlistener- difference listener- Throws:
DifferenceEngine.DifferenceFoundException- if a difference has been found
-
compareText
protected void compareText(CharacterData control, CharacterData test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException
Compare text- Parameters:
control- control texttest- test textlistener- difference listener- Throws:
DifferenceEngine.DifferenceFoundException- if a difference has been found
-
compare
protected void compare(Object expected, Object actual, Node control, Node test, DifferenceListener listener, Difference difference) throws DifferenceEngine.DifferenceFoundException
If the expected and actual values are unequal then inform the listener of a difference and throw a DifferenceFoundException.- Parameters:
expected- expected valueactual- valuecontrol- control nodetest- test nodelistener- difference listenerdifference- difference type- Throws:
DifferenceEngine.DifferenceFoundException- if a difference has been found
-
compare
protected void compare(Object expected, Object actual, Node control, Node test, DifferenceListener listener, Difference difference, XpathNodeTracker controlLoc, XpathNodeTracker testLoc) throws DifferenceEngine.DifferenceFoundException
If the expected and actual values are unequal then inform the listener of a difference and throw a DifferenceFoundException.- Parameters:
expected- expected valueactual- valuecontrol- control nodecontrolLoc- XPath location of control nodetest- test nodetestLoc- XPath location of test nodelistener- difference listenerdifference- difference type- Throws:
DifferenceEngine.DifferenceFoundException- if a difference has been found
-
-