Repository: camel Updated Branches: refs/heads/master ddf7c9f7d -> 1ea6abadc
Upgrade xmlunit to version 2.3.0 Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1ea6abad Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1ea6abad Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1ea6abad Branch: refs/heads/master Commit: 1ea6abadcac7b538091340690fb53bf12fc169d8 Parents: ddf7c9f Author: Pascal Schumacher <pascalschumac...@gmx.net> Authored: Sun Jul 16 20:36:02 2017 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Sun Jul 16 21:34:40 2017 +0200 ---------------------------------------------------------------------- components/camel-jmx/pom.xml | 4 +- .../component/jmx/MockEndpointFixture.java | 38 +++------ .../apache/camel/component/jmx/XmlFixture.java | 85 ++++++-------------- components/camel-schematron/pom.xml | 6 +- .../camel/component/schematron/util/Utils.java | 21 ++--- components/camel-spring/pom.xml | 4 +- .../spring/CamelContextFactoryBeanTest.java | 32 ++------ components/camel-xmlsecurity/pom.xml | 4 +- .../dataformat/xmlsecurity/TestHelper.java | 20 ++--- parent/pom.xml | 2 +- 10 files changed, 69 insertions(+), 147 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/1ea6abad/components/camel-jmx/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-jmx/pom.xml b/components/camel-jmx/pom.xml index d107bb2..550cb90 100644 --- a/components/camel-jmx/pom.xml +++ b/components/camel-jmx/pom.xml @@ -69,8 +69,8 @@ <scope>test</scope> </dependency> <dependency> - <groupId>xmlunit</groupId> - <artifactId>xmlunit</artifactId> + <groupId>org.xmlunit</groupId> + <artifactId>xmlunit-core</artifactId> <version>${xmlunit-version}</version> <scope>test</scope> </dependency> http://git-wip-us.apache.org/repos/asf/camel/blob/1ea6abad/components/camel-jmx/src/test/java/org/apache/camel/component/jmx/MockEndpointFixture.java ---------------------------------------------------------------------- diff --git a/components/camel-jmx/src/test/java/org/apache/camel/component/jmx/MockEndpointFixture.java b/components/camel-jmx/src/test/java/org/apache/camel/component/jmx/MockEndpointFixture.java index e9f79f0..ca3c34d 100644 --- a/components/camel-jmx/src/test/java/org/apache/camel/component/jmx/MockEndpointFixture.java +++ b/components/camel-jmx/src/test/java/org/apache/camel/component/jmx/MockEndpointFixture.java @@ -17,20 +17,16 @@ package org.apache.camel.component.jmx; import java.io.File; -import java.util.Iterator; +import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; -import javax.xml.namespace.NamespaceContext; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathExpressionException; -import javax.xml.xpath.XPathFactory; - -import org.w3c.dom.Document; +import javax.xml.transform.Source; import org.apache.camel.Exchange; import org.apache.camel.Message; import org.apache.camel.component.mock.MockEndpoint; +import org.xmlunit.xpath.JAXPXPathEngine; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -67,38 +63,26 @@ public class MockEndpointFixture { * Assert that we've received the message and resets the mock endpoint */ protected void assertMessageReceived(File aExpectedFile) throws Exception { - Document expectedDoc = XmlFixture.toDoc(aExpectedFile); + Source expectedDoc = XmlFixture.toSource(aExpectedFile); assertMessageReceived(expectedDoc); } - protected void assertMessageReceived(Document aExpectedDoc) throws Exception { - Document actual = XmlFixture.toDoc(getBody(0, String.class)); + protected void assertMessageReceived(Source aExpectedDoc) throws Exception { + Source actual = XmlFixture.toSource(getBody(0, String.class)); assertMessageReceived(aExpectedDoc, actual); } - protected void assertMessageReceived(Document aExpectedDoc, Document aActual) throws Exception, - XPathExpressionException { - Document noTime = XmlFixture.stripTimestamp(aActual); - Document noUUID = XmlFixture.stripUUID(noTime); + protected void assertMessageReceived(Source aExpectedDoc, Source aActual) throws Exception { + Source noTime = XmlFixture.stripTimestamp(aActual); + Source noUUID = XmlFixture.stripUUID(noTime); XmlFixture.assertXMLIgnorePrefix("failed to match", aExpectedDoc, noUUID); // assert that we have a timestamp and datetime // can't rely on the datetime being the same due to timezone differences // instead, we'll assert that the values exist. - XPathFactory xpf = XPathFactory.newInstance(); - XPath xp = xpf.newXPath(); - xp.setNamespaceContext(new NamespaceContext() { - public String getNamespaceURI(String aArg0) { - return "urn:org.apache.camel.component:jmx"; - } - public String getPrefix(String aArg0) { - return "jmx"; - } - public Iterator<Object> getPrefixes(String aArg0) { - return null; - } - }); + JAXPXPathEngine xp = new JAXPXPathEngine(); + xp.setNamespaceContext(Collections.singletonMap("jmx", "urn:org.apache.camel.component:jmx")); assertEquals("1", xp.evaluate("count(//jmx:timestamp)", aActual)); assertEquals("1", xp.evaluate("count(//jmx:dateTime)", aActual)); resetMockEndpoint(); http://git-wip-us.apache.org/repos/asf/camel/blob/1ea6abad/components/camel-jmx/src/test/java/org/apache/camel/component/jmx/XmlFixture.java ---------------------------------------------------------------------- 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 c939c8a..2a943eb 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 @@ -16,10 +16,9 @@ */ package org.apache.camel.component.jmx; +import static org.junit.Assert.assertFalse; + import java.io.File; -import java.io.InputStream; -import java.io.PrintWriter; -import java.io.StringWriter; import javax.xml.transform.OutputKeys; import javax.xml.transform.Source; @@ -27,92 +26,60 @@ import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMResult; -import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.xml.sax.InputSource; - -import org.custommonkey.xmlunit.Diff; -import org.custommonkey.xmlunit.Difference; -import org.custommonkey.xmlunit.DifferenceConstants; -import org.custommonkey.xmlunit.DifferenceListener; -import org.custommonkey.xmlunit.XMLAssert; -import org.custommonkey.xmlunit.XMLUnit; - -import static org.junit.Assert.fail; +import org.xmlunit.builder.DiffBuilder; +import org.xmlunit.builder.Input; +import org.xmlunit.diff.Diff; public final class XmlFixture { private XmlFixture() { } - public static Document toDoc(String aXmlString) throws Exception { - return XMLUnit.buildControlDocument(aXmlString); + public static Source toSource(String aXmlString) throws Exception { + return Input.fromString(aXmlString).build(); } - public static Document toDoc(File aFile) throws Exception { - return XMLUnit.buildControlDocument(new InputSource(aFile.toString())); + public static Source toSource(File aFile) throws Exception { + return Input.fromFile(aFile).build(); } - public static void assertXMLIgnorePrefix(String aMessage, Document aExpected, Document aActual) throws Exception { - XMLUnit.setIgnoreComments(true); - XMLUnit.setIgnoreWhitespace(true); - XMLUnit.setIgnoreAttributeOrder(true); - - Diff diff = new Diff(aExpected, aActual); - diff.overrideDifferenceListener(new DifferenceListener() { - - public void skippedComparison(Node aArg0, Node aArg1) { - } - - public int differenceFound(Difference aDifference) { - if (aDifference.getId() == DifferenceConstants.NAMESPACE_PREFIX_ID) { - return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL; - } - return DifferenceListener.RETURN_ACCEPT_DIFFERENCE; - } - }); + public static void assertXMLIgnorePrefix(String aMessage, Source aExpected, Source aActual) throws Exception { + Diff diff = DiffBuilder.compare(aExpected).withTest(aActual) + .ignoreComments().ignoreWhitespace() + .checkForSimilar().build(); try { - XMLAssert.assertXMLEqual(diff, true); + assertFalse(aMessage + ":\n" + diff.toString(), diff.hasDifferences()); } catch (Throwable t) { dump(aActual); - StringWriter sw = new StringWriter(); - t.printStackTrace(new PrintWriter(sw)); - fail(sw.toString()); + throw t; } } - public static void dump(Document aActual) throws TransformerConfigurationException, + public static void dump(Source aActual) throws TransformerConfigurationException, TransformerException { - TransformerFactory tf = XMLUnit.getTransformerFactory(); + TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); - transformer.transform(new DOMSource(aActual), new StreamResult(System.out)); + transformer.transform(aActual, new StreamResult(System.out)); } - public static Document stripTimestamp(Document aDocument) throws Exception { + public static Source stripTimestamp(Source aSource) throws Exception { String resourcePath = "/stripTimestamp.xsl"; - return transform(aDocument, resourcePath); + return transform(aSource, resourcePath); } - public static Document stripUUID(Document aDocument) throws Exception { + public static Source stripUUID(Source aSource) throws Exception { String resourcePath = "/stripUUID.xsl"; - return transform(aDocument, resourcePath); + return transform(aSource, resourcePath); } - protected static Document transform(Document aDocument, String aResourcePath) throws Exception { - TransformerFactory tf = TransformerFactory.newInstance(); - InputStream in = XmlFixture.class.getResourceAsStream(aResourcePath); - Source src = new StreamSource(in); - src.setSystemId(XmlFixture.class.getResource(aResourcePath).toExternalForm()); - Transformer t = tf.newTransformer(src); - DOMResult result = new DOMResult(); - t.transform(new DOMSource(aDocument), result); - return (Document) result.getNode(); + protected static Source transform(Source aSource, String aResourcePath) throws Exception { + Source stylesheet = new StreamSource(XmlFixture.class.getResourceAsStream(aResourcePath)); + stylesheet.setSystemId(XmlFixture.class.getResource(aResourcePath).toExternalForm()); + return Input.byTransforming(aSource).withStylesheet(stylesheet).build(); } } http://git-wip-us.apache.org/repos/asf/camel/blob/1ea6abad/components/camel-schematron/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-schematron/pom.xml b/components/camel-schematron/pom.xml index 70156da..18ba73b 100644 --- a/components/camel-schematron/pom.xml +++ b/components/camel-schematron/pom.xml @@ -60,11 +60,11 @@ <scope>test</scope> </dependency> <dependency> - <groupId>xmlunit</groupId> - <artifactId>xmlunit</artifactId> + <groupId>org.xmlunit</groupId> + <artifactId>xmlunit-core</artifactId> <version>${xmlunit-version}</version> <scope>test</scope> - </dependency> + </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> http://git-wip-us.apache.org/repos/asf/camel/blob/1ea6abad/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/util/Utils.java ---------------------------------------------------------------------- diff --git a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/util/Utils.java b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/util/Utils.java index 18fd576..b2b1992 100644 --- a/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/util/Utils.java +++ b/components/camel-schematron/src/test/java/org/apache/camel/component/schematron/util/Utils.java @@ -16,16 +16,14 @@ */ package org.apache.camel.component.schematron.util; -import java.util.HashMap; -import java.util.Map; +import java.util.Collections; import org.apache.camel.RuntimeCamelException; import org.apache.camel.component.schematron.constant.Constants; -import org.custommonkey.xmlunit.SimpleNamespaceContext; -import org.custommonkey.xmlunit.XMLUnit; -import org.custommonkey.xmlunit.XpathEngine; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.xmlunit.builder.Input; +import org.xmlunit.xpath.JAXPXPathEngine; /** * Utility Class. @@ -40,19 +38,12 @@ public final class Utils { /** * Evaluate an XPATH expression. - * - * @param xpath - * @param xml - * @return */ public static String evaluate(final String xpath, final String xml) { - Map<String, Object> m = new HashMap<String, Object>(); - m.put("svrl", Constants.HTTP_PURL_OCLC_ORG_DSDL_SVRL); - XpathEngine xpathEngine = XMLUnit.newXpathEngine(); - xpathEngine.setNamespaceContext(new SimpleNamespaceContext(m)); + JAXPXPathEngine xpathEngine = new JAXPXPathEngine(); + xpathEngine.setNamespaceContext(Collections.singletonMap("svrl", Constants.HTTP_PURL_OCLC_ORG_DSDL_SVRL)); try { - return xpathEngine.evaluate(xpath, XMLUnit.buildControlDocument(xml)); - + return xpathEngine.evaluate(xpath, Input.fromString(xml).build()); } catch (Exception e) { LOG.error("Failed to apply xpath {} on xml {}", xpath, xml); throw new RuntimeCamelException(e); http://git-wip-us.apache.org/repos/asf/camel/blob/1ea6abad/components/camel-spring/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-spring/pom.xml b/components/camel-spring/pom.xml index c7970b6..9e612e3 100644 --- a/components/camel-spring/pom.xml +++ b/components/camel-spring/pom.xml @@ -169,8 +169,8 @@ <scope>test</scope> </dependency> <dependency> - <groupId>xmlunit</groupId> - <artifactId>xmlunit</artifactId> + <groupId>org.xmlunit</groupId> + <artifactId>xmlunit-core</artifactId> <version>${xmlunit-version}</version> <scope>test</scope> </dependency> http://git-wip-us.apache.org/repos/asf/camel/blob/1ea6abad/components/camel-spring/src/test/java/org/apache/camel/spring/CamelContextFactoryBeanTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/CamelContextFactoryBeanTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/CamelContextFactoryBeanTest.java index 5b300aa..f61bd33 100644 --- a/components/camel-spring/src/test/java/org/apache/camel/spring/CamelContextFactoryBeanTest.java +++ b/components/camel-spring/src/test/java/org/apache/camel/spring/CamelContextFactoryBeanTest.java @@ -16,13 +16,9 @@ */ package org.apache.camel.spring; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; +import java.net.URL; import java.util.LinkedList; import java.util.List; -import javax.xml.bind.JAXBContext; import junit.framework.TestCase; import org.apache.camel.impl.DefaultModelJAXBContextFactory; @@ -30,10 +26,10 @@ import org.apache.camel.impl.DefaultUuidGenerator; import org.apache.camel.impl.SimpleUuidGenerator; import org.apache.camel.spi.ModelJAXBContextFactory; import org.apache.camel.spi.UuidGenerator; -import org.apache.camel.util.IOHelper; -import org.custommonkey.xmlunit.XMLAssert; -import org.custommonkey.xmlunit.XMLUnit; import org.springframework.context.support.StaticApplicationContext; +import org.xmlunit.builder.DiffBuilder; +import org.xmlunit.builder.Input; +import org.xmlunit.diff.Diff; /** * @version @@ -80,22 +76,10 @@ public class CamelContextFactoryBeanTest extends TestCase { camelContext.setEndpoints(endpoints); // Compare the new context with our reference context - Reader expectedContext = null; - try { - expectedContext = new InputStreamReader(getClass().getResourceAsStream("/org/apache/camel/spring/context-with-endpoint.xml")); - String createdContext = contextAsString(camelContext); - XMLUnit.setIgnoreWhitespace(true); - XMLAssert.assertXMLEqual(expectedContext, new StringReader(createdContext)); - } finally { - IOHelper.close(expectedContext); - } - } - - private String contextAsString(CamelContextFactoryBean context) throws Exception { - StringWriter stringOut = new StringWriter(); - JAXBContext jaxb = JAXBContext.newInstance(CamelContextFactoryBean.class); - jaxb.createMarshaller().marshal(context, stringOut); - return stringOut.toString(); + URL expectedContext = getClass().getResource("/org/apache/camel/spring/context-with-endpoint.xml"); + Diff diff = DiffBuilder.compare(expectedContext).withTest(Input.fromJaxb(camelContext)) + .ignoreWhitespace().ignoreComments().checkForSimilar().build(); + assertFalse("Expected context and actual context differ:\n" + diff.toString(), diff.hasDifferences()); } public void testCustomModelJAXBContextFactory() throws Exception { http://git-wip-us.apache.org/repos/asf/camel/blob/1ea6abad/components/camel-xmlsecurity/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-xmlsecurity/pom.xml b/components/camel-xmlsecurity/pom.xml index 439a3a6..dc1797c 100755 --- a/components/camel-xmlsecurity/pom.xml +++ b/components/camel-xmlsecurity/pom.xml @@ -95,8 +95,8 @@ <scope>test</scope> </dependency> <dependency> - <groupId>xmlunit</groupId> - <artifactId>xmlunit</artifactId> + <groupId>org.xmlunit</groupId> + <artifactId>xmlunit-core</artifactId> <version>${xmlunit-version}</version> <scope>test</scope> </dependency> http://git-wip-us.apache.org/repos/asf/camel/blob/1ea6abad/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/TestHelper.java ---------------------------------------------------------------------- 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 0fff673..587deb1 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 @@ -23,8 +23,6 @@ import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; -import org.w3c.dom.Document; -import org.w3c.dom.NodeList; import org.apache.camel.CamelContext; import org.apache.camel.Exchange; import org.apache.camel.Message; @@ -34,16 +32,17 @@ import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.converter.jaxp.XmlConverter; import org.apache.xml.security.encryption.XMLCipher; import org.apache.xml.security.encryption.XMLEncryptionException; -import org.custommonkey.xmlunit.Diff; -import org.custommonkey.xmlunit.XMLUnit; import org.junit.Assert; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; +import org.xmlunit.builder.DiffBuilder; +import org.xmlunit.diff.Diff; public class TestHelper { - protected static final String NS_XML_FRAGMENT = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" - + "<ns1:cheesesites xmlns:ns1=\"http://cheese.xmlsecurity.camel.apache.org/\">" + protected static final String NS_XML_FRAGMENT = "<ns1:cheesesites xmlns:ns1=\"http://cheese.xmlsecurity.camel.apache.org/\">" + "<netherlands>" + "<source>cow</source>" + "<cheese>gouda</cheese>" @@ -58,8 +57,7 @@ public class TestHelper { + "</france>" + "</ns1:cheesesites>"; - protected static final String XML_FRAGMENT = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" - + "<cheesesites>" + protected static final String XML_FRAGMENT = "<cheesesites>" + "<netherlands>" + "<source>cow</source>" + "<cheese>gouda</cheese>" @@ -144,7 +142,6 @@ public class TestHelper { testEncryption(XML_FRAGMENT, context); } - protected void testDecryption(String fragment, CamelContext context) throws Exception { MockEndpoint resultEndpoint = context.getEndpoint("mock:decrypted", MockEndpoint.class); resultEndpoint.setExpectedMessageCount(1); @@ -160,10 +157,9 @@ public class TestHelper { Assert.assertFalse("The XML message has encrypted data.", hasEncryptedData(inDoc)); // verify that the decrypted message matches what was sent - Document fragmentDoc = createDocumentfromInputStream(new ByteArrayInputStream(fragment.getBytes()), context); - Diff xmlDiff = XMLUnit.compareXML(fragmentDoc, inDoc); + Diff xmlDiff = DiffBuilder.compare(fragment).withTest(inDoc).checkForIdentical().build(); - Assert.assertTrue("The decrypted document does not match the control document.", xmlDiff.identical()); + Assert.assertFalse("The decrypted document does not match the control document:\n" + xmlDiff.toString(), xmlDiff.hasDifferences()); } protected void testDecryption(CamelContext context) throws Exception { http://git-wip-us.apache.org/repos/asf/camel/blob/1ea6abad/parent/pom.xml ---------------------------------------------------------------------- diff --git a/parent/pom.xml b/parent/pom.xml index a596664..41e279e 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -711,7 +711,7 @@ <xmlrpc-version>3.1.3</xmlrpc-version> <xmlrpc-client-bundle-version>3.1.3_1</xmlrpc-client-bundle-version> <xmlsec-version>2.0.8</xmlsec-version> - <xmlunit-version>1.6</xmlunit-version> + <xmlunit-version>2.3.0</xmlunit-version> <xpp3-bundle-version>1.1.4c_7</xpp3-bundle-version> <xpp3-version>1.1.4c</xpp3-version> <xsdlib-version>2013.2</xsdlib-version>