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 2021/08/10 19:50:35 UTC

[camel] 01/02: CAMEL-16853: fix resultHandlerFactory, add unit test (#5945)

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

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

commit fa4761b30577f514753afbfa07b057b6ffd479c4
Author: Rik van Ballegooijen <r....@codecast.nl>
AuthorDate: Tue Aug 10 21:45:42 2021 +0200

    CAMEL-16853: fix resultHandlerFactory, add unit test (#5945)
    
    * CAMEL-16853: fix resultHandlerFactory, add unit test
    
    * CAMEL-16853: Change unit test to DSL version, without depending on spring (note: still cyclic!)
    
    * CAMEL-16853: Fix cyclic dep: Moved unit test to camel-core, removed test dependencies from camel-xslt
    
    Co-authored-by: Rik van Ballegooijen <ri...@codecast.nl>
---
 .../apache/camel/component/xslt/XsltEndpoint.java  |  8 +--
 .../component/xslt/XsltResultHandlerTest.java      | 63 ++++++++++++++++++++++
 2 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/components/camel-xslt/src/main/java/org/apache/camel/component/xslt/XsltEndpoint.java b/components/camel-xslt/src/main/java/org/apache/camel/component/xslt/XsltEndpoint.java
index bccd61f..9d3b897 100644
--- a/components/camel-xslt/src/main/java/org/apache/camel/component/xslt/XsltEndpoint.java
+++ b/components/camel-xslt/src/main/java/org/apache/camel/component/xslt/XsltEndpoint.java
@@ -386,9 +386,7 @@ public class XsltEndpoint extends ProcessorEndpoint {
             LOG.debug("Using TransformerFactory {}", factory);
             xslt.setTransformerFactory(factory);
         }
-        if (resultHandlerFactory != null) {
-            xslt.setResultHandlerFactory(resultHandlerFactory);
-        }
+
         if (errorListener != null) {
             xslt.errorListener(errorListener);
         }
@@ -400,6 +398,10 @@ public class XsltEndpoint extends ProcessorEndpoint {
 
         configureOutput(xslt, output.name());
 
+        if (resultHandlerFactory != null) {
+            xslt.setResultHandlerFactory(resultHandlerFactory);
+        }
+
         // any additional transformer parameters then make a copy to avoid side-effects
         if (parameters != null) {
             Map<String, Object> copy = new HashMap<>(parameters);
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/xslt/XsltResultHandlerTest.java b/core/camel-core/src/test/java/org/apache/camel/component/xslt/XsltResultHandlerTest.java
new file mode 100644
index 0000000..ae3efa4
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/component/xslt/XsltResultHandlerTest.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.xslt;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.TestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class XsltResultHandlerTest extends TestSupport {
+
+    @Test
+    public void testResultHandlerFactory() throws Exception {
+        RouteBuilder builder = createRouteBuilder();
+        CamelContext context = new DefaultCamelContext();
+        ResultHandlerFactory factory = new DomResultHandlerFactory();
+        context.getRegistry().bind("factory", factory);
+        context.addRoutes(builder);
+        context.start();
+
+        XsltEndpoint endpoint = null;
+        for (Endpoint ep : context.getEndpoints()) {
+            if (ep instanceof XsltEndpoint) {
+                endpoint = (XsltEndpoint) ep;
+                break;
+            }
+        }
+
+        assertNotNull(endpoint);
+        assertEquals(DomResultHandlerFactory.class, factory.getClass());
+        assertEquals(factory, endpoint.getResultHandlerFactory());
+        assertEquals(factory, endpoint.getXslt().getResultHandlerFactory());
+    }
+
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("direct:start").to("xslt:org/apache/camel/component/xslt/example.xsl?output=bytes&resultHandlerFactory=#factory");
+            }
+        };
+    }
+
+}