@Test public void sourceforgeForumThread92c980ec5b() { Element gp1 = doc.createElement("grandparent"); Element p1_0 = doc.createElement("parent"); p1_0.setAttribute("id", "0"); gp1.appendChild(p1_0); Element p1_1 = doc.createElement("parent"); p1_1.setAttribute("id", "1"); gp1.appendChild(p1_1); Element c1_1 = doc.createElement("child"); c1_1.setAttribute("id", "1"); p1_1.appendChild(c1_1); Element gp2 = doc.createElement("grandparent"); Element p2_1 = doc.createElement("parent"); p2_1.setAttribute("id", "1"); gp2.appendChild(p2_1); Element c2_1 = doc.createElement("child"); c2_1.setAttribute("id", "1"); p2_1.appendChild(c2_1); Element c2_2 = doc.createElement("child"); c2_2.setAttribute("id", "2"); p2_1.appendChild(c2_2); DOMDifferenceEngine d = new DOMDifferenceEngine(); DiffExpecter ex = new DiffExpecter(ComparisonType.CHILD_LOOKUP, null, "/grandparent[1]/parent[1]/child[2]") .withParentXPath("/grandparent[1]/parent[2]", "/grandparent[1]/parent[1]"); d.addDifferenceListener(ex); DifferenceEvaluator ev = new DifferenceEvaluator() { public ComparisonResult evaluate(Comparison comparison, ComparisonResult outcome) { if (comparison.getType() == ComparisonType.CHILD_NODELIST_LENGTH || comparison.getType() == ComparisonType.CHILD_NODELIST_SEQUENCE) { return ComparisonResult.EQUAL; } if (comparison.getType() == ComparisonType.CHILD_LOOKUP && comparison.getTestDetails().getTarget() == null) { return ComparisonResult.EQUAL; } return outcome; } }; d.setDifferenceEvaluator(ev); d.setComparisonController(ComparisonControllers.StopWhenDifferent); d.setNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndAllAttributes)); d.setNodeFilter(new Predicate<Node>() { @Override public boolean test(Node n) { return n.getNodeType() != Node.DOCUMENT_TYPE_NODE && !("parent".equals(n.getNodeName()) && "0".equals(n.getAttributes().getNamedItem("id").getNodeValue())); } }); assertEquals(wrapAndStop(ComparisonResult.DIFFERENT), d.compareNodes(gp1, new XPathContext(gp1), gp2, new XPathContext(gp2))); assertEquals(1, ex.invoked); }
ComparisonState compareNodes(final Node control, final XPathContext controlContext, final Node test, final XPathContext testContext) { final Iterable<Node> allControlChildren = new IterableNodeList(control.getChildNodes()); final Iterable<Node> controlChildren = Linqy.filter(allControlChildren, getNodeFilter()); final Iterable<Node> allTestChildren = new IterableNodeList(test.getChildNodes()); final Iterable<Node> testChildren = Linqy.filter(allTestChildren, getNodeFilter()); return compare(new Comparison(ComparisonType.NODE_TYPE, control, getXPath(controlContext), control.getNodeType(), getParentXPath(controlContext), test, getXPath(testContext), test.getNodeType(), getParentXPath(testContext))) .andThen(new Comparison(ComparisonType.NAMESPACE_URI, control, getXPath(controlContext), control.getNamespaceURI(), getParentXPath(controlContext), test, getXPath(testContext), test.getNamespaceURI(), getParentXPath(testContext))) .andThen(new Comparison(ComparisonType.NAMESPACE_PREFIX, control, getXPath(controlContext), control.getPrefix(), getParentXPath(controlContext), test, getXPath(testContext), test.getPrefix(), getParentXPath(testContext))) .andIfTrueThen(control.getNodeType() != Node.ATTRIBUTE_NODE, new Comparison(ComparisonType.CHILD_NODELIST_LENGTH, control, getXPath(controlContext), Linqy.count(controlChildren), getParentXPath(controlContext), test, getXPath(testContext), Linqy.count(testChildren), getParentXPath(testContext))) .andThen(new DeferredComparison() { @Override public ComparisonState apply() { return nodeTypeSpecificComparison(control, controlContext, test, testContext); } }) .andIfTrueThen(control.getNodeType() != Node.ATTRIBUTE_NODE, compareChildren(controlContext, allControlChildren, controlChildren, testContext, allTestChildren, testChildren)); }
DOMDifferenceEngine extends AbstractDifferenceEngine { ComparisonState compareNodes(final Node control, final XPathContext controlContext, final Node test, final XPathContext testContext) { final Iterable<Node> allControlChildren = new IterableNodeList(control.getChildNodes()); final Iterable<Node> controlChildren = Linqy.filter(allControlChildren, getNodeFilter()); final Iterable<Node> allTestChildren = new IterableNodeList(test.getChildNodes()); final Iterable<Node> testChildren = Linqy.filter(allTestChildren, getNodeFilter()); return compare(new Comparison(ComparisonType.NODE_TYPE, control, getXPath(controlContext), control.getNodeType(), getParentXPath(controlContext), test, getXPath(testContext), test.getNodeType(), getParentXPath(testContext))) .andThen(new Comparison(ComparisonType.NAMESPACE_URI, control, getXPath(controlContext), control.getNamespaceURI(), getParentXPath(controlContext), test, getXPath(testContext), test.getNamespaceURI(), getParentXPath(testContext))) .andThen(new Comparison(ComparisonType.NAMESPACE_PREFIX, control, getXPath(controlContext), control.getPrefix(), getParentXPath(controlContext), test, getXPath(testContext), test.getPrefix(), getParentXPath(testContext))) .andIfTrueThen(control.getNodeType() != Node.ATTRIBUTE_NODE, new Comparison(ComparisonType.CHILD_NODELIST_LENGTH, control, getXPath(controlContext), Linqy.count(controlChildren), getParentXPath(controlContext), test, getXPath(testContext), Linqy.count(testChildren), getParentXPath(testContext))) .andThen(new DeferredComparison() { @Override public ComparisonState apply() { return nodeTypeSpecificComparison(control, controlContext, test, testContext); } }) .andIfTrueThen(control.getNodeType() != Node.ATTRIBUTE_NODE, compareChildren(controlContext, allControlChildren, controlChildren, testContext, allTestChildren, testChildren)); } }
DOMDifferenceEngine extends AbstractDifferenceEngine { ComparisonState compareNodes(final Node control, final XPathContext controlContext, final Node test, final XPathContext testContext) { final Iterable<Node> allControlChildren = new IterableNodeList(control.getChildNodes()); final Iterable<Node> controlChildren = Linqy.filter(allControlChildren, getNodeFilter()); final Iterable<Node> allTestChildren = new IterableNodeList(test.getChildNodes()); final Iterable<Node> testChildren = Linqy.filter(allTestChildren, getNodeFilter()); return compare(new Comparison(ComparisonType.NODE_TYPE, control, getXPath(controlContext), control.getNodeType(), getParentXPath(controlContext), test, getXPath(testContext), test.getNodeType(), getParentXPath(testContext))) .andThen(new Comparison(ComparisonType.NAMESPACE_URI, control, getXPath(controlContext), control.getNamespaceURI(), getParentXPath(controlContext), test, getXPath(testContext), test.getNamespaceURI(), getParentXPath(testContext))) .andThen(new Comparison(ComparisonType.NAMESPACE_PREFIX, control, getXPath(controlContext), control.getPrefix(), getParentXPath(controlContext), test, getXPath(testContext), test.getPrefix(), getParentXPath(testContext))) .andIfTrueThen(control.getNodeType() != Node.ATTRIBUTE_NODE, new Comparison(ComparisonType.CHILD_NODELIST_LENGTH, control, getXPath(controlContext), Linqy.count(controlChildren), getParentXPath(controlContext), test, getXPath(testContext), Linqy.count(testChildren), getParentXPath(testContext))) .andThen(new DeferredComparison() { @Override public ComparisonState apply() { return nodeTypeSpecificComparison(control, controlContext, test, testContext); } }) .andIfTrueThen(control.getNodeType() != Node.ATTRIBUTE_NODE, compareChildren(controlContext, allControlChildren, controlChildren, testContext, allTestChildren, testChildren)); } DOMDifferenceEngine();  DOMDifferenceEngine(final DocumentBuilderFactory f); }
DOMDifferenceEngine extends AbstractDifferenceEngine { ComparisonState compareNodes(final Node control, final XPathContext controlContext, final Node test, final XPathContext testContext) { final Iterable<Node> allControlChildren = new IterableNodeList(control.getChildNodes()); final Iterable<Node> controlChildren = Linqy.filter(allControlChildren, getNodeFilter()); final Iterable<Node> allTestChildren = new IterableNodeList(test.getChildNodes()); final Iterable<Node> testChildren = Linqy.filter(allTestChildren, getNodeFilter()); return compare(new Comparison(ComparisonType.NODE_TYPE, control, getXPath(controlContext), control.getNodeType(), getParentXPath(controlContext), test, getXPath(testContext), test.getNodeType(), getParentXPath(testContext))) .andThen(new Comparison(ComparisonType.NAMESPACE_URI, control, getXPath(controlContext), control.getNamespaceURI(), getParentXPath(controlContext), test, getXPath(testContext), test.getNamespaceURI(), getParentXPath(testContext))) .andThen(new Comparison(ComparisonType.NAMESPACE_PREFIX, control, getXPath(controlContext), control.getPrefix(), getParentXPath(controlContext), test, getXPath(testContext), test.getPrefix(), getParentXPath(testContext))) .andIfTrueThen(control.getNodeType() != Node.ATTRIBUTE_NODE, new Comparison(ComparisonType.CHILD_NODELIST_LENGTH, control, getXPath(controlContext), Linqy.count(controlChildren), getParentXPath(controlContext), test, getXPath(testContext), Linqy.count(testChildren), getParentXPath(testContext))) .andThen(new DeferredComparison() { @Override public ComparisonState apply() { return nodeTypeSpecificComparison(control, controlContext, test, testContext); } }) .andIfTrueThen(control.getNodeType() != Node.ATTRIBUTE_NODE, compareChildren(controlContext, allControlChildren, controlChildren, testContext, allTestChildren, testChildren)); } DOMDifferenceEngine();  DOMDifferenceEngine(final DocumentBuilderFactory f); void setDocumentBuilderFactory(DocumentBuilderFactory f); @Override void compare(Source control, Source test); }
DOMDifferenceEngine extends AbstractDifferenceEngine { ComparisonState compareNodes(final Node control, final XPathContext controlContext, final Node test, final XPathContext testContext) { final Iterable<Node> allControlChildren = new IterableNodeList(control.getChildNodes()); final Iterable<Node> controlChildren = Linqy.filter(allControlChildren, getNodeFilter()); final Iterable<Node> allTestChildren = new IterableNodeList(test.getChildNodes()); final Iterable<Node> testChildren = Linqy.filter(allTestChildren, getNodeFilter()); return compare(new Comparison(ComparisonType.NODE_TYPE, control, getXPath(controlContext), control.getNodeType(), getParentXPath(controlContext), test, getXPath(testContext), test.getNodeType(), getParentXPath(testContext))) .andThen(new Comparison(ComparisonType.NAMESPACE_URI, control, getXPath(controlContext), control.getNamespaceURI(), getParentXPath(controlContext), test, getXPath(testContext), test.getNamespaceURI(), getParentXPath(testContext))) .andThen(new Comparison(ComparisonType.NAMESPACE_PREFIX, control, getXPath(controlContext), control.getPrefix(), getParentXPath(controlContext), test, getXPath(testContext), test.getPrefix(), getParentXPath(testContext))) .andIfTrueThen(control.getNodeType() != Node.ATTRIBUTE_NODE, new Comparison(ComparisonType.CHILD_NODELIST_LENGTH, control, getXPath(controlContext), Linqy.count(controlChildren), getParentXPath(controlContext), test, getXPath(testContext), Linqy.count(testChildren), getParentXPath(testContext))) .andThen(new DeferredComparison() { @Override public ComparisonState apply() { return nodeTypeSpecificComparison(control, controlContext, test, testContext); } }) .andIfTrueThen(control.getNodeType() != Node.ATTRIBUTE_NODE, compareChildren(controlContext, allControlChildren, controlChildren, testContext, allTestChildren, testChildren)); } DOMDifferenceEngine();  DOMDifferenceEngine(final DocumentBuilderFactory f); void setDocumentBuilderFactory(DocumentBuilderFactory f); @Override void compare(Source control, Source test);  }