From: SourceForge.net <no...@so...> - 2007-12-29 22:17:50
|
Bugs item #1860681, was opened at 2007-12-29 22:17 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377768&aid=1860681&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: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: jmeister (joerg-meister) Assigned to: Nobody/Anonymous (nobody) Summary: DifferenceEngine.compareNodeList Initial Comment: Hello, it seems to me as if there is a bug in the non-deprecated version of the method DifferenceEngine.compareNodeList(). To illustrate what I mean, I have generated a small example for you. Let's say, we have the following test respectively control structure: ===[ testDoc ]================================ <books> <book> <title>Kabale und Liebe</title> </book> <book> <title>Schuld und Suehne</title> </book> </books> ===[ controlDoc ]============================= <books> <book> <title>Schuld und Suehne</title> </book> </books> Now, we want to compare these structures via XMLUnit. To do so, we generate a DetailedDiff and use a MultiLevelElementNameAndTextQualifier for a correct Node matching: Diff diff = new Diff(controlDoc, testDoc); diff.overrideElementQualifier(new MultiLevelElementNameAndTextQualifier(2)); DetailedDiff dd = new DetailedDiff(diff); Iterator i = dd.getAllDifferences().iterator(); while (i.hasNext()) System.err.println((Difference) i.next()); The result of the comparison are the following error messages (the structure of the messages are always "comparing <ctrl_node> to <test_node>" with their respective XPaths): Expected number of child nodes '1' but was '2' - comparing <books...> at /books[1] to <books...> at /books[1] Expected sequence of child nodes '0' but was '1' - comparing <book...> at /books[1]/book[1] to <book...> at /books[1]/book[2] Expected presence of child node 'null' but was 'book' - comparing at /books[1]/book[1] to <book...> at /books[1]/book[2] The first and the second message are OK. XMLUnit compared the node "Schuld und Suehne" of the control structure (/books[1]/book[1]) to "Schuld und Suehne" of the test structure (/books[1]/book[2]) and recognized, that the sequence of nodes is different. Now the problem arises: Since there are no more nodes in the control structure, but one node left in the test structure, the DifferenceEngine throws a "CHILD_NODE_NOT_FOUND" message for this node. The problem is, that the XpathNodeTracker for test and control structure are not updated in the source code, therefore they return the wrong XPath for the unmatched node "Kabale and Liebe" - it says it is "/books[1]/book[2]", but in reality it is "/books[1]/book[1]"... In this case (a node in the test structure has no counterpart in the control structure or the other way around), the XpathNodeTracker always return the XPaths to the last node matched in test respectively control structure... I have attached a proposal of how this problem may be solved. Therefore you would have to change the DifferenceEngine as well as the XpathNodeTracker. I have marked up the lines within the source code with the key word "CODE_CHANGE", so it should be easy for you to understand what I mean. If you realize it that way, the result for the example given above would be: Expected number of child nodes '1' but was '2' - comparing <books...> at /books[1] to <books...> at /books[1] Expected sequence of child nodes '0' but was '1' - comparing <book...> at /books[1]/book[1] to <book...> at /books[1]/book[2] Expected presence of child node 'null' but was 'book' - comparing at to <book...> at /books[1]/book[1] Why is it that important, that you fix this bug? Well, if you want to react on the "CHILD_NODE_NOT_FOUND" event in a DifferenceListener, then you will need the exact XPath for the node that has no counterpart. At the moment, the wrong XPath is returned. Besides that, the error message in its current form is confusing... I have used JUnit 3.8.1 Xerces 2.8.1 XMLUnit 1.1 Hope this helps, Joerg ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377768&aid=1860681&group_id=23187 |