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 2018/11/02 13:44:02 UTC

[camel] branch master updated: CAMEL-12883: Added unit test

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 2c69246  CAMEL-12883: Added unit test
2c69246 is described below

commit 2c69246054662031dc91b97ea0d81aaea709a2cc
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Nov 2 14:43:44 2018 +0100

    CAMEL-12883: Added unit test
---
 .../AdviceWithWeaveByTypeOnExceptionTest.java      | 62 ++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithWeaveByTypeOnExceptionTest.java b/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithWeaveByTypeOnExceptionTest.java
new file mode 100644
index 0000000..2fa4b04
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithWeaveByTypeOnExceptionTest.java
@@ -0,0 +1,62 @@
+/**
+ * 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.interceptor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.AdviceWithRouteBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.OnExceptionDefinition;
+import org.junit.Test;
+
+/**
+ * Advice with tests
+ */
+public class AdviceWithWeaveByTypeOnExceptionTest extends ContextTestSupport {
+
+    @Test
+    public void testWeaveOnException() throws Exception {
+        context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                weaveByType(OnExceptionDefinition.class).after().to("mock:error");
+            }
+        });
+
+        getMockEndpoint("mock:error").expectedMessageCount(1);
+        getMockEndpoint("mock:result").expectedMessageCount(0);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .onException(Exception.class)
+                        .handled(true)
+                        .to("log:error")
+                    .end()
+                    .throwException(new IllegalArgumentException("Forced"))
+                    .to("mock:result");
+            }
+        };
+    }
+}
\ No newline at end of file