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 71d99e598f0 CAMEL-18262 - Fixing the Template issue (#7995)
71d99e598f0 is described below
commit 71d99e598f08ff05cb3d083247d5e7608e91764b
Author: Rhuan Rocha <[email protected]>
AuthorDate: Mon Jul 25 12:00:47 2022 -0300
CAMEL-18262 - Fixing the Template issue (#7995)
* CAMEL-18262 - Fixing the Template issue
Signed-off-by: Rhuan Rocha <[email protected]>
* CAMEL-18262 - Adding unit test
Signed-off-by: Rhuan Rocha <[email protected]>
* CAMEL-18262 - Removing comments.
Signed-off-by: Rhuan Rocha <[email protected]>
* CAMEL-18262 - Fixing the format issue.
Signed-off-by: Rhuan Rocha <[email protected]>
* CAMEL-18262 - Fixing the template routeDefinition prepare
Signed-off-by: Rhuan Rocha <[email protected]>
* CAMEL-18262 - Fixing the format issue.
Signed-off-by: Rhuan Rocha <[email protected]>
* CAMEL-18262 - Creating one RoutesDefinition per call
Signed-off-by: Rhuan Rocha <[email protected]>
---
.../java/org/apache/camel/impl/DefaultModel.java | 7 ++
.../camel/model/RouteTemplateDefinition.java | 1 +
.../model/RouteConfigurationOnExceptionTest.java | 85 ++++++++++++++++++++++
3 files changed, 93 insertions(+)
diff --git
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java
index 816aac85b73..793c29fa05b 100644
---
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java
+++
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java
@@ -53,6 +53,7 @@ import org.apache.camel.model.RouteFilters;
import org.apache.camel.model.RouteTemplateBeanDefinition;
import org.apache.camel.model.RouteTemplateDefinition;
import org.apache.camel.model.RouteTemplateParameterDefinition;
+import org.apache.camel.model.RoutesDefinition;
import org.apache.camel.model.TemplatedRouteBeanDefinition;
import org.apache.camel.model.TemplatedRouteDefinition;
import org.apache.camel.model.TemplatedRouteParameterDefinition;
@@ -415,7 +416,13 @@ public class DefaultModel implements Model {
routeId, routeTemplateId,
"duplicate id detected: " + duplicate + ". Please correct
ids to be unique among all your routes.");
}
+
addRouteDefinition(def);
+
+ RoutesDefinition routeCollection = new RoutesDefinition();
+ routeCollection.setCamelContext(camelContext);
+ routeCollection.setRoutes(getRouteDefinitions());
+ routeCollection.prepareRoute(def);
return def.getId();
}
diff --git
a/core/camel-core-model/src/main/java/org/apache/camel/model/RouteTemplateDefinition.java
b/core/camel-core-model/src/main/java/org/apache/camel/model/RouteTemplateDefinition.java
index f700c69242f..d9fbfe9ee73 100644
---
a/core/camel-core-model/src/main/java/org/apache/camel/model/RouteTemplateDefinition.java
+++
b/core/camel-core-model/src/main/java/org/apache/camel/model/RouteTemplateDefinition.java
@@ -418,6 +418,7 @@ public class RouteTemplateDefinition extends
OptionalIdentifiedDefinition {
copy.setDescription(getDescription());
}
copy.setPrecondition(route.getPrecondition());
+ copy.setRouteConfigurationId(route.getRouteConfigurationId());
return copy;
}
diff --git
a/core/camel-core/src/test/java/org/apache/camel/model/RouteConfigurationOnExceptionTest.java
b/core/camel-core/src/test/java/org/apache/camel/model/RouteConfigurationOnExceptionTest.java
new file mode 100644
index 00000000000..bbaebbe98db
--- /dev/null
+++
b/core/camel-core/src/test/java/org/apache/camel/model/RouteConfigurationOnExceptionTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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.model;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.LoggingLevel;
+import org.apache.camel.builder.AdviceWith;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.builder.RouteConfigurationBuilder;
+import org.apache.camel.builder.TemplatedRouteBuilder;
+import org.junit.jupiter.api.Test;
+
+public class RouteConfigurationOnExceptionTest extends ContextTestSupport {
+
+ @Override
+ protected RouteBuilder[] createRouteBuilders() {
+ return new RouteBuilder[] {
+ new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("route-template")
+ .from("direct:start-template")
+ .routeConfigurationId("my-error-handler")
+ .throwException(RuntimeException.class,
"Expected Error");
+ }
+ },
+ new RouteBuilder() {
+ @Override
+ public void configure() {
+ TemplatedRouteBuilder.builder(context,
"route-template")
+ .routeId("my-test-file-route")
+ .add();
+ }
+ },
+ new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:start-normal")
+ .routeConfigurationId("my-error-handler")
+ .throwException(RuntimeException.class,
"Expected Error");
+ }
+ },
+ new RouteConfigurationBuilder() {
+ @Override
+ public void configuration() {
+
routeConfiguration("my-error-handler").onException(Exception.class).handled(true)
+ .transform(constant("Error Received"))
+ .to("mock:result");
+ }
+ }
+ };
+ }
+
+ @Test
+ void testRouteTemplateCanSupportRouteConfiguration() throws Exception {
+
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+ getMockEndpoint("mock:result").expectedBodiesReceived("Error
Received");
+ template.sendBody("direct:start-template", "foo");
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ void testNormalRouteCanSupportRouteConfiguration() throws Exception {
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+ getMockEndpoint("mock:result").expectedBodiesReceived("Error
Received");
+ template.sendBody("direct:start-normal", "foo");
+ assertMockEndpointsSatisfied();
+ }
+}