You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/06/02 05:35:30 UTC

[camel] 02/02: Added unit test based on https://github.com/apache/camel/pull/7686

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

commit 092010e1fc226d8c43bdaceab25d818a5130d134
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Jun 2 07:35:16 2022 +0200

    Added unit test based on https://github.com/apache/camel/pull/7686
---
 .../ErrorHandlerDynamicContinueTest.java           | 80 ++++++++++++++++++++++
 1 file changed, 80 insertions(+)

diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/errorhandler/ErrorHandlerDynamicContinueTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/errorhandler/ErrorHandlerDynamicContinueTest.java
new file mode 100644
index 00000000000..7b515930edc
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/errorhandler/ErrorHandlerDynamicContinueTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.processor.errorhandler;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class ErrorHandlerDynamicContinueTest extends ContextTestSupport {
+
+    @Test
+    public void testContinued() throws Exception {
+        getMockEndpoint("mock:start").expectedMessageCount(1);
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello World");
+        mock.message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isInstanceOf(IllegalArgumentException.class);
+
+        template.sendBodyAndHeader(
+                "direct:start", "Hello World",
+                "exception", "iae");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testNotContinued() throws Exception {
+        getMockEndpoint("mock:start").expectedMessageCount(1);
+
+        CamelExecutionException exception = assertThrows(CamelExecutionException.class, () -> template.sendBodyAndHeader(
+                "direct:start", "Hello World",
+                "exception", "uoe"));
+
+        assertEquals(UnsupportedOperationException.class, exception.getCause().getClass());
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                onException(Exception.class)
+                        .maximumRedeliveries(1)
+                        .continued(exchange -> {
+                            Exception e = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
+                            return e instanceof IllegalArgumentException;
+                        });
+
+                from("direct:start")
+                    .to("mock:start")
+                    .choice()
+                        .when(simple("${header.exception} == 'iae'")).throwException(new IllegalArgumentException("Forced"))
+                        .otherwise().throwException(new UnsupportedOperationException())
+                    .end()
+                    .to("mock:result");
+            }
+        };
+    }
+}