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 6921069dbaee Added unit test based on user issue
6921069dbaee is described below
commit 6921069dbaee40c8442f6c7fba091c14bd529a35
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Jan 7 18:17:41 2026 +0100
Added unit test based on user issue
---
.../camel/builder/RouteOnExceptionHandledTest.java | 66 ++++++++++++++++++++
.../RouteTemplateOnExceptionHandledTest.java | 70 ++++++++++++++++++++++
2 files changed, 136 insertions(+)
diff --git
a/core/camel-core/src/test/java/org/apache/camel/builder/RouteOnExceptionHandledTest.java
b/core/camel-core/src/test/java/org/apache/camel/builder/RouteOnExceptionHandledTest.java
new file mode 100644
index 000000000000..61d7b4b3b0c9
--- /dev/null
+++
b/core/camel-core/src/test/java/org/apache/camel/builder/RouteOnExceptionHandledTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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 java.io.IOException;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class RouteOnExceptionHandledTest extends ContextTestSupport {
+
+ @Test
+ public void testOnExceptionHandled() throws Exception {
+ getMockEndpoint("mock:result").expectedMessageCount(0);
+ getMockEndpoint("mock:io").expectedMessageCount(0);
+ getMockEndpoint("mock:error").expectedBodiesReceived("Error: World");
+
+ Exchange out =
fluentTemplate.withBody("World").to("direct:start").send();
+ Assertions.assertFalse(out.isFailed()); // should be handled
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:start")
+ .onException(IOException.class)
+ .maximumRedeliveries(3)
+ .log("IO error happened")
+ .process(exchange -> {
+ exchange.getMessage().setBody("IO: " +
exchange.getMessage().getBody());
+ })
+ .to("mock:io")
+ .end()
+
.onException(IllegalArgumentException.class).handled(true)
+ .log("An error happened")
+ .process(exchange -> {
+ exchange.getMessage().setBody("Error: " +
exchange.getMessage().getBody());
+ })
+ .to("mock:error")
+ .end()
+ .throwException(new IllegalArgumentException("Forced"))
+ .to("mock:result");
+ }
+ };
+ }
+}
diff --git
a/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplateOnExceptionHandledTest.java
b/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplateOnExceptionHandledTest.java
new file mode 100644
index 000000000000..15cb64e24a9c
--- /dev/null
+++
b/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplateOnExceptionHandledTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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 java.io.IOException;
+import java.util.Map;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class RouteTemplateOnExceptionHandledTest extends ContextTestSupport {
+
+ @Test
+ public void testOnExceptionHandled() throws Exception {
+ context.addRouteFromTemplate("myRoute", "myTemplate", Map.of("foo",
"start"));
+
+ getMockEndpoint("mock:result").expectedMessageCount(0);
+ getMockEndpoint("mock:io").expectedMessageCount(0);
+ getMockEndpoint("mock:error").expectedBodiesReceived("Error: World");
+
+ Exchange out =
fluentTemplate.withBody("World").to("direct:start").send();
+ Assertions.assertFalse(out.isFailed()); // should be handled
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("myTemplate").templateParameter("foo")
+ .from("direct:{{foo}}")
+ .onException(IOException.class)
+ .maximumRedeliveries(3)
+ .log("IO error happened")
+ .process(exchange -> {
+ exchange.getMessage().setBody("IO: " +
exchange.getMessage().getBody());
+ })
+ .to("mock:io")
+ .end()
+
.onException(IllegalArgumentException.class).handled(true)
+ .log("An error happened")
+ .process(exchange -> {
+ exchange.getMessage().setBody("Error: " +
exchange.getMessage().getBody());
+ })
+ .to("mock:error")
+ .end()
+ .throwException(new IllegalArgumentException("Forced"))
+ .to("mock:result");
+ }
+ };
+ }
+}