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

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

commit f5497b7757d96bba531e8f81f28ec5eb257b30b5
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu May 13 09:56:13 2021 +0200

    CAMEL-16607: route template / kamelets. Allow to use #type and #class for 
local beans
---
 .../camel/spring/routebuilder/MyLocalBean.java     | 34 +++++++++++++++
 .../SpringRouteTemplateLocalBeanTest.java          | 51 ++++++++++++++++++++++
 .../SpringRouteTemplateLocalBeanTest.xml           | 45 +++++++++++++++++++
 3 files changed, 130 insertions(+)

diff --git 
a/components/camel-spring-xml/src/test/java/org/apache/camel/spring/routebuilder/MyLocalBean.java
 
b/components/camel-spring-xml/src/test/java/org/apache/camel/spring/routebuilder/MyLocalBean.java
new file mode 100644
index 0000000..47fed85
--- /dev/null
+++ 
b/components/camel-spring-xml/src/test/java/org/apache/camel/spring/routebuilder/MyLocalBean.java
@@ -0,0 +1,34 @@
+/*
+ * 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.spring.routebuilder;
+
+public class MyLocalBean {
+
+    private String prefix;
+
+    public String getPrefix() {
+        return prefix;
+    }
+
+    public void setPrefix(String prefix) {
+        this.prefix = prefix;
+    }
+
+    public String hello(String body) {
+        return prefix + " " + body;
+    }
+}
diff --git 
a/components/camel-spring-xml/src/test/java/org/apache/camel/spring/routebuilder/SpringRouteTemplateLocalBeanTest.java
 
b/components/camel-spring-xml/src/test/java/org/apache/camel/spring/routebuilder/SpringRouteTemplateLocalBeanTest.java
new file mode 100644
index 0000000..7f0eba5
--- /dev/null
+++ 
b/components/camel-spring-xml/src/test/java/org/apache/camel/spring/routebuilder/SpringRouteTemplateLocalBeanTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.spring.routebuilder;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.SpringTestSupport;
+import org.junit.jupiter.api.Test;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class SpringRouteTemplateLocalBeanTest extends SpringTestSupport {
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new 
ClassPathXmlApplicationContext("org/apache/camel/spring/routebuilder/SpringRouteTemplateLocalBeanTest.xml");
+    }
+
+    @Test
+    public void testLocalBean() throws Exception {
+        Map<String, Object> parameters = new HashMap<>();
+        parameters.put("foo", "one");
+        parameters.put("bar", "cheese");
+        parameters.put("greeting", "Davs");
+        context.addRouteFromTemplate("first", "myTemplate", parameters);
+
+        MockEndpoint mock = getMockEndpoint("mock:cheese");
+        mock.expectedBodiesReceived("Davs World");
+
+        template.sendBody("direct:one", "World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+}
diff --git 
a/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/routebuilder/SpringRouteTemplateLocalBeanTest.xml
 
b/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/routebuilder/SpringRouteTemplateLocalBeanTest.xml
new file mode 100644
index 0000000..90cbfd7
--- /dev/null
+++ 
b/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/routebuilder/SpringRouteTemplateLocalBeanTest.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xmlns:context="http://www.springframework.org/schema/context";
+       xsi:schemaLocation="
+            http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
+            http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
+            http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context.xsd";>
+
+    <camelContext id="foo" xmlns="http://camel.apache.org/schema/spring";>
+        <routeTemplate id="myTemplate">
+            <description>blah blah</description>
+            <templateParameter name="foo"/>
+            <templateParameter name="bar"/>
+            <templateParameter name="greeting"/>
+            <templateBean name="myBean" 
type="#class:org.apache.camel.spring.routebuilder.MyLocalBean">
+                <property key="prefix" value="{{greeting}}"/>
+            </templateBean>
+            <route>
+                <from uri="direct:{{foo}}"/>
+                <to uri="bean:{{myBean}}"/>
+                <to uri="mock:{{bar}}"/>
+            </route>
+        </routeTemplate>
+    </camelContext>
+
+</beans>
\ No newline at end of file

Reply via email to