From: Stefan B. <bo...@us...> - 2017-11-22 12:15:33
|
I'm not sure what kind of update you exptected. The issue has been closed. I think we are only trying to figure out how to configure the difference engine to create the result you want it to produce, which is not a bug in XMLUnit. The comparison result you show doesn't match your example XML as it talks about Banana and your examples don't contain any Banana elements. In order to help you configuring XMLUnit correctly I'd need to know which result you would expect as correct in your case. If you tried XMLUnit 2.x already, I'd urge you to read https://github.com/xmlunit/user-guide/wiki/SelectingNodes --- ** [bugs:#53] DifferenceEngine error** **Status:** closed-duplicate **Group:** Java_1.3 **Created:** Thu Sep 09, 2010 09:47 AM UTC by David Krzystek **Last Updated:** Wed Nov 22, 2017 11:38 AM UTC **Owner:** nobody 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 --- Sent from sourceforge.net because xml...@li... is subscribed to https://sourceforge.net/p/xmlunit/bugs/ To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/xmlunit/admin/bugs/options. Or, if this is a mailing list, you can unsubscribe from the mailing list. |