From: Jyothi <jy...@us...> - 2017-11-22 12:05:32
|
Is there any update on the issue mentioned in the above post w.r.t change in the order of the Attribute values as below. I have tried with both XMLUnit 1 & 2 versions with no luck. Any help will be appriciated. CONTROL <Fruits> <Apple size="11" color="green"/>" <Apple size="13" color="green"/>" <Apple size="15" color="green"/>" </Fruits> TEST <Fruits> <Apple size="13" color="green"/> <Apple size="11" color="green"/> </Fruits> Disabling the comparison of unmatched nodes and using ElementNameQualifier class, I got these differences: Expected attribute value '11' but was '13' - comparing <Apple size="11"...> at /Fruits[1]/Apple[1]/@size to <Apple size="13"...> at /Fruits[1]/Apple[1]/@size Expected attribute value '13' but was '11' - comparing <Apple size="13"...> at /Fruits[1]/Apple[2]/@size to <Apple size="11"...> at /Fruits[1]/Apple[2]/@size Expected presence of child node 'Apple' but was 'null' - comparing <Apple...> at /Fruits[1]/Apple[3] 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 --- ** [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. |