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

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

commit 41d89764d9199348a5533f7850631371c63383c4
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Jan 26 13:14:14 2022 +0100

    CAMEL-17552: camel-core - Switch EIP that can optimize during bootstrap
---
 .../camel/builder/RouteTemplateSwitchTest.java     | 103 +++++++++++++++++++++
 1 file changed, 103 insertions(+)

diff --git 
a/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplateSwitchTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplateSwitchTest.java
new file mode 100644
index 0000000..260b089
--- /dev/null
+++ 
b/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplateSwitchTest.java
@@ -0,0 +1,103 @@
+/*
+ * 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.builder;
+
+import org.apache.camel.ContextTestSupport;
+import org.junit.jupiter.api.Test;
+
+public class RouteTemplateSwitchTest extends ContextTestSupport {
+
+    @Test
+    public void testRed() throws Exception {
+        TemplatedRouteBuilder.builder(context, "myTemplate")
+                .parameter("red", "true")
+                .parameter("blue", "false")
+                .routeId("myRoute")
+                .add();
+
+        getMockEndpoint("mock:end").expectedMessageCount(1);
+        getMockEndpoint("mock:red").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello Red");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testBlue() throws Exception {
+        TemplatedRouteBuilder.builder(context, "myTemplate")
+                .parameter("red", "false")
+                .parameter("blue", "true")
+                .routeId("myRoute")
+                .add();
+
+        getMockEndpoint("mock:end").expectedMessageCount(1);
+        getMockEndpoint("mock:blue").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello Red");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testNotProvidedBlue() throws Exception {
+        TemplatedRouteBuilder.builder(context, "myTemplate")
+                .parameter("blue", "true")
+                .routeId("myRoute")
+                .add();
+
+        getMockEndpoint("mock:end").expectedMessageCount(1);
+        getMockEndpoint("mock:blue").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello Red");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testNotProvided() throws Exception {
+        TemplatedRouteBuilder.builder(context, "myTemplate")
+                .routeId("myRoute")
+                .add();
+
+        getMockEndpoint("mock:end").expectedMessageCount(1);
+        getMockEndpoint("mock:red").expectedMessageCount(0);
+        getMockEndpoint("mock:blue").expectedMessageCount(0);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                routeTemplate("myTemplate")
+                        .templateOptionalParameter("red")
+                        .templateOptionalParameter("blue")
+                    .from("direct:start")
+                        .doSwitch()
+                            .when(simple("{{?red}}")).to("mock:red")
+                            .when(simple("{{?blue}}")).to("mock:blue")
+                        .end()
+                        .to("mock:end");
+            }
+        };
+    }
+}

Reply via email to