Reenable netconf-notifications-impl xml tests 38/16638/1
authorMaros Marsalek <mmarsale@cisco.com>
Mon, 16 Mar 2015 13:20:02 +0000 (14:20 +0100)
committerMaros Marsalek <mmarsale@cisco.com>
Mon, 16 Mar 2015 13:29:49 +0000 (14:29 +0100)
The tests were disabled due to improper configuration for XMLUtil.
The configuration is fine now.

Change-Id: I59fe1081ac927596fc55079e62088cceb5b52811
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
opendaylight/netconf/netconf-notifications-impl/src/test/java/org/opendaylight/controller/netconf/notifications/impl/ops/GetTest.java
opendaylight/netconf/netconf-notifications-impl/src/test/java/org/opendaylight/controller/netconf/notifications/impl/ops/NotificationsTransformUtilTest.java

index 6f38f24f10c02e3e6dac9c7147fb24104f2ba9db..05ed9bf006f79c2cc7937da1e7064f5d76364d6b 100644 (file)
@@ -8,14 +8,9 @@
 
 package org.opendaylight.controller.netconf.notifications.impl.ops;
 
-import static org.junit.Assert.assertTrue;
-
 import com.google.common.collect.Lists;
 import java.io.IOException;
-import org.custommonkey.xmlunit.Diff;
-import org.custommonkey.xmlunit.XMLUnit;
 import org.junit.Test;
-import org.opendaylight.controller.netconf.notifications.impl.ops.Get;
 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.Streams;
@@ -41,22 +36,20 @@ public class GetTest {
 
         final Document response = getBlankResponse();
         Get.serializeStreamsSubtree(response, streams);
-        final Diff diff = XMLUnit.compareXML(XmlUtil.toString(response),
+        NotificationsTransformUtilTest.compareXml(XmlUtil.toString(response),
                 "<rpc-reply message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
-                "<data>\n" +
-                "<netconf xmlns=\"urn:ietf:params:xml:ns:netmod:notification\">\n" +
-                "<streams>\n" +
-                "<stream>\n" +
-                "<name>base</name>\n" +
-                "<description>description</description>\n" +
-                "<replaySupport>false</replaySupport>\n" +
-                "</stream>\n" +
-                "</streams>\n" +
-                "</netconf>\n" +
-                "</data>\n" +
-                "</rpc-reply>\n");
-
-        assertTrue(diff.toString(), diff.identical());
+                        "<data>\n" +
+                        "<netconf xmlns=\"urn:ietf:params:xml:ns:netmod:notification\">\n" +
+                        "<streams>\n" +
+                        "<stream>\n" +
+                        "<name>base</name>\n" +
+                        "<description>description</description>\n" +
+                        "<replaySupport>false</replaySupport>\n" +
+                        "</stream>\n" +
+                        "</streams>\n" +
+                        "</netconf>\n" +
+                        "</data>\n" +
+                        "</rpc-reply>\n");
     }
 
     private Document getBlankResponse() throws IOException, SAXException {
index b63e0877b207ab66d55e5cbd92727f08ac73c762..7bb213ab46942578e4fdce191a5c7a3eb0436d79 100644 (file)
@@ -8,24 +8,30 @@
 
 package org.opendaylight.controller.netconf.notifications.impl.ops;
 
+import static org.junit.Assert.assertTrue;
+
 import com.google.common.collect.Lists;
+import java.io.IOException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import org.custommonkey.xmlunit.DetailedDiff;
 import org.custommonkey.xmlunit.Diff;
 import org.custommonkey.xmlunit.XMLUnit;
+import org.custommonkey.xmlunit.examples.RecursiveElementNameAndTextQualifier;
 import org.junit.Test;
 import org.opendaylight.controller.netconf.notifications.NetconfNotification;
 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChangeBuilder;
+import org.xml.sax.SAXException;
 
 public class NotificationsTransformUtilTest {
 
     private static final Date DATE = new Date();
     private static final String innerNotification = "<netconf-capability-change xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-notifications\">" +
-            "<deleted-capability>uri3</deleted-capability>" +
             "<deleted-capability>uri4</deleted-capability>" +
+            "<deleted-capability>uri3</deleted-capability>" +
             "<added-capability>uri1</added-capability>" +
             "</netconf-capability-change>";
 
@@ -39,17 +45,22 @@ public class NotificationsTransformUtilTest {
         final NetconfCapabilityChangeBuilder netconfCapabilityChangeBuilder = new NetconfCapabilityChangeBuilder();
 
         netconfCapabilityChangeBuilder.setAddedCapability(Lists.newArrayList(new Uri("uri1"), new Uri("uri1")));
-        netconfCapabilityChangeBuilder.setDeletedCapability(Lists.newArrayList(new Uri("uri3"), new Uri("uri4")));
+        netconfCapabilityChangeBuilder.setDeletedCapability(Lists.newArrayList(new Uri("uri4"), new Uri("uri3")));
 
         final NetconfCapabilityChange capabilityChange = netconfCapabilityChangeBuilder.build();
         final NetconfNotification transform = NotificationsTransformUtil.transform(capabilityChange, DATE);
 
         final String serialized = XmlUtil.toString(transform.getDocument());
 
+        compareXml(expectedNotification, serialized);
+    }
+
+    static void compareXml(final String expected, final String actual) throws SAXException, IOException {
         XMLUnit.setIgnoreWhitespace(true);
-        final Diff diff = XMLUnit.compareXML(expectedNotification, serialized);
-        // FIXME the diff is unreliable, provide a proper comparison of XML
-//        assertTrue(diff.toString(), diff.similar());
+        final Diff diff = new Diff(expected, actual);
+        final DetailedDiff detailedDiff = new DetailedDiff(diff);
+        detailedDiff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier());
+        assertTrue(detailedDiff.toString(), detailedDiff.similar());
     }
 
     @Test
@@ -57,9 +68,7 @@ public class NotificationsTransformUtilTest {
         final NetconfNotification netconfNotification = new NetconfNotification(XmlUtil.readXmlToDocument(innerNotification), DATE);
 
         XMLUnit.setIgnoreWhitespace(true);
-        final Diff diff = XMLUnit.compareXML(expectedNotification, netconfNotification.toString());
-        // FIXME the diff is unreliable, provide a proper comparison of XML
-//        assertTrue(diff.toString(), diff.similar());
+        compareXml(expectedNotification, netconfNotification.toString());
     }
 
 }
\ No newline at end of file