From: SourceForge.net <no...@so...> - 2010-09-09 14:12:47
|
Bugs item #3062518, was opened at 2010-09-09 11:47 Message generated for change (Settings changed) made by bodewig You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377768&aid=3062518&group_id=23187 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None >Group: Java 1.3 Status: Closed Resolution: Duplicate Priority: 5 Private: No Submitted By: David Krzystek (david-krzystek) Assigned to: Nobody/Anonymous (nobody) Summary: DifferenceEngine error Initial Comment: Hi guys, I guess I spotted an incorrect difference reporting for example desbribed below. Control document ---------------------------------------------- <Fruits> <Apple size="11" color="green"/> <Apple size="15" color="green"/> <Banana size="10"/> </Fruits> Test document ---------------------------------------------- <Fruits> <Apple size="11" color="green"/> <Banana size="11"/> </Fruits> Removing one Apple and changing Banana's attribute size in the test document, comparator reports these differences: Expected number of child nodes '3' but was '2' - comparing <Fruits...> at /Fruits[1] to <Fruits...> at /Fruits[1] Expected element tag name 'Apple' but was 'Banana' - comparing <Apple...> at /Fruits[1]/Apple[2] to <Banana...> at /Fruits[1]/Banana[1] Expected number of element attributes '2' but was '1' - comparing <Apple...> at /Fruits[1]/Apple[2] to <Banana...> at /Fruits[1]/Banana[1] Expected attribute name 'color' but was 'null' - comparing <Apple...> at /Fruits[1]/Apple[2] to <Banana...> at /Fruits[1]/Banana[1] Expected attribute value '15' but was '11' - comparing <Apple size="15"...> at /Fruits[1]/Apple[2]/@size to <Banana size="11"...> at /Fruits[1]/Banana[1]/@size Expected presence of child node 'Banana' but was 'null' - comparing <Banana...> at /Fruits[1]/Banana[1] to at null This is actually incorrect according to me. I would expect to see: Expected number of child nodes '3' but was '2' - comparing <Fruits...> at /Fruits[1] to <Fruits...> at /Fruits[1] Expected presence of child node 'Apple' but was 'null' - comparing <Apple...> at /Fruits[1]/Apple[2] to at null Expected attribute value '10' but was '11' - comparing <Banana size="10"...> at /Fruits[1]/Banana[1]/@size to <Banana size="11"...> at /Fruits[1]/Banana[1]/@size I went through the DifferenceEngine code and I could see, that the method allows the comparison of apples and bananas protected void compareNodeList(final List controlChildren, final List testChildren, final int numNodes, final DifferenceListener listener, final ElementQualifier elementQualifier) throws DifferenceFoundException The part of the code which compares unmatched test nodes with the control nodes that did not match too. ... for (int i=0; i < numNodes; ++i) { Node nextControl = (Node) controlChildren.get(i); Node nextTest = (Node) matchingNodes.get(nextControl); Integer testIndex = (Integer) matchingNodeIndexes.get(nextControl); if (nextTest == null && XMLUnit.getCompareUnmatched() && !unmatchedTestNodes.isEmpty()) { nextTest = (Node) unmatchedTestNodes.get(0); testIndex = new Integer(testChildren.indexOf(nextTest)); unmatchedTestNodes.remove(0); } ... } ... I would suggest to compare nodes of the same name. It could look like the snippet below: ... for (int i=0; i < numNodes; ++i) { Node nextControl = (Node) controlChildren.get(i); Node nextTest = (Node) matchingNodes.get(nextControl); Integer testIndex = (Integer) matchingNodeIndexes.get(nextControl); if (nextTest == null && XMLUnit.getCompareUnmatched() && !unmatchedTestNodes.isEmpty()) { nextTest = (Node) unmatchedTestNodes.get(0); // check that we are not comparing apples with bananas if (nextControl.getLocalName().equals(nextTest.getLocalName())) { testIndex = new Integer(testChildren.indexOf(nextTest)); unmatchedTestNodes.remove(0); } else { nextTest = null; } } ... } ... Anyway, thank you for your great job. David ---------------------------------------------------------------------- >Comment By: Stefan Bodewig (bodewig) Date: 2010-09-09 16:12 Message: re-opening comments and changing category based on an email by David. ---------------------------------------------------------------------- Comment By: Stefan Bodewig (bodewig) Date: 2010-09-09 12:21 Message: duplicate of issue 2758280 ---------------------------------------------------------------------- Comment By: Stefan Bodewig (bodewig) Date: 2010-09-09 12:18 Message: This is addressed in XMLUnit 1.3. You should get the expected behavior if you set XMLUnit's compareUnmateched to false. See http://xmlunit.sourceforge.net/userguide/html/apas03.html#New%20Features%201.3 ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377768&aid=3062518&group_id=23187 |