From: <bo...@us...> - 2014-12-29 15:36:34
|
Revision: 580 http://sourceforge.net/p/xmlunit/code/580 Author: bodewig Date: 2014-12-29 15:36:31 +0000 (Mon, 29 Dec 2014) Log Message: ----------- For missing attributes, the XPath should point to the attribute itself. https://sourceforge.net/p/xmlunit/feature-requests/33/ Modified Paths: -------------- trunk/src/java/org/custommonkey/xmlunit/DifferenceEngine.java trunk/src/user-guide/XMLUnit-Java.xml trunk/tests/java/org/custommonkey/xmlunit/test_Difference.java trunk/tests/java/org/custommonkey/xmlunit/test_DifferenceEngine.java Modified: trunk/src/java/org/custommonkey/xmlunit/DifferenceEngine.java =================================================================== --- trunk/src/java/org/custommonkey/xmlunit/DifferenceEngine.java 2014-12-28 19:07:04 UTC (rev 579) +++ trunk/src/java/org/custommonkey/xmlunit/DifferenceEngine.java 2014-12-29 15:36:31 UTC (rev 580) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2013, Jeff Martin, Tim Bacon +Copyright (c) 2001-2014, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -623,6 +623,7 @@ } } else { controlTracker.clearTrackedAttribute(); + controlTracker.visited(nextAttr); testTracker.clearTrackedAttribute(); compare(attrName, null, control, test, listener, ATTR_NAME_NOT_FOUND); @@ -638,6 +639,7 @@ } else { controlTracker.clearTrackedAttribute(); testTracker.clearTrackedAttribute(); + testTracker.visited(nextAttr); compare(null, getUnNamespacedNodeName(nextAttr, isNamespaced(nextAttr)), @@ -660,7 +662,6 @@ return aNode.getNodeName(); } - /** * @param attribute * @return true if the attribute represents a namespace declaration Modified: trunk/src/user-guide/XMLUnit-Java.xml =================================================================== --- trunk/src/user-guide/XMLUnit-Java.xml 2014-12-28 19:07:04 UTC (rev 579) +++ trunk/src/user-guide/XMLUnit-Java.xml 2014-12-29 15:36:31 UTC (rev 580) @@ -3793,6 +3793,15 @@ href="https://sourceforge.net/p/xmlunit/bugs/64/">Issue 64</ulink> </listitem> + <listitem> + When an attribute cannot be found (a + <literal>ATTR_NAME_NOT_FOUND</literal> difference) the + XPath on the side where the attribute exists will now + point to the attribute itself rather than its owning element. + <ulink + href="https://sourceforge.net/p/xmlunit/feature-requests/33/">Feature + Request 33</ulink> + </listitem> </itemizedlist> </section> </section> Modified: trunk/tests/java/org/custommonkey/xmlunit/test_Difference.java =================================================================== --- trunk/tests/java/org/custommonkey/xmlunit/test_Difference.java 2014-12-28 19:07:04 UTC (rev 579) +++ trunk/tests/java/org/custommonkey/xmlunit/test_Difference.java 2014-12-29 15:36:31 UTC (rev 580) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2009, Jeff Martin, Tim Bacon +Copyright (c) 2001-2009,2014, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -115,12 +115,34 @@ Difference d2 = (Difference) diffs.get(1); assertEquals(DifferenceConstants.ATTR_NAME_NOT_FOUND_ID, d2.getId()); - assertEquals("/foo[1]/bar[1]", + assertEquals("/foo[1]/bar[1]/@y", d2.getControlNodeDetail().getXpathLocation()); assertEquals("/foo[1]/bar[1]", d2.getTestNodeDetail().getXpathLocation()); } + public void testXpathOfMissingTestAttribute() throws Exception { + Diff d = new Diff("<foo><bar a=\"x\"/></foo>", + "<foo><bar a=\"x\" y=\"z\"/></foo>"); + DetailedDiff dd = new DetailedDiff(d); + List diffs = dd.getAllDifferences(); + assertEquals(2, diffs.size()); + Difference d1 = (Difference) diffs.get(0); + assertEquals(DifferenceConstants.ELEMENT_NUM_ATTRIBUTES_ID, + d1.getId()); + assertEquals("/foo[1]/bar[1]", + d1.getControlNodeDetail().getXpathLocation()); + assertEquals("/foo[1]/bar[1]", + d1.getTestNodeDetail().getXpathLocation()); + Difference d2 = (Difference) diffs.get(1); + assertEquals(DifferenceConstants.ATTR_NAME_NOT_FOUND_ID, + d2.getId()); + assertEquals("/foo[1]/bar[1]", + d2.getControlNodeDetail().getXpathLocation()); + assertEquals("/foo[1]/bar[1]/@y", + d2.getTestNodeDetail().getXpathLocation()); + } + /** * Constructor for test_Difference. * @param name Modified: trunk/tests/java/org/custommonkey/xmlunit/test_DifferenceEngine.java =================================================================== --- trunk/tests/java/org/custommonkey/xmlunit/test_DifferenceEngine.java 2014-12-28 19:07:04 UTC (rev 579) +++ trunk/tests/java/org/custommonkey/xmlunit/test_DifferenceEngine.java 2014-12-29 15:36:31 UTC (rev 580) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2008,2013 Jeff Martin, Tim Bacon +Copyright (c) 2001-2008,2013-2014 Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -841,6 +841,8 @@ test.setAttribute("baz", "bar"); engine.compare(control, test, listener, null); assertEquals(ATTR_NAME_NOT_FOUND_ID, listener.comparingWhat); + assertEquals("/foo[1]/@bar", listener.controlXpath); + assertEquals("/foo[1]", listener.testXpath); } public void testMatchTrackerSetViaConstructor() throws Exception { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |