Repository: camel
Updated Branches:
  refs/heads/camel-2.13.x ff82f3869 -> 4ab33e84a
  refs/heads/camel-2.14.x f77a40672 -> 6fca142dd
  refs/heads/master 4641a45c2 -> a4562daaa


CAMEL-8327: Fixed weaveByType when using Choice not working.


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

Branch: refs/heads/master
Commit: a4562daaa1c6a5a847e839070d53367a81a3a133
Parents: 4641a45
Author: Claus Ibsen <davscl...@apache.org>
Authored: Tue Feb 10 07:14:29 2015 +0100
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Tue Feb 10 07:54:42 2015 +0100

----------------------------------------------------------------------
 .../camel/model/ProcessorDefinitionHelper.java  | 18 ++++++
 .../issues/AdviceWithWeaveByTypeCBRTest.java    | 62 ++++++++++++++++++++
 .../model/ProcessorDefinitionHelperTest.java    |  1 +
 3 files changed, 81 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a4562daa/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 315b35a..67b107c 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
@@ -219,6 +219,12 @@ public final class ProcessorDefinitionHelper {
             // special for choice
             if (out instanceof ChoiceDefinition) {
                 ChoiceDefinition choice = (ChoiceDefinition) out;
+
+                // ensure to add ourself if we match also
+                if (type.isInstance(choice)) {
+                    found.add((T)choice);
+                }
+
                 for (WhenDefinition when : choice.getWhenClauses()) {
                     if (type.isInstance(when)) {
                         found.add((T)when);   
@@ -240,6 +246,12 @@ public final class ProcessorDefinitionHelper {
             // special for try ... catch ... finally
             if (out instanceof TryDefinition) {
                 TryDefinition doTry = (TryDefinition) out;
+
+                // ensure to add ourself if we match also
+                if (type.isInstance(doTry)) {
+                    found.add((T)doTry);
+                }
+
                 List<ProcessorDefinition<?>> doTryOut = 
doTry.getOutputsWithoutCatches();
                 doFindType(doTryOut, type, found);
 
@@ -259,6 +271,12 @@ public final class ProcessorDefinitionHelper {
             // special for some types which has special outputs
             if (out instanceof OutputDefinition) {
                 OutputDefinition outDef = (OutputDefinition) out;
+
+                // ensure to add ourself if we match also
+                if (type.isInstance(outDef)) {
+                    found.add((T)outDef);
+                }
+
                 List<ProcessorDefinition<?>> outDefOut = outDef.getOutputs();
                 doFindType(outDefOut, type, found);
 

http://git-wip-us.apache.org/repos/asf/camel/blob/a4562daa/camel-core/src/test/java/org/apache/camel/issues/AdviceWithWeaveByTypeCBRTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/issues/AdviceWithWeaveByTypeCBRTest.java
 
b/camel-core/src/test/java/org/apache/camel/issues/AdviceWithWeaveByTypeCBRTest.java
new file mode 100644
index 0000000..2aebf55
--- /dev/null
+++ 
b/camel-core/src/test/java/org/apache/camel/issues/AdviceWithWeaveByTypeCBRTest.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.issues;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.AdviceWithRouteBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.ChoiceDefinition;
+
+/**
+ * @version
+ */
+public class AdviceWithWeaveByTypeCBRTest extends ContextTestSupport {
+
+    public void testWeaveByType() throws Exception {
+        context.getRouteDefinitions().get(0).adviceWith(context, new 
AdviceWithRouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                weaveByType(ChoiceDefinition.class).replace().to("mock:baz");
+            }
+        });
+
+        getMockEndpoint("mock:baz").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .transform(simple("Hello ${body}"))
+                    .log("Got ${body}")
+                    .to("mock:result")
+                    .choice()
+                        .when(header("foo").isEqualTo("bar"))
+                        .to("mock:resultA")
+                    .otherwise()
+                        .to("mock:resultB");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a4562daa/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
index 8aa7b0c..2116bee 100644
--- 
a/camel-core/src/test/java/org/apache/camel/model/ProcessorDefinitionHelperTest.java
+++ 
b/camel-core/src/test/java/org/apache/camel/model/ProcessorDefinitionHelperTest.java
@@ -29,6 +29,7 @@ public class ProcessorDefinitionHelperTest extends 
ContextTestSupport {
         Iterator<ProcessorDefinition> it = 
ProcessorDefinitionHelper.filterTypeInOutputs(route.getOutputs(), 
ProcessorDefinition.class);
         assertNotNull(it);
 
+        assertEquals("choice1", it.next().getId());
         assertEquals("whenfoo", it.next().getId());
         assertEquals("foo", it.next().getId());
         assertEquals("whenbar", it.next().getId());

Reply via email to