From: <bo...@us...> - 2013-04-14 16:29:52
|
Revision: 527 http://sourceforge.net/p/xmlunit/code/527 Author: bodewig Date: 2013-04-14 16:29:49 +0000 (Sun, 14 Apr 2013) Log Message: ----------- Port fix for Issue 60 by Eric Siegerman to 2.x branch Modified Paths: -------------- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEngine.java trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DetailedDiff.java trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DifferenceEngine.java trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_IgnoreTextAndAttributeValuesDifferenceListener.java trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_NewDifferenceEngine.java trunk/xmlunit/src/user-guide/XMLUnit-Java.xml Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEngine.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEngine.java 2013-04-14 15:59:58 UTC (rev 526) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEngine.java 2013-04-14 16:29:49 UTC (rev 527) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2010, Jeff Martin, Tim Bacon +Copyright (c) 2001-2010,2013 Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -322,16 +322,28 @@ protected void compareNodeChildren(Node control, Node test, DifferenceListener listener, ElementQualifier elementQualifier) throws DifferenceFoundException { - if (control.hasChildNodes() && test.hasChildNodes()) { - List controlChildren = nodeList2List(control.getChildNodes()); - List testChildren = nodeList2List(test.getChildNodes()); - Integer controlLength = new Integer(controlChildren.size()); - Integer testLength = new Integer(testChildren.size()); - compare(controlLength, testLength, control, test, listener, - CHILD_NODELIST_LENGTH); - compareNodeList(controlChildren, testChildren, - controlLength.intValue(), listener, elementQualifier); + List controlChildren = nodeList2List(control.getChildNodes()); + List testChildren = nodeList2List(test.getChildNodes()); + + Integer controlLength = new Integer(controlChildren.size()); + Integer testLength = new Integer(testChildren.size()); + compare(controlLength, testLength, control, test, listener, + CHILD_NODELIST_LENGTH); + + if (control.hasChildNodes() || test.hasChildNodes()) { + if (!control.hasChildNodes()) { + for (Iterator iter = testChildren.iterator(); iter.hasNext();) { + missingNode(null, (Node) iter.next(), listener); + } + } else if (!test.hasChildNodes()) { + for (Iterator iter = controlChildren.iterator(); iter.hasNext();) { + missingNode((Node) iter.next(), null, listener); + } + } else { + compareNodeList(controlChildren, testChildren, + controlLength.intValue(), listener, elementQualifier); + } } } Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2013-04-14 15:59:58 UTC (rev 526) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2013-04-14 16:29:49 UTC (rev 527) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2010, Jeff Martin, Tim Bacon +Copyright (c) 2001-2010,2013 Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; +import java.util.List; import java.util.Map; import javax.xml.namespace.QName; import javax.xml.transform.Source; @@ -213,7 +214,8 @@ engine.compare(ctrlSource, tstSource); } - public static Difference toDifference(Comparison comp) { + public static Iterable<Difference> toDifference(Comparison comp) { + List<Difference> diffs = new LinkedList<Difference>(); Difference proto = null; switch (comp.getType()) { case ATTR_VALUE_EXPLICITLY_SPECIFIED: @@ -276,19 +278,19 @@ Comparison.Detail td = comp.getTestDetails(); if (ZERO.equals(cd.getValue()) || ZERO.equals(td.getValue())) { - return new Difference(HAS_CHILD_NODES, - new NodeDetail(String - .valueOf(!ZERO - .equals(cd - .getValue())), - (Node) cd.getTarget(), - cd.getXPath()), - new NodeDetail(String - .valueOf(!ZERO - .equals(td - .getValue())), - (Node) td.getTarget(), - td.getXPath())); + diffs.add(new Difference(HAS_CHILD_NODES, + new NodeDetail(String + .valueOf(!ZERO + .equals(cd + .getValue())), + (Node) cd.getTarget(), + cd.getXPath()), + new NodeDetail(String + .valueOf(!ZERO + .equals(td + .getValue())), + (Node) td.getTarget(), + td.getXPath()))); } proto = CHILD_NODELIST_LENGTH; break; @@ -306,10 +308,10 @@ break; } if (proto != null) { - return new Difference(proto, toNodeDetail(comp.getControlDetails()), - toNodeDetail(comp.getTestDetails())); + diffs.add(new Difference(proto, toNodeDetail(comp.getControlDetails()), + toNodeDetail(comp.getTestDetails()))); } - return null; + return diffs; } public static NodeDetail toNodeDetail(Comparison.Detail detail) { @@ -333,8 +335,7 @@ public void comparisonPerformed(Comparison comparison, ComparisonResult outcome) { - Difference diff = toDifference(comparison); - if (diff != null) { + for (Difference diff : toDifference(comparison)) { mt.matchFound(diff); } } @@ -350,8 +351,7 @@ public void comparisonPerformed(Comparison comparison, ComparisonResult outcome) { - Difference diff = toDifference(comparison); - if (diff != null) { + for (Difference diff : toDifference(comparison)) { dl.differenceFound(diff); } } @@ -412,9 +412,10 @@ public ComparisonResult evaluate(Comparison comparison, ComparisonResult outcome) { - Difference diff = toDifference(comparison); - if (diff != null && cc.haltComparison(diff)) { - return ComparisonResult.CRITICAL; + for (Difference diff : toDifference(comparison)) { + if (cc.haltComparison(diff)) { + return ComparisonResult.CRITICAL; + } } return outcome; } @@ -445,21 +446,31 @@ public ComparisonResult evaluate(Comparison comparison, ComparisonResult outcome) { - Difference diff = toDifference(comparison); - if (diff != null) { + ComparisonResult max = outcome; + for (Difference diff : toDifference(comparison)) { + ComparisonResult curr = null; switch (dl.differenceFound(diff)) { case DifferenceListener .RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL: - return ComparisonResult.EQUAL; + curr = ComparisonResult.EQUAL; + break; case DifferenceListener .RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR: - return ComparisonResult.SIMILAR; + curr = ComparisonResult.SIMILAR; + break; case DifferenceListener .RETURN_UPGRADE_DIFFERENCE_NODES_DIFFERENT: - return ComparisonResult.DIFFERENT; + curr = ComparisonResult.DIFFERENT; + break; + default: + // unknown result, ignore it + break; } + if (curr != null && curr.compareTo(max) > 0) { + max = curr; + } } - return outcome; + return max; } } Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DetailedDiff.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DetailedDiff.java 2013-04-14 15:59:58 UTC (rev 526) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DetailedDiff.java 2013-04-14 16:29:49 UTC (rev 527) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2008,2010 Jeff Martin, Tim Bacon +Copyright (c) 2001-2008,2010,2013 Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -63,17 +63,19 @@ private void assertExpectedDifferencesFirstForecastControl(List differences, DetailedDiff detailedDiff) { - assertEquals("size: " + detailedDiff, 5, differences.size()); + assertEquals("size: " + detailedDiff, 6, differences.size()); assertEquals("first: " + detailedDiff, DifferenceConstants.HAS_CHILD_NODES, differences.get(0)); assertEquals("second: " + detailedDiff, - DifferenceConstants.ELEMENT_NUM_ATTRIBUTES, differences.get(1)); + DifferenceConstants.CHILD_NODELIST_LENGTH, differences.get(1)); assertEquals("third: " + detailedDiff, - DifferenceConstants.ATTR_NAME_NOT_FOUND, differences.get(2)); - assertEquals("fourth: " + detailedDiff, - DifferenceConstants.ATTR_VALUE, differences.get(3)); + DifferenceConstants.ELEMENT_NUM_ATTRIBUTES, differences.get(2)); + assertEquals("forth: " + detailedDiff, + DifferenceConstants.ATTR_NAME_NOT_FOUND, differences.get(3)); assertEquals("fifth: " + detailedDiff, - DifferenceConstants.CHILD_NODE_NOT_FOUND, differences.get(4)); + DifferenceConstants.ATTR_VALUE, differences.get(4)); + assertEquals("sixth: " + detailedDiff, + DifferenceConstants.CHILD_NODE_NOT_FOUND, differences.get(5)); } public void testAllDifferencesSecondForecastControl() throws Exception { @@ -82,18 +84,20 @@ List differences = detailedDiff.getAllDifferences(); - assertEquals("size: " + detailedDiff, 5, differences.size()); + assertEquals("size: " + detailedDiff, 6, differences.size()); assertEquals("first: " + detailedDiff, DifferenceConstants.HAS_CHILD_NODES, differences.get(0)); assertEquals("second: " + detailedDiff, - DifferenceConstants.ELEMENT_NUM_ATTRIBUTES, differences.get(1)); + DifferenceConstants.CHILD_NODELIST_LENGTH, differences.get(1)); assertEquals("third: " + detailedDiff, - DifferenceConstants.ATTR_VALUE, differences.get(2)); + DifferenceConstants.ELEMENT_NUM_ATTRIBUTES, differences.get(2)); assertEquals("forth: " + detailedDiff, + DifferenceConstants.ATTR_VALUE, differences.get(3)); + assertEquals("fifth: " + detailedDiff, DifferenceConstants.ATTR_NAME_NOT_FOUND, - differences.get(3)); - assertEquals("fifth: " + detailedDiff, - DifferenceConstants.CHILD_NODE_NOT_FOUND, differences.get(4)); + differences.get(4)); + assertEquals("sixth: " + detailedDiff, + DifferenceConstants.CHILD_NODE_NOT_FOUND, differences.get(5)); } public void testPrototypeIsADetailedDiff() throws Exception { Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java 2013-04-14 15:59:58 UTC (rev 526) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java 2013-04-14 16:29:49 UTC (rev 527) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2013, Jeff Martin, Tim Bacon +Copyright (c) 2001-2013 Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -789,9 +789,10 @@ // // NODE_TYPE(Element), NAMESPACE_URI(none), // NAMESPACE_PREFIX(none), HAS_CHILD_NODES(false), + // CHILD_NODELIST_LENGTH(0), // ELEMENT_TAG_NAME(foo), ELEMENT_NUM_ATTRIBUTE(none), // SCHEMA_LOCATION(none), NO_NAMESPACE_SCHEMA_LOCATION(none) - assertEquals(14, count[0]); + assertEquals(15, count[0]); } public void testMatchTrackerSetViaEngine() throws Exception { @@ -816,8 +817,9 @@ // // NODE_TYPE(Element), NAMESPACE_URI(none), // NAMESPACE_PREFIX(none), ELEMENT_TAG_NAME(foo), - // ELEMENT_NUM_ATTRIBUTE(none), HAS_CHILD_NODES(false) - assertEquals(12, count[0]); + // ELEMENT_NUM_ATTRIBUTE(none), HAS_CHILD_NODES(false), + // CHILD_NODELIST_LENGTH(0) + assertEquals(13, count[0]); } public void testMatchTrackerSetViaOverrideOnEngine() throws Exception { @@ -843,8 +845,9 @@ // // NODE_TYPE(Element), NAMESPACE_URI(none), // NAMESPACE_PREFIX(none), ELEMENT_TAG_NAME(foo), - // ELEMENT_NUM_ATTRIBUTE(none), HAS_CHILD_NODES(false) - assertEquals(12, count[0]); + // ELEMENT_NUM_ATTRIBUTE(none), HAS_CHILD_NODES(false), + // CHILD_NODELIST_LENGTH(0) + assertEquals(13, count[0]); } public void testMatchTrackerSetViaNewEngine() throws Exception { @@ -869,9 +872,10 @@ // // NODE_TYPE(Element), NAMESPACE_URI(none), // NAMESPACE_PREFIX(none), HAS_CHILD_NODES(false), + // CHILD_NODELIST_LENGTH(0), // ELEMENT_TAG_NAME(foo), ELEMENT_NUM_ATTRIBUTE(none), // SCHEMA_LOCATION(none), NO_NAMESPACE_SCHEMA_LOCATION(none) - assertEquals(14, count[0]); + assertEquals(15, count[0]); } public void testMatchTrackerSetViaOverrideOnNewEngine() throws Exception { @@ -897,9 +901,10 @@ // // NODE_TYPE(Element), NAMESPACE_URI(none), // NAMESPACE_PREFIX(none), HAS_CHILD_NODES(false), + // CHILD_NODELIST_LENGTH(0), // ELEMENT_TAG_NAME(foo), ELEMENT_NUM_ATTRIBUTE(none), // SCHEMA_LOCATION(none), NO_NAMESPACE_SCHEMA_LOCATION(none) - assertEquals(14, count[0]); + assertEquals(15, count[0]); } public void testCDATAAndIgnoreWhitespace() throws Exception { Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DifferenceEngine.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DifferenceEngine.java 2013-04-14 15:59:58 UTC (rev 526) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DifferenceEngine.java 2013-04-14 16:29:49 UTC (rev 527) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2008,2010 Jeff Martin, Tim Bacon +Copyright (c) 2001-2008,2010,2013 Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -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); } @@ -857,8 +857,9 @@ d.compare(control, test, listener, null); // NODE_TYPE (not null), NODE_TYPE(Element), NAMESPACE_URI(none), // NAMESPACE_PREFIX(none), ELEMENT_TAG_NAME(foo), - // ELEMENT_NUM_ATTRIBUTE(none), HAS_CHILD_NODES(false) - assertEquals(7, count[0]); + // ELEMENT_NUM_ATTRIBUTE(none), HAS_CHILD_NODES(false), + // CHILD_NODELIST_LENGTH(0) + assertEquals(8, count[0]); } public void testMatchTrackerSetViaSetter() throws Exception { @@ -873,8 +874,9 @@ engine.compare(control, test, listener, null); // NODE_TYPE (not null), NODE_TYPE(Element), NAMESPACE_URI(none), // NAMESPACE_PREFIX(none), ELEMENT_TAG_NAME(foo), - // ELEMENT_NUM_ATTRIBUTE(none), HAS_CHILD_NODES(false) - assertEquals(7, count[0]); + // ELEMENT_NUM_ATTRIBUTE(none), HAS_CHILD_NODES(false), + // CHILD_NODELIST_LENGTH(0) + assertEquals(8, count[0]); } /** Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_IgnoreTextAndAttributeValuesDifferenceListener.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_IgnoreTextAndAttributeValuesDifferenceListener.java 2013-04-14 15:59:58 UTC (rev 526) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_IgnoreTextAndAttributeValuesDifferenceListener.java 2013-04-14 16:29:49 UTC (rev 527) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 200, Jeff Martin, Tim Bacon +Copyright (c) 2001-2008,2013 Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -146,9 +146,9 @@ new Diff(control, dissimilarTest)); dissimilarDetailedDiff.overrideDifferenceListener(listener); List differences = dissimilarDetailedDiff.getAllDifferences(); - assertEquals("has children, wrong number of attributes, missing attribute, different attribute value, and missing text node. " + assertEquals("has children, wrong number of attributes, missing attribute, different attribute value, number of children and missing text node. " + dissimilarDetailedDiff.toString(), - 5, differences.size()); + 6, differences.size()); int recoverable = 0; for (Iterator iter = differences.iterator(); iter.hasNext(); ) { Difference aDifference = (Difference) iter.next(); Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_NewDifferenceEngine.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_NewDifferenceEngine.java 2013-04-14 15:59:58 UTC (rev 526) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_NewDifferenceEngine.java 2013-04-14 16:29:49 UTC (rev 527) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2008,2010 Jeff Martin, Tim Bacon +Copyright (c) 2001-2008,2010,2013 Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -255,11 +255,11 @@ String test = "<stuff><item id=\"2\"/></stuff>"; listenToDifferences(control, test); assertEquals("15th difference type", - NewDifferenceEngine.HAS_CHILD_NODES_ID, + NewDifferenceEngine.CHILD_NODELIST_LENGTH_ID, listener.comparingWhat); - assertEquals("15th difference control value", "true", + assertEquals("15th difference control value", "1", listener.expected); - assertEquals("15th difference test value", "false", + assertEquals("15th difference test value", "0", listener.actual); assertEquals("15th control xpath", "/stuff[1]/item[1]", listener.controlXpath); @@ -390,9 +390,10 @@ d.compare(control, test, listener, null); // NODE_TYPE(Element), NAMESPACE_URI(none), // NAMESPACE_PREFIX(none), HAS_CHILD_NODES(false), + // CHILD_NODELIST_LENGTH(0), // ELEMENT_TAG_NAME(foo), ELEMENT_NUM_ATTRIBUTE(none), // SCHEMA_LOCATION(none), NO_NAMESPACE_SCHEMA_LOCATION(none) - assertEquals(8, count[0]); + assertEquals(9, count[0]); } public void testMatchTrackerSetViaSetter() throws Exception { @@ -407,9 +408,10 @@ engine.compare(control, test, listener, null); // NODE_TYPE(Element), NAMESPACE_URI(none), // NAMESPACE_PREFIX(none), HAS_CHILD_NODES(false), + // CHILD_NODELIST_LENGTH(0) // ELEMENT_TAG_NAME(foo), ELEMENT_NUM_ATTRIBUTE(none), // SCHEMA_LOCATION(none), NO_NAMESPACE_SCHEMA_LOCATION(none) - assertEquals(8, count[0]); + assertEquals(9, count[0]); } /** Modified: trunk/xmlunit/src/user-guide/XMLUnit-Java.xml =================================================================== --- trunk/xmlunit/src/user-guide/XMLUnit-Java.xml 2013-04-14 15:59:58 UTC (rev 526) +++ trunk/xmlunit/src/user-guide/XMLUnit-Java.xml 2013-04-14 16:29:49 UTC (rev 527) @@ -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> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |