From: <bo...@us...> - 2013-04-14 15:00:48
|
Revision: 525 http://sourceforge.net/p/xmlunit/code/525 Author: bodewig Date: 2013-04-14 15:00:45 +0000 (Sun, 14 Apr 2013) Log Message: ----------- signal CHILD_NODELIST_LENGTH and CHILD_NODE_NOT_FOUND in addition to HAS_CHILD_NODES - patch by Eric Siegerman - closes issue 60 Modified Paths: -------------- branches/xmlunit-1.x/src/java/org/custommonkey/xmlunit/DifferenceEngine.java branches/xmlunit-1.x/src/user-guide/XMLUnit-Java.xml branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_DifferenceEngine.java branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_IgnoreTextAndAttributeValuesDifferenceListener.java Modified: branches/xmlunit-1.x/src/java/org/custommonkey/xmlunit/DifferenceEngine.java =================================================================== --- branches/xmlunit-1.x/src/java/org/custommonkey/xmlunit/DifferenceEngine.java 2013-02-07 20:50:46 UTC (rev 524) +++ branches/xmlunit-1.x/src/java/org/custommonkey/xmlunit/DifferenceEngine.java 2013-04-14 15:00:45 UTC (rev 525) @@ -320,7 +320,7 @@ protected void compareNodeChildren(Node control, Node test, DifferenceListener listener, ElementQualifier elementQualifier) throws DifferenceFoundException { - if (control.hasChildNodes() && test.hasChildNodes()) { + if (control.hasChildNodes() || test.hasChildNodes()) { List controlChildren = nodeList2List(control.getChildNodes()); List testChildren = nodeList2List(test.getChildNodes()); @@ -328,8 +328,19 @@ Integer testLength = new Integer(testChildren.size()); compare(controlLength, testLength, control, test, listener, CHILD_NODELIST_LENGTH); - compareNodeList(controlChildren, testChildren, - controlLength.intValue(), listener, elementQualifier); + + if (controlLength.intValue() == 0) { + for (Iterator iter = testChildren.iterator(); iter.hasNext();) { + missingNode(null, (Node) iter.next(), listener); + } + } else if (testLength.intValue() == 0) { + for (Iterator iter = controlChildren.iterator(); iter.hasNext();) { + missingNode((Node) iter.next(), null, listener); + } + } else { + compareNodeList(controlChildren, testChildren, + controlLength.intValue(), listener, elementQualifier); + } } } Modified: branches/xmlunit-1.x/src/user-guide/XMLUnit-Java.xml =================================================================== --- branches/xmlunit-1.x/src/user-guide/XMLUnit-Java.xml 2013-02-07 20:50:46 UTC (rev 524) +++ branches/xmlunit-1.x/src/user-guide/XMLUnit-Java.xml 2013-04-14 15:00:45 UTC (rev 525) @@ -3695,6 +3695,46 @@ </section> </section> + <section id="Changes 1.5"> + <title>Changes from XMLUnit 1.4 to 1.5</title> + + <section id="Breaking Changes 1.5"> + <title>Breaking Changes</title> + + <itemizedlist> + <listitem> + If one node in the comparison has children while the other + one has not, XMLUnit 1.5 will signal a + <literal>CHILD_NODELIST_LENGTH</literal> difference and + <literal>CHILD_NODE_NOT_FOUND</literal> + differences for each child node of the node that has + children in addition to a <literal>HAS_CHILD_NODES</literal> difference. + <ulink + href="https://sourceforge.net/p/xmlunit/bugs/60/">Issue + 60</ulink> + </listitem> + </itemizedlist> + </section> + + <section id="New Features 1.5"> + <title>New Features</title> + + <itemizedlist> + <listitem> + </listitem> + </itemizedlist> + </section> + + <section id="Bugfixes 1.5"> + <title>Important Bug Fixes</title> + + <itemizedlist> + <listitem> + </listitem> + </itemizedlist> + </section> + </section> + </appendix> </article> Modified: branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java =================================================================== --- branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java 2013-02-07 20:50:46 UTC (rev 524) +++ branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java 2013-04-14 15:00:45 UTC (rev 525) @@ -63,7 +63,7 @@ private void assertExpectedDifferencesFirstForecastControl(List differences, DetailedDiff detailedDiff) { - assertEquals("size: " + detailedDiff, 5, differences.size()); + assertEquals("size: " + detailedDiff, 7, differences.size()); assertEquals("first: " + detailedDiff, DifferenceConstants.ELEMENT_NUM_ATTRIBUTES, differences.get(0)); assertEquals("second: " + detailedDiff, @@ -74,6 +74,10 @@ DifferenceConstants.ATTR_SEQUENCE, differences.get(3)); assertEquals("fifth: " + detailedDiff, DifferenceConstants.HAS_CHILD_NODES, differences.get(4)); + assertEquals("sixth: " + detailedDiff, + DifferenceConstants.CHILD_NODELIST_LENGTH, differences.get(5)); + assertEquals("seventh: " + detailedDiff, + DifferenceConstants.CHILD_NODE_NOT_FOUND, differences.get(6)); } public void testAllDifferencesSecondForecastControl() throws Exception { @@ -82,7 +86,7 @@ List differences = detailedDiff.getAllDifferences(); - assertEquals("size: " + detailedDiff, 5, differences.size()); + assertEquals("size: " + detailedDiff, 7, differences.size()); assertEquals("first: " + detailedDiff, DifferenceConstants.ELEMENT_NUM_ATTRIBUTES, differences.get(0)); assertEquals("second: " + detailedDiff, @@ -94,6 +98,10 @@ differences.get(3)); assertEquals("fifth: " + detailedDiff, DifferenceConstants.HAS_CHILD_NODES, differences.get(4)); + assertEquals("sixth: " + detailedDiff, + DifferenceConstants.CHILD_NODELIST_LENGTH, differences.get(5)); + assertEquals("seventy: " + detailedDiff, + DifferenceConstants.CHILD_NODE_NOT_FOUND, differences.get(6)); } public void testPrototypeIsADetailedDiff() throws Exception { @@ -116,15 +124,18 @@ new InputSource(new FileReader(test))) ); List l = differencesWithWhitespace.getAllDifferences(); - int unmatchedNodes = 0; + int unmatchedNodeDiffs = 0; + int hasChildNodeDiffs = 0; for (Iterator iter = l.iterator(); iter.hasNext();) { Difference d = (Difference) iter.next(); if (d.getId() == DifferenceConstants.CHILD_NODE_NOT_FOUND_ID) { - unmatchedNodes++; + unmatchedNodeDiffs++; + } else if (d.getId() == DifferenceConstants.HAS_CHILD_NODES_ID) { + hasChildNodeDiffs++; } } - assertEquals(1402 + unmatchedNodes, + assertEquals(1402 + hasChildNodeDiffs + unmatchedNodeDiffs, differencesWithWhitespace.getAllDifferences().size()); try { @@ -133,14 +144,17 @@ new Diff(new FileReader(control), new FileReader(test)); DetailedDiff detailedDiff = new DetailedDiff(prototype); List differences = detailedDiff.getAllDifferences(); - unmatchedNodes = 0; + unmatchedNodeDiffs = 0; + hasChildNodeDiffs = 0; for (Iterator iter = differences.iterator(); iter.hasNext();) { Difference d = (Difference) iter.next(); if (d.getId() == DifferenceConstants.CHILD_NODE_NOT_FOUND_ID) { - unmatchedNodes++; + unmatchedNodeDiffs++; + } else if (d.getId() == DifferenceConstants.HAS_CHILD_NODES_ID) { + hasChildNodeDiffs++; } } - assertEquals(40 + unmatchedNodes, differences.size()); + assertEquals(40 + hasChildNodeDiffs + unmatchedNodeDiffs, differences.size()); SimpleXpathEngine xpathEngine = new SimpleXpathEngine(); Document controlDoc = Modified: branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_DifferenceEngine.java =================================================================== --- branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_DifferenceEngine.java 2013-02-07 20:50:46 UTC (rev 524) +++ branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_DifferenceEngine.java 2013-04-14 15:00:45 UTC (rev 525) @@ -646,15 +646,15 @@ String test = "<stuff><item id=\"2\"/></stuff>"; listenToDifferences(control, test); assertEquals("15th difference type", - DifferenceEngine.HAS_CHILD_NODES_ID, + DifferenceEngine.CHILD_NODE_NOT_FOUND_ID, listener.comparingWhat); - assertEquals("15th difference control value", "true", + assertEquals("15th difference control value", "thing", listener.expected); - assertEquals("15th difference test value", "false", + assertEquals("15th difference test value", "null", listener.actual); - assertEquals("15th control xpath", "/stuff[1]/item[1]", + assertEquals("15th control xpath", "/stuff[1]/item[1]/thing[1]", listener.controlXpath); - assertEquals("15th test xpath", "/stuff[1]/item[1]", + assertNull("15th test xpath should be null but is " + listener.testXpath, listener.testXpath); } Modified: branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_IgnoreTextAndAttributeValuesDifferenceListener.java =================================================================== --- branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_IgnoreTextAndAttributeValuesDifferenceListener.java 2013-02-07 20:50:46 UTC (rev 524) +++ branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_IgnoreTextAndAttributeValuesDifferenceListener.java 2013-04-14 15:00:45 UTC (rev 525) @@ -146,9 +146,10 @@ new Diff(control, dissimilarTest)); dissimilarDetailedDiff.overrideDifferenceListener(listener); List differences = dissimilarDetailedDiff.getAllDifferences(); - assertEquals("wrong number of attributes, missing attribute, different attribute value, and missing text node. " + assertEquals("wrong number of attributes, missing attribute, different attribute value, presence of subnodes, " + + "number of subnodes, missing text node. " + dissimilarDetailedDiff.toString(), - 4, differences.size()); + 6, differences.size()); int recoverable = 0; for (Iterator iter = differences.iterator(); iter.hasNext(); ) { Difference aDifference = (Difference) iter.next(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |