org.custommonkey.xmlunit

Class DifferenceEngine

public class DifferenceEngine extends Object implements DifferenceConstants

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.
Examples and more at xmlunit. sourceforge.net

See Also: differenceFound

Nested Class Summary
protected static classDifferenceEngine.DifferenceFoundException
Marker exception thrown by the protected compare() method and passed upwards through the call stack to the public compare() method.
Constructor Summary
DifferenceEngine(ComparisonController controller)
Simple constructor
Method Summary
voidcompare(Node control, Node test, DifferenceListener listener, ElementQualifier elementQualifier)
Entry point for Node comparison testing.
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 voidcompareAttribute(Attr control, Attr test, DifferenceListener listener)
Compare two attributes
protected voidcompareCDataSection(CDATASection control, CDATASection test, DifferenceListener listener)
Compare two CDATA sections
protected voidcompareComment(Comment control, Comment test, DifferenceListener listener)
Compare two comments
protected voidcompareDocument(Document control, Document test, DifferenceListener listener, ElementQualifier elementQualifier)
Compare two Documents for doctype and then element differences
protected voidcompareDocumentType(DocumentType control, DocumentType test, DifferenceListener listener)
Compare two DocumentType nodes
protected voidcompareElement(Element control, Element test, DifferenceListener listener)
Compare 2 elements and their attributes
protected 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 further
protected 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(NodeList control, NodeList test, 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 instructions
protected voidcompareText(Text control, Text test, DifferenceListener listener)
Compare text

Constructor Detail

DifferenceEngine

public DifferenceEngine(ComparisonController controller)
Simple constructor

Parameters: controller the instance used to determine whether a Difference detected by this class should halt further comparison or not

See Also: haltComparison

Method Detail

compare

public void compare(Node control, Node test, DifferenceListener listener, ElementQualifier elementQualifier)
Entry point for Node comparison testing.

Parameters: control Control XML to compare test Test XML to compare listener Notified of any differences detected during node comparison testing elementQualifier 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.

compare

protected void compare(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.

Parameters: expected actual control test listener differenceType

Throws: DifferenceFoundException

compareAttribute

protected void compareAttribute(Attr control, Attr test, DifferenceListener listener)
Compare two attributes

Parameters: control test listener

Throws: DifferenceFoundException

compareCDataSection

protected void compareCDataSection(CDATASection control, CDATASection test, DifferenceListener listener)
Compare two CDATA sections

Parameters: control test listener

Throws: DifferenceFoundException

compareComment

protected void compareComment(Comment control, Comment test, DifferenceListener listener)
Compare two comments

Parameters: control test listener

Throws: DifferenceFoundException

compareDocument

protected void compareDocument(Document control, Document test, DifferenceListener listener, ElementQualifier elementQualifier)
Compare two Documents for doctype and then element differences

Parameters: control test listener elementQualifier

Throws: DifferenceFoundException

compareDocumentType

protected void compareDocumentType(DocumentType control, DocumentType test, DifferenceListener listener)
Compare two DocumentType nodes

Parameters: control test listener

Throws: DifferenceFoundException

compareElement

protected void compareElement(Element control, Element test, DifferenceListener listener)
Compare 2 elements and their attributes

Parameters: control test listener

Throws: DifferenceFoundException

compareHasChildNodes

protected void compareHasChildNodes(Node control, Node test, DifferenceListener listener)
Compare the number of children, and if the same, compare the actual children via their NodeLists.

Parameters: control test listener

Throws: DifferenceFoundException

compareNode

protected void compareNode(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.

Parameters: control test listener elementQualifier

Throws: DifferenceFoundException

compareNodeBasics

protected boolean compareNodeBasics(Node control, Node test, DifferenceListener listener)
Compares node type and node namespace characteristics: basically determines if nodes are comparable further

Parameters: control test listener

Returns: true if the nodes are comparable further, false otherwise

Throws: DifferenceFoundException

compareNodeChildren

protected void compareNodeChildren(Node control, Node test, DifferenceListener listener, ElementQualifier elementQualifier)
Compare the number of children, and if the same, compare the actual children via their NodeLists.

Parameters: control test listener elementQualifier

Throws: DifferenceFoundException

compareNodeList

protected void compareNodeList(NodeList control, NodeList test, 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.

Parameters: control test numNodes convenience parameter because the calling method should know the value already listener elementQualifier 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: DifferenceFoundException

compareProcessingInstruction

protected void compareProcessingInstruction(ProcessingInstruction control, ProcessingInstruction test, DifferenceListener listener)
Compare two processing instructions

Parameters: control test listener

Throws: DifferenceFoundException

compareText

protected void compareText(Text control, Text test, DifferenceListener listener)
Compare text

Parameters: control test listener

Throws: DifferenceFoundException