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 2021/04/20 06:50:30 UTC

[camel] branch master updated: Added test based on user forum issue

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

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


The following commit(s) were added to refs/heads/master by this push:
     new fb47a92  Added test based on user forum issue
fb47a92 is described below

commit fb47a92c17d7da2b7a6a5cf162a9a550cfff3ddc
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Apr 20 08:49:51 2021 +0200

    Added test based on user forum issue
---
 .../TwoDoTryAndThrowInInnerCatchIssueTest.java     | 86 ++++++++++++++++++++++
 1 file changed, 86 insertions(+)

diff --git a/core/camel-core/src/test/java/org/apache/camel/issues/TwoDoTryAndThrowInInnerCatchIssueTest.java b/core/camel-core/src/test/java/org/apache/camel/issues/TwoDoTryAndThrowInInnerCatchIssueTest.java
new file mode 100644
index 0000000..869525f
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/issues/TwoDoTryAndThrowInInnerCatchIssueTest.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.issues;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.LoggingLevel;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.TryDefinition;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.fail;
+
+/**
+ * Based on user forum issue
+ */
+public class TwoDoTryAndThrowInInnerCatchIssueTest extends ContextTestSupport {
+
+    @Test
+    public void testSendThatIsCaught() throws Exception {
+        ExtendedCamelContext ecc = context.adapt(ExtendedCamelContext.class);
+        String xml = ecc.getModelToXMLDumper().dumpModelAsXml(context, context.getRouteDefinition("myroute"));
+        log.info(xml);
+
+        try {
+            template.requestBody("direct:test", "test", String.class);
+        } catch (Exception e) {
+            fail("Should not fail");
+        }
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                errorHandler(noErrorHandler());
+
+                TryDefinition try1 = from("direct:test").routeId("myroute").doTry();
+
+                TryDefinition try2 = try1.doTry();
+
+                try2.throwException(new IllegalArgumentException("Forced by me"))
+                        .doCatch(Exception.class)
+                        .log(LoggingLevel.INFO, TwoDoTryAndThrowInInnerCatchIssueTest.class.getName(), "docatch 1")
+                        .throwException(new IllegalArgumentException("Second forced by me"))
+                        .end();
+
+                try1.doCatch(Exception.class)
+                        .log(LoggingLevel.INFO, TwoDoTryAndThrowInInnerCatchIssueTest.class.getName(), "docatch 3")
+                        .end();
+
+                // stacked doTry in Java DSL has a flaw so you can do as above
+                /*
+                from("direct:test").
+                    doTry().
+                        doTry().
+                            throwException(new IllegalArgumentException("Forced by me"))
+                        .doCatch(Exception.class)
+                            .log(LoggingLevel.INFO,DoThrowInCatchIssueTest.class.getName(), "docatch 1")
+                            .throwException(new IllegalArgumentException("Second forced by me"))
+                        .endDoTry() // end catch block
+                    .endDoTry() // end inner try
+                    .doCatch(Exception.class)
+                        .log(LoggingLevel.INFO,DoThrowInCatchIssueTest.class.getName(), "docatch 3")
+                    .end();
+                            }
+                        };*/
+            }
+        };
+    }
+}