@Test public void compareElements() { DOMDifferenceEngine d = new DOMDifferenceEngine(); DiffExpecter ex = new DiffExpecter(ComparisonType.ELEMENT_TAG_NAME); d.addDifferenceListener(ex); d.setComparisonController(ComparisonControllers.StopWhenDifferent); Element e1 = doc.createElement("foo"); Element e2 = doc.createElement("foo"); Element e3 = doc.createElement("bar"); assertEquals(wrap(ComparisonResult.EQUAL), d.compareNodes(e1, new XPathContext(), e2, new XPathContext())); assertEquals(wrapAndStop(ComparisonResult.DIFFERENT), d.compareNodes(e1, new XPathContext(), e3, new XPathContext())); assertEquals(1, ex.invoked); d = new DOMDifferenceEngine(); ex = new DiffExpecter(ComparisonType.ELEMENT_NUM_ATTRIBUTES); e1.setAttribute("attr1", "value1"); d.addDifferenceListener(ex); d.setComparisonController(ComparisonControllers.StopWhenDifferent); assertEquals(wrapAndStop(ComparisonResult.DIFFERENT), d.compareNodes(e1, new XPathContext(), e2, new XPathContext())); assertEquals(1, ex.invoked); d = new DOMDifferenceEngine(); ex = new DiffExpecter(ComparisonType.ATTR_NAME_LOOKUP, "/@attr1", "/"); e2.setAttributeNS("urn:xmlunit:test", "attr1", "value1"); d.addDifferenceListener(ex); d.setComparisonController(ComparisonControllers.StopWhenDifferent); assertEquals(wrapAndStop(ComparisonResult.DIFFERENT), d.compareNodes(e1, new XPathContext(), e2, new XPathContext())); assertEquals(1, ex.invoked); d = new DOMDifferenceEngine(); d.addDifferenceListener(new ComparisonListener() { public void comparisonPerformed(Comparison comparison, ComparisonResult outcome) { fail("unexpected Comparison of type " + comparison.getType() + " with outcome " + outcome + " and values '" + comparison.getControlDetails().getValue() + "' and '" + comparison.getTestDetails().getValue() + "'"); } }); e1.setAttributeNS("urn:xmlunit:test", "attr1", "value1"); e2.setAttributeNS(null, "attr1", "value1"); d.addDifferenceListener(ex); d.setComparisonController(ComparisonControllers.StopWhenDifferent); assertEquals(wrap(ComparisonResult.EQUAL), d.compareNodes(e1, new XPathContext(), e2, new XPathContext())); }
private ComparisonState compareElements(final Element control, final XPathContext controlContext, final Element test, final XPathContext testContext) { return compare(new Comparison(ComparisonType.ELEMENT_TAG_NAME, control, getXPath(controlContext), Nodes.getQName(control).getLocalPart(), getParentXPath(controlContext), test, getXPath(testContext), Nodes.getQName(test).getLocalPart(), getParentXPath(testContext))) .andThen(new DeferredComparison() { @Override public ComparisonState apply() { return compareElementAttributes(control, controlContext, test, testContext); } }); }
DOMDifferenceEngine extends AbstractDifferenceEngine { private ComparisonState compareElements(final Element control, final XPathContext controlContext, final Element test, final XPathContext testContext) { return compare(new Comparison(ComparisonType.ELEMENT_TAG_NAME, control, getXPath(controlContext), Nodes.getQName(control).getLocalPart(), getParentXPath(controlContext), test, getXPath(testContext), Nodes.getQName(test).getLocalPart(), getParentXPath(testContext))) .andThen(new DeferredComparison() { @Override public ComparisonState apply() { return compareElementAttributes(control, controlContext, test, testContext); } }); } }
DOMDifferenceEngine extends AbstractDifferenceEngine { private ComparisonState compareElements(final Element control, final XPathContext controlContext, final Element test, final XPathContext testContext) { return compare(new Comparison(ComparisonType.ELEMENT_TAG_NAME, control, getXPath(controlContext), Nodes.getQName(control).getLocalPart(), getParentXPath(controlContext), test, getXPath(testContext), Nodes.getQName(test).getLocalPart(), getParentXPath(testContext))) .andThen(new DeferredComparison() { @Override public ComparisonState apply() { return compareElementAttributes(control, controlContext, test, testContext); } }); } DOMDifferenceEngine();  DOMDifferenceEngine(final DocumentBuilderFactory f); }
DOMDifferenceEngine extends AbstractDifferenceEngine { private ComparisonState compareElements(final Element control, final XPathContext controlContext, final Element test, final XPathContext testContext) { return compare(new Comparison(ComparisonType.ELEMENT_TAG_NAME, control, getXPath(controlContext), Nodes.getQName(control).getLocalPart(), getParentXPath(controlContext), test, getXPath(testContext), Nodes.getQName(test).getLocalPart(), getParentXPath(testContext))) .andThen(new DeferredComparison() { @Override public ComparisonState apply() { return compareElementAttributes(control, controlContext, test, testContext); } }); } DOMDifferenceEngine();  DOMDifferenceEngine(final DocumentBuilderFactory f); void setDocumentBuilderFactory(DocumentBuilderFactory f); @Override void compare(Source control, Source test); }
DOMDifferenceEngine extends AbstractDifferenceEngine { private ComparisonState compareElements(final Element control, final XPathContext controlContext, final Element test, final XPathContext testContext) { return compare(new Comparison(ComparisonType.ELEMENT_TAG_NAME, control, getXPath(controlContext), Nodes.getQName(control).getLocalPart(), getParentXPath(controlContext), test, getXPath(testContext), Nodes.getQName(test).getLocalPart(), getParentXPath(testContext))) .andThen(new DeferredComparison() { @Override public ComparisonState apply() { return compareElementAttributes(control, controlContext, test, testContext); } }); } DOMDifferenceEngine();  DOMDifferenceEngine(final DocumentBuilderFactory f); void setDocumentBuilderFactory(DocumentBuilderFactory f); @Override void compare(Source control, Source test);  }