camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1442046 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/model/ProcessorDefinition.java test/java/org/apache/camel/processor/CBRWhenUnmarshalEndChoiceTest.java
Date Mon, 04 Feb 2013 08:12:08 GMT
Author: davsclaus
Date: Mon Feb  4 08:12:08 2013
New Revision: 1442046

URL: http://svn.apache.org/viewvc?rev=1442046&view=rev
Log:
CAMEL-5953: Fixed Java DSL endChoice to avoid class cast exception when using unmarshal.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWhenUnmarshalEndChoiceTest.java
      - copied, changed from r1441903, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SimpleMockTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java?rev=1442046&r1=1442045&r2=1442046&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java Mon
Feb  4 08:12:08 2013
@@ -1248,7 +1248,14 @@ public abstract class ProcessorDefinitio
      * @return the builder
      */
     public ChoiceDefinition endChoice() {
-        ProcessorDefinition<?> def = end();
+        // are we already a choice?
+        ProcessorDefinition<?> def = this;
+        if (def instanceof ChoiceDefinition) {
+            return (ChoiceDefinition) def;
+        }
+
+        // okay end this and get back to the choice
+        def = end();
         if (def instanceof WhenDefinition) {
             return (ChoiceDefinition) def.getParent();
         } else if (def instanceof OtherwiseDefinition) {

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWhenUnmarshalEndChoiceTest.java
(from r1441903, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SimpleMockTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWhenUnmarshalEndChoiceTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWhenUnmarshalEndChoiceTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SimpleMockTest.java&r1=1441903&r2=1442046&rev=1442046&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SimpleMockTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRWhenUnmarshalEndChoiceTest.java
Mon Feb  4 08:12:08 2013
@@ -18,28 +18,20 @@ package org.apache.camel.processor;
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
 
 /**
  * @version 
  */
-public class SimpleMockTest extends ContextTestSupport {
+public class CBRWhenUnmarshalEndChoiceTest extends ContextTestSupport {
 
-    public void testSimple() throws Exception {
-        MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedBodiesReceived("Hello World");
-
-        template.sendBody("direct:start", "Hello World");
-
-        assertMockEndpointsSatisfied();
-    }
-
-    public void testSimpleTwoMessages() throws Exception {
-        MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedBodiesReceived("Hello World", "Bye World");
-
-        template.sendBody("direct:start", "Hello World");
-        template.sendBody("direct:start", "Bye World");
+    public void testCBR() throws Exception {
+        getMockEndpoint("mock:when").expectedMessageCount(1);
+        getMockEndpoint("mock:other").expectedMessageCount(1);
+        getMockEndpoint("mock:result").expectedMessageCount(2);
+
+        template.sendBody("direct:abc", "Hello World");
+        template.sendBody("direct:abc", null);
+        template.sendBody("direct:abc", "Please do not fail");
 
         assertMockEndpointsSatisfied();
     }
@@ -49,7 +41,17 @@ public class SimpleMockTest extends Cont
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("direct:start").to("log:foo").to("log:bar").to("mock:result");
+                from("direct:abc")
+                    .filter(body().isNotNull())
+                        .choice()
+                            .when().simple("${body} == 'Please do not fail'")
+                                .to("mock:when")
+                                .unmarshal().string().endChoice()
+                            .otherwise()
+                                .to("mock:other")
+                            .end()
+                        .to("mock:result")
+                    .end();
             }
         };
     }



Mime
View raw message