Migrate netconf-api's use of xmlunit 86/105686/3
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 25 Apr 2023 22:48:11 +0000 (00:48 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 25 Apr 2023 23:12:36 +0000 (01:12 +0200)
This is a rather straighforward migration, pretty much exactly as
documented in the migration guide.

Change-Id: I18f2dce0bf2855af2f7ade48eb449ee9fc9125cc
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
protocol/netconf-api/pom.xml
protocol/netconf-api/src/test/java/org/opendaylight/netconf/api/xml/XmlUtilTest.java

index 06e6686366203d63af95c4ffe4caf1e1287d71ab..4974b380def52036ac2cf231d007d389cf7b035c 100644 (file)
@@ -52,8 +52,7 @@
     </dependency>
     <dependency>
       <groupId>org.xmlunit</groupId>
-      <artifactId>xmlunit-legacy</artifactId>
-      <scope>test</scope>
+      <artifactId>xmlunit-core</artifactId>
     </dependency>
   </dependencies>
 </project>
index f427e7bf3700f395d4a6c9d966a93c9667c84cb6..9fea9256478d4b5fca4a7700dcb306f73831bd8e 100644 (file)
@@ -8,16 +8,19 @@
 package org.opendaylight.netconf.api.xml;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
 
 import java.util.Optional;
-import org.custommonkey.xmlunit.Diff;
-import org.custommonkey.xmlunit.XMLUnit;
 import org.junit.Test;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.xml.sax.SAXParseException;
+import org.xmlunit.builder.DiffBuilder;
+import org.xmlunit.builder.Input;
+import org.xmlunit.builder.Transform;
+import org.xmlunit.diff.DefaultNodeMatcher;
+import org.xmlunit.diff.ElementSelectors;
 
 public class XmlUtilTest {
     private static final String XML_SNIPPET = """
@@ -41,11 +44,14 @@ public class XmlUtilTest {
         document.appendChild(top);
         assertEquals("top", XmlUtil.createDocumentCopy(document).getDocumentElement().getTagName());
 
-        XMLUnit.setIgnoreAttributeOrder(true);
-        XMLUnit.setIgnoreWhitespace(true);
+        final var diff = DiffBuilder.compare(document)
+            .withTest(XML_SNIPPET)
+            .ignoreWhitespace()
+            .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))
+            .checkForSimilar()
+            .build();
 
-        final Diff diff = XMLUnit.compareXML(XMLUnit.buildControlDocument(XML_SNIPPET), document);
-        assertTrue(diff.toString(), diff.similar());
+        assertFalse(diff.toString(), diff.hasDifferences());
     }
 
     @Test
@@ -76,6 +82,6 @@ public class XmlUtilTest {
             </users>
             """;
 
-        assertEquals(input, XmlUtil.toString(XMLUnit.buildControlDocument(input)));
+        assertEquals(input, XmlUtil.toString(Transform.source(Input.from(input).build()).build().toDocument()));
     }
 }