From: <bo...@us...> - 2014-12-29 15:57:04
|
Revision: 581 http://sourceforge.net/p/xmlunit/code/581 Author: bodewig Date: 2014-12-29 15:56:36 +0000 (Mon, 29 Dec 2014) Log Message: ----------- Provide the NS-information as part of the difference's value for ATTR_NAME_NOT_FOUND and CHILD_NODE_NOT_FOUND differences. https://sourceforge.net/p/xmlunit/bugs/65/ Modified Paths: -------------- trunk/src/java/org/custommonkey/xmlunit/DifferenceEngine.java trunk/src/user-guide/XMLUnit-Java.xml 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-29 15:36:31 UTC (rev 580) +++ trunk/src/java/org/custommonkey/xmlunit/DifferenceEngine.java 2014-12-29 15:56:36 UTC (rev 581) @@ -512,11 +512,11 @@ throws DifferenceFoundException { if (control != null) { controlTracker.visited(control); - compare(control.getNodeName(), null, control, null, + compare(getQName(control), null, control, null, listener, CHILD_NODE_NOT_FOUND, controlTracker, null); } else { testTracker.visited(test); - compare(null, test.getNodeName(), null, test, listener, + compare(null, getQName(test), null, test, listener, CHILD_NODE_NOT_FOUND, null, testTracker); } } @@ -625,7 +625,8 @@ controlTracker.clearTrackedAttribute(); controlTracker.visited(nextAttr); testTracker.clearTrackedAttribute(); - compare(attrName, null, control, test, listener, + compare(getQName(nextAttr, isNamespacedAttr), null, + control, test, listener, ATTR_NAME_NOT_FOUND); } } @@ -641,8 +642,7 @@ testTracker.clearTrackedAttribute(); testTracker.visited(nextAttr); compare(null, - getUnNamespacedNodeName(nextAttr, - isNamespaced(nextAttr)), + getQName(nextAttr), control, test, listener, ATTR_NAME_NOT_FOUND); } } @@ -662,6 +662,17 @@ return aNode.getNodeName(); } + private String getQName(Node aNode) { + return getQName(aNode, isNamespaced(aNode)); + } + + private String getQName(Node aNode, boolean isNamespacedNode) { + if (isNamespacedNode) { + return "{" + aNode.getNamespaceURI() + "}" + aNode.getLocalName(); + } + 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-29 15:36:31 UTC (rev 580) +++ trunk/src/user-guide/XMLUnit-Java.xml 2014-12-29 15:56:36 UTC (rev 581) @@ -1516,7 +1516,10 @@ <row> <entry><literal>CHILD_NODE_NOT_FOUND_ID</literal></entry> <entry>The name of the unmatched node or - <literal>"null"</literal>.</entry> + <literal>"null"</literal>. If the node is an element + inside an XML namespace the name will be QName-like + <literal>{NS-URI}LOCAL-NAME</literal> - in all other + cases it is the node's local name.</entry> </row> <row> <entry><literal>ATTR_SEQUENCE_ID</literal></entry> @@ -1530,7 +1533,11 @@ </row> <row> <entry><literal>ATTR_NAME_NOT_FOUND_ID</literal></entry> - <entry>The attribute's name or <literal>"null"</literal>.</entry> + <entry>The attribute's name or + <literal>"null"</literal>. If the attribute belongs to + an XML namespace the name will be QName-like + <literal>{NS-URI}LOCAL-NAME</literal> - in all other + cases it is the attribute's local name.</entry> </row> <row> <entry><literal>ATTR_VALUE_ID</literal></entry> @@ -3765,6 +3772,15 @@ <itemizedlist> <listitem> + In cases of <literal>ATTR_NAME_NOT_FOUND</literal> and + <literal>CHILD_NODE_NOT_FOUND</literal> differences the + value used to be the local name of the missing attribute + or node. It will now be a QName-like + <literal>{NS-URI}LOCAL-NAME</literal> string if the + attribute or node belonged to an XML namespace. + <ulink + href="https://sourceforge.net/p/xmlunit/bugs/65/">Issue + 65</ulink> </listitem> </itemizedlist> </section> Modified: trunk/tests/java/org/custommonkey/xmlunit/test_DifferenceEngine.java =================================================================== --- trunk/tests/java/org/custommonkey/xmlunit/test_DifferenceEngine.java 2014-12-29 15:36:31 UTC (rev 580) +++ trunk/tests/java/org/custommonkey/xmlunit/test_DifferenceEngine.java 2014-12-29 15:56:36 UTC (rev 581) @@ -621,6 +621,8 @@ String test = "<stuff><?item data?></stuff>"; listenToDifferences(control, test); // mutiple Differences, we only see the last one, missing second element + assertEquals("item", listener.expected); + assertEquals("null", listener.actual); assertEquals("13 difference type", DifferenceConstants.CHILD_NODE_NOT_FOUND_ID, listener.comparingWhat); @@ -629,6 +631,23 @@ assertNull("13th test xpath", listener.testXpath); } + public void testMissingChildNS() throws Exception { + engine = new DifferenceEngine(PSEUDO_DETAILED_DIFF); + String control = "<stuff xmlns=\"http://example.org/\">" + + "<item id=\"1\"/><item id=\"2\"/></stuff>"; + String test = "<stuff xmlns=\"http://example.org/\"><?item data?></stuff>"; + listenToDifferences(control, test); + // mutiple Differences, we only see the last one, missing second element + assertEquals("{http://example.org/}item", listener.expected); + assertEquals("null", listener.actual); + assertEquals("13 difference type", + DifferenceConstants.CHILD_NODE_NOT_FOUND_ID, + listener.comparingWhat); + assertEquals("13th control xpath", "/stuff[1]/item[2]", + listener.controlXpath); + assertNull("13th test xpath", listener.testXpath); + } + public void testXpathLocation14() throws Exception { engine = new DifferenceEngine(PSEUDO_DETAILED_DIFF); String control = "<stuff><thing id=\"1\"/><item id=\"2\"/></stuff>"; @@ -841,10 +860,25 @@ test.setAttribute("baz", "bar"); engine.compare(control, test, listener, null); assertEquals(ATTR_NAME_NOT_FOUND_ID, listener.comparingWhat); + assertEquals("bar", listener.expected); + assertEquals("null", listener.actual); assertEquals("/foo[1]/@bar", listener.controlXpath); assertEquals("/foo[1]", listener.testXpath); } + public void testMissingAttributeNS() throws Exception { + Element control = document.createElement("foo"); + control.setAttributeNS("http://example.org/", "bar", "baz"); + Element test = document.createElement("foo"); + test.setAttributeNS("http://example.org/", "baz", "bar"); + engine.compare(control, test, listener, null); + assertEquals(ATTR_NAME_NOT_FOUND_ID, listener.comparingWhat); + assertEquals("{http://example.org/}bar", listener.expected); + assertEquals("null", listener.actual); + assertEquals("/foo[1]/@bar", listener.controlXpath); + assertEquals("/foo[1]", listener.testXpath); + } + public void testMatchTrackerSetViaConstructor() throws Exception { Element control = document.createElement("foo"); Element test = document.createElement("foo"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |