[xmlsectool] branch master updated: XSTJ-71 - migrate away from legacy xmlunit API

Ian Young ian at iay.org.uk
Tue Mar 13 12:16:55 EDT 2018


This is an automated email from the git hooks/post-receive script.

iay pushed a commit to branch master
in repository xmlsectool.

View the commit online:
http://git.shibboleth.net/view/?p=xmlsectool.git;a=commit;h=3a4e210d6113082b6b220e5f345d51cc71549a89

The following commit(s) were added to refs/heads/master by this push:
       new  3a4e210   XSTJ-71 - migrate away from legacy xmlunit API
3a4e210 is described below

commit 3a4e210d6113082b6b220e5f345d51cc71549a89
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Tue Mar 13 16:16:50 2018 +0000

    XSTJ-71 - migrate away from legacy xmlunit API
---
 pom.xml                                            |  2 +-
 .../net/shibboleth/tool/xmlsectool/BaseTest.java   | 43 +++++++++++++++++-----
 2 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/pom.xml b/pom.xml
index 70fd61a..2f3459e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -119,7 +119,7 @@
         <!-- Test Dependencies -->
         <dependency>
             <groupId>org.xmlunit</groupId>
-            <artifactId>xmlunit-legacy</artifactId>
+            <artifactId>xmlunit-core</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
diff --git a/src/test/java/net/shibboleth/tool/xmlsectool/BaseTest.java b/src/test/java/net/shibboleth/tool/xmlsectool/BaseTest.java
index b6ba682..1ea28a1 100644
--- a/src/test/java/net/shibboleth/tool/xmlsectool/BaseTest.java
+++ b/src/test/java/net/shibboleth/tool/xmlsectool/BaseTest.java
@@ -29,9 +29,8 @@ import java.security.cert.CertificateException;
 import java.util.MissingResourceException;
 
 import javax.annotation.Nonnull;
+import javax.xml.transform.Source;
 
-import org.custommonkey.xmlunit.Diff;
-import org.custommonkey.xmlunit.XMLUnit;
 import org.opensaml.core.config.InitializationException;
 import org.opensaml.security.SecurityProviderTestSupport;
 import org.opensaml.security.x509.X509Credential;
@@ -42,12 +41,17 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
+import org.xmlunit.builder.DiffBuilder;
+import org.xmlunit.builder.Input;
+import org.xmlunit.diff.Diff;
+import org.xmlunit.input.NormalizedSource;
 
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
 import net.shibboleth.utilities.java.support.logic.Constraint;
 import net.shibboleth.utilities.java.support.primitive.StringSupport;
 import net.shibboleth.utilities.java.support.xml.BasicParserPool;
 import net.shibboleth.utilities.java.support.xml.ParserPool;
+import net.shibboleth.utilities.java.support.xml.SerializeSupport;
 import net.shibboleth.utilities.java.support.xml.XMLParserException;
 
 public abstract class BaseTest {
@@ -181,7 +185,6 @@ public abstract class BaseTest {
     @BeforeClass
     public void setUp() throws ComponentInitializationException, InitializationException {
         InitializationSupport.initialize();
-        XMLUnit.setIgnoreWhitespace(true);
 
         parserPool = new BasicParserPool();
         parserPool.initialize();
@@ -223,18 +226,40 @@ public abstract class BaseTest {
     }
 
     /**
-     * Checks whether two nodes are identical based on {@link Diff#identical()}.
-     * 
+     * Checks whether two nodes are identical.
+     *
+     * The only variation that is permitted for the purpose of comparison is that
+     * adjacent text nodes will be coalesced.
+     *
+     * Tests requiring other semantics should call XMLUnit directly.
+     *
      * @param expected the expected node against which the actual node will be tested, never null
      * @param actual the actual node tested against the expected node, never null
      */
-    public void assertXMLIdentical(Node expected, Node actual) {
+    public void assertXMLIdentical(@Nonnull final Node expected, @Nonnull final Node actual) {
         Constraint.isNotNull(expected, "Expected Node may not be null");
         Constraint.isNotNull(actual, "Actual Node may not be null");
 
-        Diff diff = new Diff(expected.getOwnerDocument(), actual.getOwnerDocument());
-        if (!diff.identical()) {
-            org.testng.Assert.fail(diff.toString());
+        /*
+         * Normalize empty and adjacent text nodes within the source nodes.
+         *
+         * Don't try to simplify this by passing expected and actual directly to the
+         * NormalizedSource(Node) constructor. That's much faster, as the constructor just
+         * normalizes the provided node, but by the same token it causes the original
+         * node to be changed, and side-effects are undesirable in a general-use method
+         * like this one.
+         */
+        final Source expectedSource = new NormalizedSource(Input.fromNode(expected).build());
+        final Source actualSource = new NormalizedSource(Input.fromNode(actual).build());
+
+        final Diff diff = DiffBuilder.compare(expectedSource).withTest(actualSource)
+                .checkForIdentical()
+                .build();
+
+        if (diff.hasDifferences()) {
+            System.out.println("Expected:\n" + SerializeSupport.nodeToString(expected));
+            System.out.println("Actual:\n" + SerializeSupport.nodeToString(actual));
+            Assert.fail(diff.toString());
         }
     }
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list