/** * If the expected and actual values are unequal then inform the listener of * a difference and throw a DifferenceFoundException. * @param expected * @param actual * @param control * @param test * @param listener * @param difference * @throws DifferenceFoundException */ protected void compare(Object expected, Object actual, Node control, Node test, DifferenceListener listener, Difference difference) throws DifferenceFoundException { compare(expected, actual, control, test, listener, difference, controlTracker, testTracker); }
/** * Compare 2 elements and their attributes * @param control * @param test * @param listener * @throws DifferenceFoundException */ protected void compareElement(Element control, Element test, DifferenceListener listener) throws DifferenceFoundException { compare(getUnNamespacedNodeName(control), getUnNamespacedNodeName(test), control, test, listener, ELEMENT_TAG_NAME); NamedNodeMap controlAttr = control.getAttributes(); Integer controlNonXmlnsAttrLength = getNonSpecialAttrLength(controlAttr); NamedNodeMap testAttr = test.getAttributes(); Integer testNonXmlnsAttrLength = getNonSpecialAttrLength(testAttr); compare(controlNonXmlnsAttrLength, testNonXmlnsAttrLength, control, test, listener, ELEMENT_NUM_ATTRIBUTES); compareElementAttributes(control, test, controlAttr, testAttr, listener); }
/** * Compare two Documents for doctype and then element differences * @param control * @param test * @param listener * @param elementQualifier * @throws DifferenceFoundException */ protected void compareDocument(Document control, Document test, DifferenceListener listener, ElementQualifier elementQualifier) throws DifferenceFoundException { DocumentType controlDoctype = control.getDoctype(); DocumentType testDoctype = test.getDoctype(); compare(getNullOrNotNull(controlDoctype), getNullOrNotNull(testDoctype), controlDoctype, testDoctype, listener, HAS_DOCTYPE_DECLARATION); if (controlDoctype!=null && testDoctype!=null) { compareNode(controlDoctype, testDoctype, listener, elementQualifier); } }
/** * If the expected and actual values are unequal then inform the listener of * a difference and throw a DifferenceFoundException. * @param expected * @param actual * @param control * @param test * @param listener * @param differenceType * @throws DifferenceFoundException */ protected void compare(Object expected, Object actual, Node control, Node test, DifferenceListener listener, Difference difference) throws DifferenceFoundException { compare(expected, actual, control, test, listener, difference, controlTracker, testTracker); }
/** * Compare 2 elements and their attributes * @param control * @param test * @param listener * @throws DifferenceFoundException */ protected void compareElement(Element control, Element test, DifferenceListener listener) throws DifferenceFoundException { compare(getUnNamespacedNodeName(control), getUnNamespacedNodeName(test), control, test, listener, ELEMENT_TAG_NAME); NamedNodeMap controlAttr = control.getAttributes(); Integer controlNonXmlnsAttrLength = getNonSpecialAttrLength(controlAttr); NamedNodeMap testAttr = test.getAttributes(); Integer testNonXmlnsAttrLength = getNonSpecialAttrLength(testAttr); compare(controlNonXmlnsAttrLength, testNonXmlnsAttrLength, control, test, listener, ELEMENT_NUM_ATTRIBUTES); compareElementAttributes(control, test, controlAttr, testAttr, listener); }
/** * Compare two Documents for doctype and then element differences * @param control * @param test * @param listener * @param elementQualifier * @throws DifferenceFoundException */ protected void compareDocument(Document control, Document test, DifferenceListener listener, ElementQualifier elementQualifier) throws DifferenceFoundException { DocumentType controlDoctype = control.getDoctype(); DocumentType testDoctype = test.getDoctype(); compare(getNullOrNotNull(controlDoctype), getNullOrNotNull(testDoctype), controlDoctype, testDoctype, listener, HAS_DOCTYPE_DECLARATION); if (controlDoctype!=null && testDoctype!=null) { compareNode(controlDoctype, testDoctype, listener, elementQualifier); } }
/** * Top of the recursive comparison execution tree */ protected final void compare() { if (compared) { return; } getDifferenceEngine().compare(controlDoc, testDoc, this, elementQualifierDelegate); compared = true; }
/** * Compare two DocumentType nodes * @param control * @param test * @param listener * @throws DifferenceFoundException */ protected void compareDocumentType(DocumentType control, DocumentType test, DifferenceListener listener) throws DifferenceFoundException { compare(control.getName(), test.getName(), control, test, listener, DOCTYPE_NAME); compare(control.getPublicId(), test.getPublicId(), control, test, listener, DOCTYPE_PUBLIC_ID); compare(control.getSystemId(), test.getSystemId(), control, test, listener, DOCTYPE_SYSTEM_ID); }
/** * Compare two DocumentType nodes * @param control * @param test * @param listener * @throws DifferenceFoundException */ protected void compareDocumentType(DocumentType control, DocumentType test, DifferenceListener listener) throws DifferenceFoundException { compare(control.getName(), test.getName(), control, test, listener, DOCTYPE_NAME); compare(control.getPublicId(), test.getPublicId(), control, test, listener, DOCTYPE_PUBLIC_ID); compare(control.getSystemId(), test.getSystemId(), control, test, listener, DOCTYPE_SYSTEM_ID); }
private void missingNode(Node control, Node test, DifferenceListener listener) throws DifferenceFoundException { if (control != null) { controlTracker.visited(control); compare(control.getNodeName(), null, control, null, listener, CHILD_NODE_NOT_FOUND, controlTracker, null); } else { testTracker.visited(test); compare(null, test.getNodeName(), null, test, listener, CHILD_NODE_NOT_FOUND, null, testTracker); } }
/** * Compare two attributes * @param control * @param test * @param listener * @throws DifferenceFoundException */ protected void compareAttribute(Attr control, Attr test, DifferenceListener listener) throws DifferenceFoundException { controlTracker.visited(control); testTracker.visited(test); compare(control.getPrefix(), test.getPrefix(), control, test, listener, NAMESPACE_PREFIX); compare(control.getValue(), test.getValue(), control, test, listener, ATTR_VALUE); compare(control.getSpecified() ? Boolean.TRUE : Boolean.FALSE, test.getSpecified() ? Boolean.TRUE : Boolean.FALSE, control, test, listener, ATTR_VALUE_EXPLICITLY_SPECIFIED); }
/** * Compare two attributes * @param control * @param test * @param listener * @throws DifferenceFoundException */ protected void compareAttribute(Attr control, Attr test, DifferenceListener listener) throws DifferenceFoundException { controlTracker.visited(control); testTracker.visited(test); compare(control.getPrefix(), test.getPrefix(), control, test, listener, NAMESPACE_PREFIX); compare(control.getValue(), test.getValue(), control, test, listener, ATTR_VALUE); compare(control.getSpecified() ? Boolean.TRUE : Boolean.FALSE, test.getSpecified() ? Boolean.TRUE : Boolean.FALSE, control, test, listener, ATTR_VALUE_EXPLICITLY_SPECIFIED); }
private void missingNode(Node control, Node test, DifferenceListener listener) throws DifferenceFoundException { if (control != null) { controlTracker.visited(control); compare(getQName(control), null, control, null, listener, CHILD_NODE_NOT_FOUND, controlTracker, null); } else { testTracker.visited(test); compare(null, getQName(test), null, test, listener, CHILD_NODE_NOT_FOUND, null, testTracker); } }
/** * Character comparison method used by comments, text and CDATA sections * @param control * @param test * @param listener * @param differenceType * @throws DifferenceFoundException */ private void compareCharacterData(CharacterData control, CharacterData test, DifferenceListener listener, Difference difference) throws DifferenceFoundException { compare(control.getData(), test.getData(), control, test, listener, difference); }
/** * Character comparison method used by comments, text and CDATA sections * @param control * @param test * @param listener * @param difference * @throws DifferenceFoundException */ private void compareCharacterData(CharacterData control, CharacterData test, DifferenceListener listener, Difference difference) throws DifferenceFoundException { compare(control.getData(), test.getData(), control, test, listener, difference); }
/** * Compare two processing instructions * @param control * @param test * @param listener * @throws DifferenceFoundException */ protected void compareProcessingInstruction(ProcessingInstruction control, ProcessingInstruction test, DifferenceListener listener) throws DifferenceFoundException { compare(control.getTarget(), test.getTarget(), control, test, listener, PROCESSING_INSTRUCTION_TARGET); compare(control.getData(), test.getData(), control, test, listener, PROCESSING_INSTRUCTION_DATA); }
/** * Compare the number of children, and if the same, compare the actual * children via their NodeLists. * @param control * @param test * @param listener * @throws DifferenceFoundException */ protected void compareHasChildNodes(Node control, Node test, DifferenceListener listener) throws DifferenceFoundException { Boolean controlHasChildren = hasChildNodes(control); Boolean testHasChildren = hasChildNodes(test); compare(controlHasChildren, testHasChildren, control, test, listener, HAS_CHILD_NODES); }
/** * Compare two processing instructions * @param control * @param test * @param listener * @throws DifferenceFoundException */ protected void compareProcessingInstruction(ProcessingInstruction control, ProcessingInstruction test, DifferenceListener listener) throws DifferenceFoundException { compare(control.getTarget(), test.getTarget(), control, test, listener, PROCESSING_INSTRUCTION_TARGET); compare(control.getData(), test.getData(), control, test, listener, PROCESSING_INSTRUCTION_DATA); }
/** * Compare the number of children, and if the same, compare the actual * children via their NodeLists. * @param control * @param test * @param listener * @throws DifferenceFoundException */ protected void compareHasChildNodes(Node control, Node test, DifferenceListener listener) throws DifferenceFoundException { Boolean controlHasChildren = hasChildNodes(control); Boolean testHasChildren = hasChildNodes(test); compare(controlHasChildren, testHasChildren, control, test, listener, HAS_CHILD_NODES); }
private boolean isdifferent(Document testDoc, Document controlDoc) { boolean isdifferent = false; XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreComments(true); XMLUnit.setNormalize(true); Diff myDiff = new Diff(controlDoc, testDoc); DetailedDiff myComparisonController = new DetailedDiff(myDiff); DifferenceEngine engine = new DifferenceEngine(myComparisonController); XmlDifferenceListener listener = new XmlDifferenceListener(); ElementNameAndAttributeQualifier myElementQualifier = new ElementNameAndAttributeQualifier(); try { //debug engine.compare(controlDoc.getDocumentElement(), testDoc.getDocumentElement(), listener, myElementQualifier); } catch (NullPointerException ne) { LOG.error(ne); } isdifferent =listener.called(); return isdifferent; } }