From: <bo...@us...> - 2009-09-18 15:29:43
|
Revision: 353 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=353&view=rev Author: bodewig Date: 2009-09-18 15:29:36 +0000 (Fri, 18 Sep 2009) Log Message: ----------- disable XMLUnit's behavior where it matches unmatched nodes against each other even if they don't qualify for comparision. Issue 2758280 Modified Paths: -------------- branches/xmlunit-1.x/src/java/org/custommonkey/xmlunit/DifferenceEngine.java branches/xmlunit-1.x/src/java/org/custommonkey/xmlunit/XMLUnit.java branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java Modified: branches/xmlunit-1.x/src/java/org/custommonkey/xmlunit/DifferenceEngine.java =================================================================== --- branches/xmlunit-1.x/src/java/org/custommonkey/xmlunit/DifferenceEngine.java 2009-08-17 07:38:21 UTC (rev 352) +++ branches/xmlunit-1.x/src/java/org/custommonkey/xmlunit/DifferenceEngine.java 2009-09-18 15:29:36 UTC (rev 353) @@ -454,7 +454,8 @@ } } } - if (!matchFound && fallbackMatch >= 0) { + if (!matchFound && XMLUnit.getCompareUnmatched() + && fallbackMatch >= 0) { matchFound = true; j = fallbackMatch; } @@ -472,7 +473,8 @@ Node nextControl = (Node) controlChildren.get(i); Node nextTest = (Node) matchingNodes.get(nextControl); Integer testIndex = (Integer) matchingNodeIndexes.get(nextControl); - if (nextTest == null && !unmatchedTestNodes.isEmpty()) { + if (nextTest == null && XMLUnit.getCompareUnmatched() + && !unmatchedTestNodes.isEmpty()) { nextTest = (Node) unmatchedTestNodes.get(0); testIndex = new Integer(testChildren.indexOf(nextTest)); unmatchedTestNodes.remove(0); Modified: branches/xmlunit-1.x/src/java/org/custommonkey/xmlunit/XMLUnit.java =================================================================== --- branches/xmlunit-1.x/src/java/org/custommonkey/xmlunit/XMLUnit.java 2009-08-17 07:38:21 UTC (rev 352) +++ branches/xmlunit-1.x/src/java/org/custommonkey/xmlunit/XMLUnit.java 2009-09-18 15:29:36 UTC (rev 353) @@ -83,6 +83,7 @@ private static String xsltVersion = "1.0"; private static String xpathFactoryName = null; private static boolean expandEntities = false; + private static boolean compareUnmatched = true; private static final String XSLT_VERSION_START = " version=\""; private static final String XSLT_VERSION_END = "\">"; @@ -881,5 +882,22 @@ public static boolean getExpandEntityReferences() { return expandEntities; } + + /** + * Whether to compare unmatched control nodes to unmatched test nodes. + * + * <p>Defaults to true.</p> + */ + public static void setCompareUnmatched(boolean b) { + compareUnmatched = b; + } + + /** + * Whether unmatched control nodes should be compared to unmatched + * test nodes. + */ + public static boolean getCompareUnmatched() { + return compareUnmatched; + } } 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 2009-08-17 07:38:21 UTC (rev 352) +++ branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java 2009-09-18 15:29:36 UTC (rev 353) @@ -323,4 +323,58 @@ secondForecast = "<weather><today temp=\"20\"/></weather>"; } + /** + * https://sourceforge.net/tracker/?func=detail&aid=2758280&group_id=23187&atid=377768 + */ + public void testCompareUnmatched() throws Exception { + String control = "<root><a>1</a>" + + "<b>1</b>" + + "<c>1</c>" + + "<d>1</d>" + + "<e>1</e></root>"; + String test = "<root><a>1</a>" + + "<b>1</b>" + + "<z>1</z>" + + "<d>1</d>" + + "<e>1</e></root>"; + DetailedDiff d = (DetailedDiff) buildDiff(control, test); + List l = d.getAllDifferences(); + assertEquals(1, l.size()); + Difference diff = (Difference) l.get(0); + assertEquals(DifferenceConstants.ELEMENT_TAG_NAME_ID, diff.getId()); + } + + /** + * https://sourceforge.net/tracker/?func=detail&aid=2758280&group_id=23187&atid=377768 + */ + public void testDontCompareUnmatched() throws Exception { + String control = "<root><a>1</a>" + + "<b>1</b>" + + "<c>1</c>" + + "<d>1</d>" + + "<e>1</e></root>"; + String test = "<root><a>1</a>" + + "<b>1</b>" + + "<z>1</z>" + + "<d>1</d>" + + "<e>1</e></root>"; + try { + XMLUnit.setCompareUnmatched(false); + DetailedDiff d = (DetailedDiff) buildDiff(control, test); + List l = d.getAllDifferences(); + assertEquals(2, l.size()); + Difference diff = (Difference) l.get(0); + assertEquals(DifferenceConstants.CHILD_NODE_NOT_FOUND_ID, + diff.getId()); + assertNotNull(diff.getControlNodeDetail().getNode()); + assertNull(diff.getTestNodeDetail().getNode()); + diff = (Difference) l.get(1); + assertEquals(DifferenceConstants.CHILD_NODE_NOT_FOUND_ID, + diff.getId()); + assertNull(diff.getControlNodeDetail().getNode()); + assertNotNull(diff.getTestNodeDetail().getNode()); + } finally { + XMLUnit.setCompareUnmatched(true); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |