Repository: camel
Updated Branches:
  refs/heads/master 9ab732a2d -> 3c2252aa5


CAMEL-7562: Fixed advice with when using CBR may add twice to when clauses in 
the CBR.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/689147e9
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/689147e9
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/689147e9

Branch: refs/heads/master
Commit: 689147e951c83887ab84bcf88ee1784ddab1db6a
Parents: b08edf3
Author: Claus Ibsen <davscl...@apache.org>
Authored: Mon Jun 30 21:34:58 2014 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Tue Jul 1 07:22:12 2014 +0200

----------------------------------------------------------------------
 .../camel/model/ProcessorDefinitionHelper.java  | 10 ++-
 .../apache/camel/issues/AdviceWithCBRTest.java  | 67 ++++++++++++++++++++
 .../model/ProcessorDefinitionHelperTest.java    | 53 ++++++++++++++++
 3 files changed, 127 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/689147e9/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
 
b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
index 5575d36..2ae283b 100644
--- 
a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
+++ 
b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
@@ -198,9 +198,6 @@ public final class ProcessorDefinitionHelper {
         }
 
         for (ProcessorDefinition out : outputs) {
-            if (type.isInstance(out)) {
-                found.add((T)out);
-            }
 
             // send is much common
             if (out instanceof SendDefinition) {
@@ -222,6 +219,9 @@ public final class ProcessorDefinitionHelper {
                     List<ProcessorDefinition<?>> children = 
choice.getOtherwise().getOutputs();
                     doFindType(children, type, found);
                 }
+
+                // do not check children as we already did that
+                continue;
             }
 
             // special for try ... catch ... finally
@@ -253,6 +253,10 @@ public final class ProcessorDefinitionHelper {
                 continue;
             }
 
+            if (type.isInstance(out)) {
+                found.add((T)out);
+            }
+
             // try children as well
             List<ProcessorDefinition<?>> children = out.getOutputs();
             doFindType(children, type, found);

http://git-wip-us.apache.org/repos/asf/camel/blob/689147e9/camel-core/src/test/java/org/apache/camel/issues/AdviceWithCBRTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/issues/AdviceWithCBRTest.java 
b/camel-core/src/test/java/org/apache/camel/issues/AdviceWithCBRTest.java
new file mode 100644
index 0000000..83965ba
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/issues/AdviceWithCBRTest.java
@@ -0,0 +1,67 @@
+/**
+ * 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.builder.AdviceWithRouteBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.RouteDefinition;
+
+/**
+ * @version 
+ */
+public class AdviceWithCBRTest extends ContextTestSupport {
+
+    public void testAdviceCBR() throws Exception {
+        RouteDefinition route = context.getRouteDefinitions().get(0);
+        route.adviceWith(context, new AdviceWithRouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                weaveById("foo").after().to("mock:foo2");
+                weaveById("bar").after().to("mock:bar2");
+            }
+        });
+
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:foo2").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:bar").expectedBodiesReceived("Bye World");
+        getMockEndpoint("mock:bar2").expectedBodiesReceived("Bye World");
+        getMockEndpoint("mock:baz").expectedBodiesReceived("Hi World");
+
+        template.sendBodyAndHeader("direct:start", "Hello World", "foo", 
"123");
+        template.sendBodyAndHeader("direct:start", "Bye World", "bar", "123");
+        template.sendBody("direct:start", "Hi World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .choice()
+                        .when(header("foo")).to("mock:foo").id("foo")
+                        .when(header("bar")).to("mock:bar").id("bar")
+                    .otherwise()
+                         .to("mock:baz").id("baz");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/689147e9/camel-core/src/test/java/org/apache/camel/model/ProcessorDefinitionHelperTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/model/ProcessorDefinitionHelperTest.java
 
b/camel-core/src/test/java/org/apache/camel/model/ProcessorDefinitionHelperTest.java
new file mode 100644
index 0000000..4aa1d7e
--- /dev/null
+++ 
b/camel-core/src/test/java/org/apache/camel/model/ProcessorDefinitionHelperTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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 java.util.Iterator;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+public class ProcessorDefinitionHelperTest extends ContextTestSupport {
+
+    public void testFilterTypeInOutputs() throws Exception {
+        RouteDefinition route = context.getRouteDefinitions().get(0);
+
+        Iterator<ProcessorDefinition> it = 
ProcessorDefinitionHelper.filterTypeInOutputs(route.getOutputs(), 
ProcessorDefinition.class);
+        assertNotNull(it);
+
+        assertEquals("foo", it.next().getId());
+        assertEquals("bar", it.next().getId());
+        assertEquals("baz", it.next().getId());
+        assertFalse(it.hasNext());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .choice()
+                        .when(header("foo")).to("mock:foo").id("foo")
+                        .when(header("bar")).to("mock:bar").id("bar")
+                    .otherwise()
+                        .to("mock:baz").id("baz");
+            }
+        };
+    }
+
+}

Reply via email to