From 5627c1cfe8b8d9c3fc9ec6596c60a67e26e54cbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Pupier?= Date: Thu, 19 Oct 2023 09:12:52 +0200 Subject: [PATCH 1/2] chores use dependency management for xmlunit-core MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * it is used in 4 different places Signed-off-by: Aurélien Pupier --- components/camel-jmx/pom.xml | 1 - components/camel-schematron/pom.xml | 1 - components/camel-xj/pom.xml | 1 - components/camel-xmlsecurity/pom.xml | 1 - parent/pom.xml | 5 +++++ 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/components/camel-jmx/pom.xml b/components/camel-jmx/pom.xml index d2749d1ac27dc..27ce319f20f1b 100644 --- a/components/camel-jmx/pom.xml +++ b/components/camel-jmx/pom.xml @@ -65,7 +65,6 @@ org.xmlunit xmlunit-core - ${xmlunit-version} test diff --git a/components/camel-schematron/pom.xml b/components/camel-schematron/pom.xml index 6de80b6a45b46..74f64a5be8f03 100644 --- a/components/camel-schematron/pom.xml +++ b/components/camel-schematron/pom.xml @@ -57,7 +57,6 @@ org.xmlunit xmlunit-core - ${xmlunit-version} test diff --git a/components/camel-xj/pom.xml b/components/camel-xj/pom.xml index 9b541ecd0dfe4..d69086d9a04af 100644 --- a/components/camel-xj/pom.xml +++ b/components/camel-xj/pom.xml @@ -62,7 +62,6 @@ org.xmlunit xmlunit-core - ${xmlunit-version} test diff --git a/components/camel-xmlsecurity/pom.xml b/components/camel-xmlsecurity/pom.xml index e5127d7ae0d22..57954ff58112d 100644 --- a/components/camel-xmlsecurity/pom.xml +++ b/components/camel-xmlsecurity/pom.xml @@ -97,7 +97,6 @@ org.xmlunit xmlunit-core - ${xmlunit-version} test diff --git a/parent/pom.xml b/parent/pom.xml index c4de9d7a06769..af3091e47fa64 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -2697,6 +2697,11 @@ pom import + + org.xmlunit + xmlunit-core + ${xmlunit-version} + From 16c4a25b2e44cc1c304baff40ea6596636b7604b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Pupier?= Date: Thu, 19 Oct 2023 14:30:36 +0200 Subject: [PATCH 2/2] chores: Use xmlunit-assertj instead of xmlunit-core MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Simpler and more compact code * Better error message built-in Signed-off-by: Aurélien Pupier --- components/camel-jmx/pom.xml | 2 +- .../camel/component/jmx/XmlFixture.java | 18 +++------ components/camel-schematron/pom.xml | 2 +- components/camel-xj/pom.xml | 2 +- .../camel/component/xj/XJTestUtils.java | 38 ++++++++----------- components/camel-xmlsecurity/pom.xml | 2 +- .../dataformat/xmlsecurity/TestHelper.java | 8 +--- parent/pom.xml | 2 +- 8 files changed, 27 insertions(+), 47 deletions(-) diff --git a/components/camel-jmx/pom.xml b/components/camel-jmx/pom.xml index 27ce319f20f1b..366b5f9ad97e9 100644 --- a/components/camel-jmx/pom.xml +++ b/components/camel-jmx/pom.xml @@ -64,7 +64,7 @@ org.xmlunit - xmlunit-core + xmlunit-assertj3 test 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 8ae7c726002dc..1e1dbd69e2099 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.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 static Source toSource(File aFile) { } 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 74f64a5be8f03..513df4d295f69 100644 --- a/components/camel-schematron/pom.xml +++ b/components/camel-schematron/pom.xml @@ -56,7 +56,7 @@ org.xmlunit - xmlunit-core + xmlunit-assertj3 test diff --git a/components/camel-xj/pom.xml b/components/camel-xj/pom.xml index d69086d9a04af..ebc2cd4ff2c3d 100644 --- a/components/camel-xj/pom.xml +++ b/components/camel-xj/pom.xml @@ -61,7 +61,7 @@ org.xmlunit - xmlunit-core + xmlunit-assertj3 test 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 906801b535c97..b854a087d1637 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.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 @@ static void transformJson2XmlAndCompare(String xsl, String testName) throws Exce 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 57954ff58112d..51cf448760892 100644 --- a/components/camel-xmlsecurity/pom.xml +++ b/components/camel-xmlsecurity/pom.xml @@ -96,7 +96,7 @@ org.xmlunit - xmlunit-core + xmlunit-assertj3 test 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 9786efdf315de..369c8036e0aa7 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.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 @@ protected void testDecryption(String fragment, CamelContext context) throws Exce 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 af3091e47fa64..297f3e220e45e 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -2699,7 +2699,7 @@ org.xmlunit - xmlunit-core + xmlunit-assertj3 ${xmlunit-version}