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 d6452ba  CAMEL-15555: Added unit test
d6452ba is described below

commit d6452ba7e5c290a9d4312e828635b9b9230f0280
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Jun 7 10:42:24 2021 +0200

    CAMEL-15555: Added unit test
---
 .../apache/camel/cdi/routetemplate/MyRoute.java    | 30 ++++++++
 .../cdi/routetemplate/MyRouteCreatorBean.java      | 51 +++++++++++++
 .../camel/cdi/routetemplate/MySecondRoute.java     | 30 ++++++++
 .../camel/cdi/routetemplate/MyTemplateRoute.java   | 31 ++++++++
 .../camel/cdi/routetemplate/RouteTemplateTest.java | 84 ++++++++++++++++++++++
 5 files changed, 226 insertions(+)

diff --git 
a/components/camel-cdi/src/test/java/org/apache/camel/cdi/routetemplate/MyRoute.java
 
b/components/camel-cdi/src/test/java/org/apache/camel/cdi/routetemplate/MyRoute.java
new file mode 100644
index 0000000..9a45e34
--- /dev/null
+++ 
b/components/camel-cdi/src/test/java/org/apache/camel/cdi/routetemplate/MyRoute.java
@@ -0,0 +1,30 @@
+/*
+ * 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.cdi.routetemplate;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class MyRoute extends RouteBuilder {
+
+    @Override
+    public void configure() throws Exception {
+        from("direct:start")
+                .to("direct:foo")
+                .to("direct:bar")
+                .to("mock:result");
+    }
+}
diff --git 
a/components/camel-cdi/src/test/java/org/apache/camel/cdi/routetemplate/MyRouteCreatorBean.java
 
b/components/camel-cdi/src/test/java/org/apache/camel/cdi/routetemplate/MyRouteCreatorBean.java
new file mode 100644
index 0000000..720b4fe
--- /dev/null
+++ 
b/components/camel-cdi/src/test/java/org/apache/camel/cdi/routetemplate/MyRouteCreatorBean.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.cdi.routetemplate;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+import javax.inject.Inject;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.CamelEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@ApplicationScoped
+public class MyRouteCreatorBean {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(MyRouteCreatorBean.class);
+
+    @Inject
+    CamelContext context;
+
+    public void setupRoutes(@Observes CamelEvent.CamelContextStartedEvent 
startup) throws Exception {
+        LOG.info("Creating routes from templates");
+
+        Map<String, Object> parameters = new HashMap<>();
+        parameters.put("start", "foo");
+        parameters.put("append", "A");
+        context.addRouteFromTemplate("foo", "myTemplate", parameters);
+        parameters.clear();
+        parameters.put("start", "bar");
+        parameters.put("append", "B");
+        context.addRouteFromTemplate("bar", "myTemplate", parameters);
+    }
+}
diff --git 
a/components/camel-cdi/src/test/java/org/apache/camel/cdi/routetemplate/MySecondRoute.java
 
b/components/camel-cdi/src/test/java/org/apache/camel/cdi/routetemplate/MySecondRoute.java
new file mode 100644
index 0000000..2bd3933
--- /dev/null
+++ 
b/components/camel-cdi/src/test/java/org/apache/camel/cdi/routetemplate/MySecondRoute.java
@@ -0,0 +1,30 @@
+/*
+ * 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.cdi.routetemplate;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class MySecondRoute extends RouteBuilder {
+
+    @Override
+    public void configure() throws Exception {
+        from("direct:start2")
+                .to("direct:bar")
+                .to("direct:foo")
+                .to("mock:result2");
+    }
+}
diff --git 
a/components/camel-cdi/src/test/java/org/apache/camel/cdi/routetemplate/MyTemplateRoute.java
 
b/components/camel-cdi/src/test/java/org/apache/camel/cdi/routetemplate/MyTemplateRoute.java
new file mode 100644
index 0000000..114823c
--- /dev/null
+++ 
b/components/camel-cdi/src/test/java/org/apache/camel/cdi/routetemplate/MyTemplateRoute.java
@@ -0,0 +1,31 @@
+/*
+ * 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.cdi.routetemplate;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class MyTemplateRoute extends RouteBuilder {
+
+    @Override
+    public void configure() throws Exception {
+        routeTemplate("myTemplate")
+                .templateParameter("start")
+                .templateParameter("append")
+                .from("direct:{{start}}")
+                .transform().simple("${body}{{append}}");
+    }
+}
diff --git 
a/components/camel-cdi/src/test/java/org/apache/camel/cdi/routetemplate/RouteTemplateTest.java
 
b/components/camel-cdi/src/test/java/org/apache/camel/cdi/routetemplate/RouteTemplateTest.java
new file mode 100644
index 0000000..c93013c
--- /dev/null
+++ 
b/components/camel-cdi/src/test/java/org/apache/camel/cdi/routetemplate/RouteTemplateTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.cdi.routetemplate;
+
+import java.util.concurrent.TimeUnit;
+
+import javax.inject.Inject;
+
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.cdi.CdiCamelExtension;
+import org.apache.camel.cdi.Uri;
+import org.apache.camel.cdi.bean.DefaultCamelContextBean;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied;
+
+@RunWith(Arquillian.class)
+public class RouteTemplateTest {
+
+    @Inject
+    private DefaultCamelContextBean defaultCamelContext;
+
+    @Inject
+    @Uri("direct:start")
+    private ProducerTemplate defaultInbound;
+
+    @Inject
+    @Uri("mock:result")
+    private MockEndpoint defaultOutbound;
+
+    @Inject
+    @Uri("direct:start2")
+    private ProducerTemplate defaultInbound2;
+
+    @Inject
+    @Uri("mock:result2")
+    private MockEndpoint defaultOutbound2;
+
+    @Deployment
+    public static Archive<?> deployment() {
+        return ShrinkWrap.create(JavaArchive.class)
+                // Camel CDI
+                .addPackage(CdiCamelExtension.class.getPackage())
+                // Test classes
+                .addClasses(DefaultCamelContextBean.class, 
MyRouteCreatorBean.class, MyRoute.class, MySecondRoute.class,
+                        MyTemplateRoute.class)
+                // Bean archive deployment descriptor
+                .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
+    }
+
+    @Test
+    public void verifyCamelContext() throws Exception {
+        defaultOutbound.expectedBodiesReceived("Hello AB");
+        defaultOutbound2.expectedBodiesReceived("Bye BA");
+
+        defaultInbound.sendBody("direct:start", "Hello ");
+        defaultInbound2.sendBody("direct:start2", "Bye ");
+
+        assertIsSatisfied(2L, TimeUnit.SECONDS, defaultOutbound, 
defaultOutbound2);
+    }
+
+}

Reply via email to