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 2022/04/20 12:11:49 UTC
[camel] branch main updated: CAMEL-17985: added unit test for XsltUriResolver using ref: scheme (#7469)
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 d6299c626d5 CAMEL-17985: added unit test for XsltUriResolver using ref: scheme (#7469)
d6299c626d5 is described below
commit d6299c626d5cfef2b031f9396a5b931340e3edb8
Author: Bruno Mendola <18...@users.noreply.github.com>
AuthorDate: Wed Apr 20 14:11:38 2022 +0200
CAMEL-17985: added unit test for XsltUriResolver using ref: scheme (#7469)
* CAMEL-17985: fixed support for "ref:" scheme in ResourceHelper
* CAMEL-17985: added unit test for XsltUriResolver using ref: scheme
* CAMEL-17985: added unit test for XsltUriResolver using ref: scheme
* CAMEL-17985: checkstyle fix
---
.../camel/builder/xml/XsltUriResolverTest.java | 29 +++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/core/camel-core/src/test/java/org/apache/camel/builder/xml/XsltUriResolverTest.java b/core/camel-core/src/test/java/org/apache/camel/builder/xml/XsltUriResolverTest.java
index 176e065a5cb..10a010c2f68 100644
--- a/core/camel-core/src/test/java/org/apache/camel/builder/xml/XsltUriResolverTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/builder/xml/XsltUriResolverTest.java
@@ -16,24 +16,47 @@
*/
package org.apache.camel.builder.xml;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+
import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
import org.apache.camel.CamelContext;
import org.apache.camel.component.xslt.XsltUriResolver;
import org.apache.camel.impl.DefaultCamelContext;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.*;
public class XsltUriResolverTest {
@Test
- public void testResolveUri() throws Exception {
+ public void testResolveUriUsingClasspath() throws Exception {
CamelContext context = new DefaultCamelContext();
XsltUriResolver xsltUriResolver = new XsltUriResolver(context, "classpath:xslt/staff/staff.xsl");
Source source = xsltUriResolver.resolve("../../xslt/common/staff_template.xsl", "classpath:xslt/staff/staff.xsl");
assertNotNull(source);
assertEquals("classpath:xslt/common/staff_template.xsl", source.getSystemId());
}
+
+ @Test
+ public void testResolveUriUsingRef() throws Exception {
+ CamelContext context = new DefaultCamelContext();
+ String staffTemplateXsl = readFileFromClasspathAsString("xslt/common/staff_template.xsl");
+ context.getRegistry().bind("staffTemplateXsl", staffTemplateXsl);
+ XsltUriResolver xsltUriResolver = new XsltUriResolver(context, "classpath:xslt/staff/staff.xsl");
+ Source source = xsltUriResolver.resolve("ref:staffTemplateXsl", "classpath:xslt/staff/staff.xsl");
+ assertNotNull(source);
+ assertEquals("ref:staffTemplateXsl", source.getSystemId());
+ assertArrayEquals(((StreamSource)source).getInputStream().readAllBytes(), staffTemplateXsl.getBytes());
+ }
+
+ private static String readFileFromClasspathAsString(String path) throws IOException {
+ try (InputStream is = XsltUriResolverTest.class.getClassLoader().getResourceAsStream(path)) {
+ assert is != null;
+ return new String(is.readAllBytes(), StandardCharsets.UTF_8);
+ }
+ }
}