CAMEL-6447: Fixed CBR not working correctly when being nested. Also fixed
endChoice to work better when nested.
Conflicts:
camel-core/src/main/java/org/apache/camel/processor/ChoiceProcessor.java
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/27a5f833
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/27a5f833
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/27a5f833
Branch: refs/heads/camel-2.11.x
Commit: 27a5f833bb87f9bd99c129f5f739456aeaee8dd5
Parents: ba58c25
Author: Claus Ibsen <[email protected]>
Authored: Thu Aug 22 21:40:41 2013 +0200
Committer: Claus Ibsen <[email protected]>
Committed: Thu Aug 22 22:36:38 2013 +0200
----------------------------------------------------------------------
.../apache/camel/model/ProcessorDefinition.java | 7 +-
.../camel/processor/NestedChoiceIssueTest.java | 74 +++++++++++++++
.../processor/TripleNestedChoiceIssueTest.java | 93 +++++++++++++++++++
.../async/AsyncNestedTripleChoiceIssueTest.java | 97 ++++++++++++++++++++
.../processor/SpringNestedChoiceIssueTest.java | 32 +++++++
.../processor/SpringNestedChoiceIssueTest.xml | 48 ++++++++++
6 files changed, 350 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/27a5f833/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
----------------------------------------------------------------------
diff --git
a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index a01d95c..c9b37a8 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -1274,8 +1274,13 @@ public abstract class ProcessorDefinition<Type extends
ProcessorDefinition<Type>
* @return the builder
*/
public ChoiceDefinition endChoice() {
- // are we already a choice?
+ // are we nested choice?
ProcessorDefinition<?> def = this;
+ if (def.getParent() instanceof WhenDefinition) {
+ return (ChoiceDefinition) def.getParent().getParent();
+ }
+
+ // are we already a choice?
if (def instanceof ChoiceDefinition) {
return (ChoiceDefinition) def;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/27a5f833/camel-core/src/test/java/org/apache/camel/processor/NestedChoiceIssueTest.java
----------------------------------------------------------------------
diff --git
a/camel-core/src/test/java/org/apache/camel/processor/NestedChoiceIssueTest.java
b/camel-core/src/test/java/org/apache/camel/processor/NestedChoiceIssueTest.java
new file mode 100644
index 0000000..bb74f3c
--- /dev/null
+++
b/camel-core/src/test/java/org/apache/camel/processor/NestedChoiceIssueTest.java
@@ -0,0 +1,74 @@
+/**
+ * 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;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+public class NestedChoiceIssueTest extends ContextTestSupport {
+
+ public void testNestedChoiceBig() throws Exception {
+ getMockEndpoint("mock:low").expectedMessageCount(0);
+ getMockEndpoint("mock:med").expectedMessageCount(0);
+ getMockEndpoint("mock:big").expectedMessageCount(1);
+
+ template.sendBodyAndHeader("direct:start", "Hello World", "foo", 10);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testNestedChoiceMed() throws Exception {
+ getMockEndpoint("mock:low").expectedMessageCount(0);
+ getMockEndpoint("mock:med").expectedMessageCount(1);
+ getMockEndpoint("mock:big").expectedMessageCount(0);
+
+ template.sendBodyAndHeader("direct:start", "Hello World", "foo", 4);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testNestedChoiceLow() throws Exception {
+ getMockEndpoint("mock:low").expectedMessageCount(1);
+ getMockEndpoint("mock:med").expectedMessageCount(0);
+ getMockEndpoint("mock:big").expectedMessageCount(0);
+
+ template.sendBodyAndHeader("direct:start", "Hello World", "foo", 1);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .choice()
+ .when(header("foo").isGreaterThan(1))
+ .choice()
+ .when(header("foo").isGreaterThan(5))
+ .to("mock:big")
+ .otherwise()
+ .to("mock:med")
+ .endChoice()
+ .otherwise()
+ .to("mock:low")
+ .end();
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/27a5f833/camel-core/src/test/java/org/apache/camel/processor/TripleNestedChoiceIssueTest.java
----------------------------------------------------------------------
diff --git
a/camel-core/src/test/java/org/apache/camel/processor/TripleNestedChoiceIssueTest.java
b/camel-core/src/test/java/org/apache/camel/processor/TripleNestedChoiceIssueTest.java
new file mode 100644
index 0000000..713deda
--- /dev/null
+++
b/camel-core/src/test/java/org/apache/camel/processor/TripleNestedChoiceIssueTest.java
@@ -0,0 +1,93 @@
+/**
+ * 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;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+public class TripleNestedChoiceIssueTest extends ContextTestSupport {
+
+ public void testNestedChoiceVeryBig() throws Exception {
+ getMockEndpoint("mock:low").expectedMessageCount(0);
+ getMockEndpoint("mock:med").expectedMessageCount(0);
+ getMockEndpoint("mock:big").expectedMessageCount(0);
+ getMockEndpoint("mock:verybig").expectedMessageCount(1);
+
+ template.sendBodyAndHeader("direct:start", "Hello World", "foo", 20);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testNestedChoiceBig() throws Exception {
+ getMockEndpoint("mock:low").expectedMessageCount(0);
+ getMockEndpoint("mock:med").expectedMessageCount(0);
+ getMockEndpoint("mock:big").expectedMessageCount(1);
+ getMockEndpoint("mock:verybig").expectedMessageCount(0);
+
+ template.sendBodyAndHeader("direct:start", "Hello World", "foo", 10);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testNestedChoiceMed() throws Exception {
+ getMockEndpoint("mock:low").expectedMessageCount(0);
+ getMockEndpoint("mock:med").expectedMessageCount(1);
+ getMockEndpoint("mock:big").expectedMessageCount(0);
+ getMockEndpoint("mock:verybig").expectedMessageCount(0);
+
+ template.sendBodyAndHeader("direct:start", "Hello World", "foo", 4);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testNestedChoiceLow() throws Exception {
+ getMockEndpoint("mock:low").expectedMessageCount(1);
+ getMockEndpoint("mock:med").expectedMessageCount(0);
+ getMockEndpoint("mock:big").expectedMessageCount(0);
+ getMockEndpoint("mock:verybig").expectedMessageCount(0);
+
+ template.sendBodyAndHeader("direct:start", "Hello World", "foo", 1);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .choice()
+ .when(header("foo").isGreaterThan(1))
+ .choice()
+ .when(header("foo").isGreaterThan(5))
+ .choice()
+ .when(header("foo").isGreaterThan(10))
+ .to("mock:verybig")
+ .otherwise()
+ .to("mock:big")
+ .endChoice()
+ .otherwise()
+ .to("mock:med")
+ .endChoice()
+ .otherwise()
+ .to("mock:low")
+ .end();
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/27a5f833/camel-core/src/test/java/org/apache/camel/processor/async/AsyncNestedTripleChoiceIssueTest.java
----------------------------------------------------------------------
diff --git
a/camel-core/src/test/java/org/apache/camel/processor/async/AsyncNestedTripleChoiceIssueTest.java
b/camel-core/src/test/java/org/apache/camel/processor/async/AsyncNestedTripleChoiceIssueTest.java
new file mode 100644
index 0000000..2cc0561
--- /dev/null
+++
b/camel-core/src/test/java/org/apache/camel/processor/async/AsyncNestedTripleChoiceIssueTest.java
@@ -0,0 +1,97 @@
+/**
+ * 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.async;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+public class AsyncNestedTripleChoiceIssueTest extends ContextTestSupport {
+
+ public void testNestedChoiceVeryBig() throws Exception {
+ getMockEndpoint("mock:low").expectedMessageCount(0);
+ getMockEndpoint("mock:med").expectedMessageCount(0);
+ getMockEndpoint("mock:big").expectedMessageCount(0);
+ getMockEndpoint("mock:verybig").expectedMessageCount(1);
+
+ template.sendBodyAndHeader("direct:start", "Hello World", "foo", 10);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testNestedChoiceBig() throws Exception {
+ getMockEndpoint("mock:low").expectedMessageCount(0);
+ getMockEndpoint("mock:med").expectedMessageCount(0);
+ getMockEndpoint("mock:big").expectedMessageCount(1);
+ getMockEndpoint("mock:verybig").expectedMessageCount(0);
+
+ template.sendBodyAndHeader("direct:start", "Hello World", "foo", 7);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testNestedChoiceMed() throws Exception {
+ getMockEndpoint("mock:low").expectedMessageCount(0);
+ getMockEndpoint("mock:med").expectedMessageCount(1);
+ getMockEndpoint("mock:big").expectedMessageCount(0);
+ getMockEndpoint("mock:verybig").expectedMessageCount(0);
+
+ template.sendBodyAndHeader("direct:start", "Hello World", "foo", 4);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testNestedChoiceLow() throws Exception {
+ getMockEndpoint("mock:low").expectedMessageCount(1);
+ getMockEndpoint("mock:med").expectedMessageCount(0);
+ getMockEndpoint("mock:big").expectedMessageCount(0);
+ getMockEndpoint("mock:verybig").expectedMessageCount(0);
+
+ template.sendBodyAndHeader("direct:start", "Hello World", "foo", 1);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ context.addComponent("async", new MyAsyncComponent());
+
+ from("direct:start")
+ .choice()
+ .when(header("foo").isGreaterThan(1))
+ .to("async:bye:camel")
+ .choice()
+ .when(header("foo").isGreaterThan(5))
+ .to("async:bye:camel2")
+ .choice()
+ .when(header("foo").isGreaterThan(7))
+ .to("mock:verybig")
+ .otherwise()
+ .to("mock:big")
+ .endChoice()
+ .otherwise()
+ .to("mock:med")
+ .endChoice()
+ .otherwise()
+ .to("mock:low")
+ .end();
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/27a5f833/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringNestedChoiceIssueTest.java
----------------------------------------------------------------------
diff --git
a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringNestedChoiceIssueTest.java
b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringNestedChoiceIssueTest.java
new file mode 100644
index 0000000..2a471ff
--- /dev/null
+++
b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringNestedChoiceIssueTest.java
@@ -0,0 +1,32 @@
+/**
+ * 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.spring.processor;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.processor.NestedChoiceIssueTest;
+
+import static
org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+/**
+ * @version
+ */
+public class SpringNestedChoiceIssueTest extends NestedChoiceIssueTest {
+
+ protected CamelContext createCamelContext() throws Exception {
+ return createSpringCamelContext(this,
"org/apache/camel/spring/processor/SpringNestedChoiceIssueTest.xml");
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/27a5f833/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringNestedChoiceIssueTest.xml
----------------------------------------------------------------------
diff --git
a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringNestedChoiceIssueTest.xml
b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringNestedChoiceIssueTest.xml
new file mode 100644
index 0000000..ea9c7a3
--- /dev/null
+++
b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringNestedChoiceIssueTest.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <choice>
+ <when>
+ <simple>${header.foo} > 1</simple>
+ <choice>
+ <when>
+ <simple>${header.foo} > 5</simple>
+ <to uri="mock:big"/>
+ </when>
+ <otherwise>
+ <to uri="mock:med"/>
+ </otherwise>
+ </choice>
+ </when>
+ <otherwise>
+ <to uri="mock:low"/>
+ </otherwise>
+ </choice>
+ </route>
+ </camelContext>
+
+</beans>