You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/10/19 17:37:50 UTC

[camel] branch main updated: Migrate from xmlunit-core to xmlunit-assertj to simplify code (#11774)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 1a56b858e85 Migrate from xmlunit-core to xmlunit-assertj to simplify code (#11774)
1a56b858e85 is described below

commit 1a56b858e85d6c18212f1775cda7797b83dd4c3b
Author: Aurélien Pupier <ap...@redhat.com>
AuthorDate: Thu Oct 19 19:37:43 2023 +0200

    Migrate from xmlunit-core to xmlunit-assertj to simplify code (#11774)
    
    * chores use dependency management for xmlunit-core
    
    * it is used in 4 different places
    
    Signed-off-by: Aurélien Pupier <ap...@redhat.com>
    
    * chores: Use xmlunit-assertj instead of xmlunit-core
    
    * Simpler and more compact code
    * Better error message built-in
    
    Signed-off-by: Aurélien Pupier <ap...@redhat.com>
    
    ---------
    
    Signed-off-by: Aurélien Pupier <ap...@redhat.com>
---
 components/camel-jmx/pom.xml                       |  3 +-
 .../org/apache/camel/component/jmx/XmlFixture.java | 18 +++-------
 components/camel-schematron/pom.xml                |  3 +-
 components/camel-xj/pom.xml                        |  3 +-
 .../org/apache/camel/component/xj/XJTestUtils.java | 38 +++++++++-------------
 components/camel-xmlsecurity/pom.xml               |  3 +-
 .../camel/dataformat/xmlsecurity/TestHelper.java   |  8 ++---
 parent/pom.xml                                     |  5 +++
 8 files changed, 31 insertions(+), 50 deletions(-)

diff --git a/components/camel-jmx/pom.xml b/components/camel-jmx/pom.xml
index d2749d1ac27..366b5f9ad97 100644
--- a/components/camel-jmx/pom.xml
+++ b/components/camel-jmx/pom.xml
@@ -64,8 +64,7 @@
         </dependency>
         <dependency>
             <groupId>org.xmlunit</groupId>
-            <artifactId>xmlunit-core</artifactId>
-            <version>${xmlunit-version}</version>
+            <artifactId>xmlunit-assertj3</artifactId>
             <scope>test</scope>
         </dependency>
     </dependencies>
diff --git a/components/camel-jmx/src/test/java/org/apache/camel/component/jmx/XmlFixture.java b/components/camel-jmx/src/test/java/org/apache/camel/component/jmx/XmlFixture.java
index 8ae7c726002..1e1dbd69e20 100644
--- a/components/camel-jmx/src/test/java/org/apache/camel/component/jmx/XmlFixture.java
+++ b/components/camel-jmx/src/test/java/org/apache/camel/component/jmx/XmlFixture.java
@@ -26,11 +26,8 @@ import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
-import org.xmlunit.builder.DiffBuilder;
+import org.xmlunit.assertj3.XmlAssert;
 import org.xmlunit.builder.Input;
-import org.xmlunit.diff.Diff;
-
-import static org.junit.jupiter.api.Assertions.assertFalse;
 
 public final class XmlFixture {
 
@@ -46,15 +43,10 @@ public final class XmlFixture {
     }
 
     public static void assertXMLIgnorePrefix(String aMessage, Source aExpected, Source aActual) throws Exception {
-        Diff diff = DiffBuilder.compare(aExpected).withTest(aActual)
-                .ignoreComments().ignoreWhitespace()
-                .checkForSimilar().build();
-        try {
-            assertFalse(diff.hasDifferences(), aMessage + ":\n" + diff.toString());
-        } catch (Exception t) {
-            dump(aActual);
-            throw t;
-        }
+        XmlAssert.assertThat(aExpected).and(aActual)
+            .ignoreComments()
+            .ignoreWhitespace()
+            .areSimilar();
     }
 
     public static void dump(Source aActual)
diff --git a/components/camel-schematron/pom.xml b/components/camel-schematron/pom.xml
index 6de80b6a45b..513df4d295f 100644
--- a/components/camel-schematron/pom.xml
+++ b/components/camel-schematron/pom.xml
@@ -56,8 +56,7 @@
         </dependency>
         <dependency>
             <groupId>org.xmlunit</groupId>
-            <artifactId>xmlunit-core</artifactId>
-            <version>${xmlunit-version}</version>
+            <artifactId>xmlunit-assertj3</artifactId>
             <scope>test</scope>
         </dependency>
     </dependencies>
diff --git a/components/camel-xj/pom.xml b/components/camel-xj/pom.xml
index 9b541ecd0df..ebc2cd4ff2c 100644
--- a/components/camel-xj/pom.xml
+++ b/components/camel-xj/pom.xml
@@ -61,8 +61,7 @@
         </dependency>
         <dependency>
             <groupId>org.xmlunit</groupId>
-            <artifactId>xmlunit-core</artifactId>
-            <version>${xmlunit-version}</version>
+            <artifactId>xmlunit-assertj3</artifactId>
             <scope>test</scope>
         </dependency>
     </dependencies>
diff --git a/components/camel-xj/src/test/java/org/apache/camel/component/xj/XJTestUtils.java b/components/camel-xj/src/test/java/org/apache/camel/component/xj/XJTestUtils.java
index 906801b535c..b854a087d16 100644
--- a/components/camel-xj/src/test/java/org/apache/camel/component/xj/XJTestUtils.java
+++ b/components/camel-xj/src/test/java/org/apache/camel/component/xj/XJTestUtils.java
@@ -43,11 +43,8 @@ import com.fasterxml.jackson.core.JsonGenerator;
 import com.fasterxml.jackson.core.JsonParser;
 import org.apache.commons.io.IOUtils;
 import org.skyscreamer.jsonassert.JSONAssert;
-import org.xmlunit.builder.DiffBuilder;
+import org.xmlunit.assertj3.XmlAssert;
 import org.xmlunit.builder.Input;
-import org.xmlunit.diff.Diff;
-
-import static org.junit.jupiter.api.Assertions.assertFalse;
 
 final class XJTestUtils {
 
@@ -161,24 +158,19 @@ final class XJTestUtils {
 
         final String expected = IOUtils.toString(referenceFile, StandardCharsets.UTF_8.name());
         final String result = byteArrayOutputStream.toString(StandardCharsets.UTF_8.name());
-
-        final Diff diff = DiffBuilder
-                .compare(Input.fromString(expected))
-                .withTest(Input.fromString(result))
-                .ignoreElementContentWhitespace()
-                .withNodeFilter(toTest -> {
-                    if (toTest instanceof Comment) {
-                        final Comment comment = (Comment) toTest;
-                        final String text = comment.getNodeValue();
-
-                        return text == null || !text.contains("License");
-                    }
-
-                    return true;
-                })
-                .checkForIdentical()
-                .build();
-
-        assertFalse(diff.hasDifferences(), "\nExpected: " + expected + "\n\nGot: " + result + "\n\nDiff: " + diff.toString());
+        XmlAssert.assertThat(Input.fromString(expected))
+            .and(Input.fromString(result))
+            .ignoreElementContentWhitespace()
+            .withNodeFilter(toTest -> {
+                if (toTest instanceof Comment) {
+                    final Comment comment = (Comment) toTest;
+                    final String text = comment.getNodeValue();
+
+                    return text == null || !text.contains("License");
+                }
+
+                return true;
+            })
+            .areIdentical();
     }
 }
diff --git a/components/camel-xmlsecurity/pom.xml b/components/camel-xmlsecurity/pom.xml
index e5127d7ae0d..51cf4487608 100644
--- a/components/camel-xmlsecurity/pom.xml
+++ b/components/camel-xmlsecurity/pom.xml
@@ -96,8 +96,7 @@
         </dependency>
         <dependency>
             <groupId>org.xmlunit</groupId>
-            <artifactId>xmlunit-core</artifactId>
-            <version>${xmlunit-version}</version>
+            <artifactId>xmlunit-assertj3</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
diff --git a/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/TestHelper.java b/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/TestHelper.java
index 9786efdf315..369c8036e0a 100644
--- a/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/TestHelper.java
+++ b/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/TestHelper.java
@@ -38,8 +38,7 @@ import org.apache.xml.security.encryption.XMLCipher;
 import org.apache.xml.security.encryption.XMLEncryptionException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.xmlunit.builder.DiffBuilder;
-import org.xmlunit.diff.Diff;
+import org.xmlunit.assertj3.XmlAssert;
 
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -162,10 +161,7 @@ public class TestHelper {
         assertFalse(hasEncryptedData(inDoc), "The XML message has encrypted data.");
 
         // verify that the decrypted message matches what was sent
-        Diff xmlDiff = DiffBuilder.compare(fragment).withTest(inDoc).checkForIdentical().build();
-
-        assertFalse(xmlDiff.hasDifferences(),
-                "The decrypted document does not match the control document:\n" + xmlDiff.toString());
+        XmlAssert.assertThat(fragment).and(inDoc).areIdentical();
     }
 
     protected void testDecryption(CamelContext context) throws Exception {
diff --git a/parent/pom.xml b/parent/pom.xml
index 6ad3c753e9e..5af17281d64 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -2696,6 +2696,11 @@
                 <type>pom</type>
                 <scope>import</scope>
             </dependency>
+            <dependency>
+                <groupId>org.xmlunit</groupId>
+                <artifactId>xmlunit-assertj3</artifactId>
+                <version>${xmlunit-version}</version>
+            </dependency>
 
             <!-- Netty bom -->
             <dependency>