You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bv...@apache.org on 2022/12/13 09:56:04 UTC

[camel] 01/01: CAMEL-18809: RouteDefinitionHelper should resolve the intercepted from URI which is configured with property placeholder

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

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

commit 737d47a97224518a9fc28365f3f366e5199dba93
Author: Babak Vahdat <bv...@apache.org>
AuthorDate: Tue Dec 13 10:55:32 2022 +0100

    CAMEL-18809: RouteDefinitionHelper should resolve the intercepted from URI which is configured with property placeholder
---
 ...nterceptFromAndInterceptSendToEndpointTest.java | 91 ++++++++++++++++++++++
 ...nterceptSendToEndpointWithPlaceholdersTest.java | 86 ++++++++++++++++++++
 2 files changed, 177 insertions(+)

diff --git a/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplateInterceptFromAndInterceptSendToEndpointTest.java b/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplateInterceptFromAndInterceptSendToEndpointTest.java
new file mode 100644
index 00000000000..98811ea9de4
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplateInterceptFromAndInterceptSendToEndpointTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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.apache.camel.Route;
+import org.apache.camel.model.RouteConfigurationDefinition;
+import org.apache.camel.model.RouteTemplateDefinition;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.camel.util.CollectionHelper.mapOf;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class RouteTemplateInterceptFromAndInterceptSendToEndpointTest extends ContextTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Test
+    void testCreateRouteFromRouteTemplate() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                routeTemplate("myTemplate").templateParameter("foo").templateParameter("bar")
+                        .from("direct:{{foo}}")
+                        .to("mock:{{bar}}");
+
+                RouteConfigurationDefinition routeConfigurationDefinition = new RouteConfigurationDefinition();
+                routeConfigurationDefinition.setCamelContext(context);
+
+                routeConfigurationDefinition.
+                        interceptFrom("direct:intercepted-from").
+                        to(getMockEndpoint("mock:intercepted-from"));
+
+                routeConfigurationDefinition.
+                        interceptSendToEndpoint("mock:intercepted-send-to").
+                        to(getMockEndpoint("mock:intercepted-send-to-before")).
+                        afterUri(getMockEndpoint("mock:intercepted-send-to-after").getEndpointUri());
+
+                context.addRouteConfiguration(routeConfigurationDefinition);
+            }
+        });
+
+        assertEquals(1, context.getRouteTemplateDefinitions().size());
+
+        RouteTemplateDefinition routeTemplate = context.getRouteTemplateDefinition("myTemplate");
+        assertEquals("foo", routeTemplate.getTemplateParameters().get(0).getName());
+        assertEquals("bar", routeTemplate.getTemplateParameters().get(1).getName());
+
+        for (String uriSuffix : new String[]{"from", "send-to", "send-to-before", "send-to-after"}) {
+            getMockEndpoint("mock:intercepted-" + uriSuffix).expectedBodiesReceived("Hello Intercepted");
+        }
+
+        TemplatedRouteBuilder.builder(context, "myTemplate")
+                .routeId("intercepted")
+                .parameter("foo", "intercepted-from")
+                .parameter("bar", "intercepted-send-to")
+                .add();
+
+        // now start camel
+        context.start();
+
+        assertEquals(1, context.getRouteDefinitions().size());
+        assertEquals(1, context.getRoutes().size());
+        assertEquals("Started", context.getRouteController().getRouteStatus("intercepted").name());
+        assertEquals("true", context.getRoute("intercepted").getProperties().get(Route.TEMPLATE_PROPERTY));
+
+        template.sendBody("direct:intercepted-from", "Hello Intercepted");
+
+        assertMockEndpointsSatisfied();
+
+        context.stop();
+    }
+
+}
diff --git a/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplateInterceptFromAndInterceptSendToEndpointWithPlaceholdersTest.java b/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplateInterceptFromAndInterceptSendToEndpointWithPlaceholdersTest.java
new file mode 100644
index 00000000000..7487e9210d7
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplateInterceptFromAndInterceptSendToEndpointWithPlaceholdersTest.java
@@ -0,0 +1,86 @@
+/*
+ * 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.apache.camel.Route;
+import org.apache.camel.model.RouteConfigurationDefinition;
+import org.apache.camel.model.RouteTemplateDefinition;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class RouteTemplateInterceptFromAndInterceptSendToEndpointWithPlaceholdersTest extends ContextTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Test
+    void testCreateRouteFromRouteTemplate() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                routeTemplate("myTemplate").templateParameter("foo").templateParameter("bar")
+                        .from("direct:{{foo}}")
+                        .to("mock:{{bar}}");
+
+                RouteConfigurationDefinition routeConfigurationDefinition = new RouteConfigurationDefinition();
+                routeConfigurationDefinition.setCamelContext(context);
+
+                routeConfigurationDefinition.interceptFrom("direct:one").to("mock:intercepted-from");
+
+                routeConfigurationDefinition.interceptSendToEndpoint("mock:cheese").to("mock:intercepted-to-before")
+                        .afterUri("mock:intercepted-to-after");
+
+                context.addRouteConfiguration(routeConfigurationDefinition);
+            }
+        });
+
+        assertEquals(1, context.getRouteTemplateDefinitions().size());
+
+        RouteTemplateDefinition routeTemplate = context.getRouteTemplateDefinition("myTemplate");
+        assertEquals("foo", routeTemplate.getTemplateParameters().get(0).getName());
+        assertEquals("bar", routeTemplate.getTemplateParameters().get(1).getName());
+
+        for (String uriSuffix : new String[] { "from", "to-before", "to-after" }) {
+            getMockEndpoint("mock:intercepted-" + uriSuffix).expectedBodiesReceived("Hello Intercepted");
+        }
+
+        TemplatedRouteBuilder.builder(context, "myTemplate")
+                .routeId("intercepted")
+                .parameter("foo", "one")
+                .parameter("bar", "cheese")
+                .add();
+
+        // now start camel
+        context.start();
+
+        assertEquals(1, context.getRouteDefinitions().size());
+        assertEquals(1, context.getRoutes().size());
+        assertEquals("Started", context.getRouteController().getRouteStatus("intercepted").name());
+        assertEquals("true", context.getRoute("intercepted").getProperties().get(Route.TEMPLATE_PROPERTY));
+
+        template.sendBody("direct:one", "Hello Intercepted");
+
+        assertMockEndpointsSatisfied();
+
+        context.stop();
+    }
+
+}