camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r784038 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/management/ camel-core/src/main/java/org/apache/camel/model/ camel-core/src/test/java/org/apache/camel/processor/ camel-core/src/test/java/org/apache/camel/processor/inter...
Date Fri, 12 Jun 2009 09:00:33 GMT
Author: davsclaus
Date: Fri Jun 12 09:00:33 2009
New Revision: 784038

URL: http://svn.apache.org/viewvc?rev=784038&view=rev
Log:
CAMEL-1697: Added more unit tests regarding using .end(). Simplyfied using .end() with doTry
as we just need 1 end to end the block.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceWithEndTest.java
  (with props)
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitWithEndTest.java
  (with props)
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitWithNestedFilterShouldSkipFilteredExchanges.java
      - copied, changed from r783688, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitShouldSkipFilteredExchanges.java
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringComplexBlockWithEndTest.java
      - copied, changed from r783977, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringAggregatorWithCustomStrategyTest.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringComplexBlockWithEndTest.xml
      - copied, changed from r783977, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/multicast.xml
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/ChoiceDefinition.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryDefinition.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitShouldSkipFilteredExchanges.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromWhenWithChoiceTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java?rev=784038&r1=784037&r2=784038&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
Fri Jun 12 09:00:33 2009
@@ -272,6 +272,10 @@
 
                 return wrapper;
             }
+
+            public String toString() {
+                return "Instrument";
+            }
         });
 
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ChoiceDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ChoiceDefinition.java?rev=784038&r1=784037&r2=784038&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ChoiceDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ChoiceDefinition.java Fri
Jun 12 09:00:33 2009
@@ -33,8 +33,6 @@
 import org.apache.camel.processor.FilterProcessor;
 import org.apache.camel.spi.RouteContext;
 import org.apache.camel.util.CollectionStringBuffer;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
 /**
  * Represents an XML <choice/> element
@@ -44,8 +42,7 @@
 @XmlRootElement(name = "choice")
 @XmlAccessorType(XmlAccessType.FIELD)
 public class ChoiceDefinition extends ProcessorDefinition<ChoiceDefinition> {
-    private static final transient Log LOG = LogFactory.getLog(ChoiceDefinition.class);
-    
+
     @XmlElementRef
     private List<WhenDefinition> whenClauses = new ArrayList<WhenDefinition>();
     @XmlElement(required = false)
@@ -74,8 +71,6 @@
         Processor otherwiseProcessor = null;
         if (otherwise != null) {
             otherwiseProcessor = otherwise.createProcessor(routeContext);
-        } else {
-            LOG.warn("No otherwise clause was specified for this choice block: " + this +
", any unmatched exchanges will be dropped.");
         }
         return new ChoiceProcessor(filters, otherwiseProcessor);
     }
@@ -157,4 +152,5 @@
     public void setOtherwise(OtherwiseDefinition otherwise) {
         this.otherwise = otherwise;
     }
+
 }

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=784038&r1=784037&r2=784038&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 Fri
Jun 12 09:00:33 2009
@@ -714,9 +714,16 @@
      */
     @SuppressWarnings("unchecked")
     public ProcessorDefinition<? extends ProcessorDefinition> end() {
+        // when using doTry .. doCatch .. doFinally we should always
+        // end the try definition to avoid having to use 2 x end() in the route
+        // this is counter intuitive for end users
+        if (this instanceof TryDefinition) {
+            popBlock();
+        }
+
         if (blocks.isEmpty()) {
             if (parent == null) {
-                throw new IllegalArgumentException("Root node with no active block");
+                return this; 
             }
             return parent;
         }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryDefinition.java?rev=784038&r1=784037&r2=784038&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryDefinition.java Fri Jun
12 09:00:33 2009
@@ -102,6 +102,19 @@
     }
 
     /**
+     * The finally block for a given handle
+     *
+     * @return  the try builder
+     */
+    public TryDefinition doFinally() {
+        popBlock();
+        FinallyDefinition answer = new FinallyDefinition();
+        addOutput(answer);
+        pushBlock(answer);
+        return this;
+    }
+
+    /**
      * Sets an additional predicate that should be true before the onCatch is triggered.
      * <p/>
      * To be used for fine grained controlling whether a thrown exception should be intercepted
@@ -186,25 +199,6 @@
         return handled(toPredicate(handled));
     }
 
-    /**
-     * The finally block for a given handle
-     *
-     * @return  the try builder
-     */
-    public TryDefinition doFinally() {
-        popBlock();
-        FinallyDefinition answer = new FinallyDefinition();
-        addOutput(answer);
-        pushBlock(answer);
-        return this;
-    }
-
-    @Override
-    public ProcessorDefinition<? extends ProcessorDefinition> end() {
-        popBlock();
-        return super.end();
-    }
-
     // Properties
     // -------------------------------------------------------------------------
 

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceWithEndTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceWithEndTest.java?rev=784038&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceWithEndTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceWithEndTest.java
Fri Jun 12 09:00:33 2009
@@ -0,0 +1,126 @@
+/**
+ * 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 java.util.List;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Navigate;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class ChoiceWithEndTest extends ContextTestSupport {
+
+    public void testRouteIsCorrectAtRuntime() throws Exception {
+        // use navigate to find that the end works as expected
+        Navigate<Processor> nav = context.getRoutes().get(0).navigate();
+        List<Processor> node = nav.next();
+        node = ((Navigate) node.get(0)).next();
+
+        // there should be 4 outputs as the end in the otherwise should
+        // ensure that the transform and last send is not within the choice
+        assertEquals(4, node.size());
+        // the navigate API is a bit simple at this time of writing so it does take a little
+        // bit of ugly code to find the correct processor in the runtime route
+        assertIsInstanceOf(SendProcessor.class, unwrapChannel(node.get(0)).getNextProcessor());
+        assertIsInstanceOf(ChoiceProcessor.class, unwrapChannel(node.get(1)).getNextProcessor());
+        assertIsInstanceOf(TransformProcessor.class, unwrapChannel(node.get(2)).getNextProcessor());
+        assertIsInstanceOf(SendProcessor.class, unwrapChannel(node.get(3)).getNextProcessor());
+    }
+
+    public void testChoiceHello() throws Exception {
+        getMockEndpoint("mock:start").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:echo").expectedBodiesReceived("echo Hello World");
+        getMockEndpoint("mock:last").expectedBodiesReceived("last echo Hello World");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testChoiceBye() throws Exception {
+        getMockEndpoint("mock:start").expectedBodiesReceived("Bye World");
+        getMockEndpoint("mock:bye").expectedBodiesReceived("We do not care");
+        getMockEndpoint("mock:last").expectedBodiesReceived("last We do not care");
+
+        template.sendBody("direct:start", "Bye World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testChoiceOther() throws Exception {
+        getMockEndpoint("mock:start").expectedBodiesReceived("Camel");
+        getMockEndpoint("mock:other").expectedBodiesReceived("other Camel");
+        getMockEndpoint("mock:last").expectedBodiesReceived("last other Camel");
+
+        template.sendBody("direct:start", "Camel");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                MyChoiceBean bean = new MyChoiceBean();
+
+                from("direct:start")
+                    .to("mock:start")
+                    .choice()
+                        .when(body().contains("Hello"))
+                            .bean(bean, "echo").to("mock:echo")
+                        .when(body().contains("Bye"))
+                            // must use another route as the Java DSL
+                            // will lose its scope so you cannot call otherwise later
+                            .to("direct:bye").to("mock:bye")
+                        .otherwise()
+                            .bean(bean, "other").to("mock:other")
+                        .end()
+                    .transform(body().prepend("last "))
+                    .to("mock:last");
+
+                from("direct:bye")
+                    .doTry()
+                        .bean(bean, "bye").to("mock:bye")
+                    .doCatch(Exception.class)
+                        .setBody(constant("We do not care"))
+                    .end();
+            }
+        };
+    }
+
+    public class MyChoiceBean {
+
+        public String echo(String s) {
+            return "echo " + s;
+        }
+
+        public String bye(String s) throws Exception {
+            throw new IllegalArgumentException("Damn does not work");
+        }
+
+        public String other(String s) {
+            return "other " + s;
+        }
+    }
+
+}
+

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceWithEndTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceWithEndTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitShouldSkipFilteredExchanges.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitShouldSkipFilteredExchanges.java?rev=784038&r1=784037&r2=784038&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitShouldSkipFilteredExchanges.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitShouldSkipFilteredExchanges.java
Fri Jun 12 09:00:33 2009
@@ -64,16 +64,15 @@
                 from("direct:split")
                     .split(body(List.class), new MyAggregationStrategy())
                         .filter(goodWord)
-                        .to("mock:filtered");
+                            .to("mock:filtered");
             }
         };
     }
 
-    private class MyAggregationStrategy implements AggregationStrategy {
+    protected class MyAggregationStrategy implements AggregationStrategy {
 
         public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
             String newBody = newExchange.getIn().getBody(String.class);
-            assertTrue("Should have been filtered: " + newBody, newBody.contains("World"));
 
             if (oldExchange == null) {
                 return newExchange;

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitWithEndTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitWithEndTest.java?rev=784038&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitWithEndTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitWithEndTest.java
Fri Jun 12 09:00:33 2009
@@ -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;
+
+import java.util.List;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Navigate;
+import org.apache.camel.Processor;
+import org.apache.camel.Exchange;
+import org.apache.camel.processor.aggregate.AggregationStrategy;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class SplitWithEndTest extends ContextTestSupport {
+
+    public void testRouteIsCorrectAtRuntime() throws Exception {
+        // use navigate to find that the end works as expected
+        Navigate<Processor> nav = context.getRoutes().get(0).navigate();
+        List<Processor> node = nav.next();
+        node = ((Navigate) node.get(0)).next();
+
+        // there should be 4 outputs as the end in the otherwise should
+        // ensure that the transform and last send is not within the choice
+        assertEquals(4, node.size());
+        // the navigate API is a bit simple at this time of writing so it does take a little
+        // bit of ugly code to find the correct processor in the runtime route
+        assertIsInstanceOf(SendProcessor.class, unwrapChannel(node.get(0)).getNextProcessor());
+        assertIsInstanceOf(Splitter.class, unwrapChannel(node.get(1)).getNextProcessor());
+        assertIsInstanceOf(TransformProcessor.class, unwrapChannel(node.get(2)).getNextProcessor());
+        assertIsInstanceOf(SendProcessor.class, unwrapChannel(node.get(3)).getNextProcessor());
+    }
+
+    public void testSplit() throws Exception {
+        getMockEndpoint("mock:start").expectedBodiesReceived("Hello,World");
+        getMockEndpoint("mock:last").expectedBodiesReceived("last hi Hello@hi World");
+
+        template.sendBody("direct:start", "Hello,World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                MySplitBean bean = new MySplitBean();
+
+                from("direct:start")
+                    .to("mock:start")
+                    .split(body().tokenize(","),
+                            new AggregationStrategy() {
+                                public Exchange aggregate(Exchange oldExchange, Exchange
newExchange) {
+                                    if (oldExchange == null) {
+                                        return newExchange;
+                                    }
+                                    String body = oldExchange.getIn().getBody(String.class);
+                                    String newBody = newExchange.getIn().getBody(String.class);
+                                    newExchange.getIn().setBody(body + "@" + newBody);
+                                    return newExchange;
+                                }
+                            })
+                        .bean(bean, "hi").to("mock:split")
+                    .end()
+                    .transform(body().prepend("last "))
+                    .to("mock:last");
+            }
+        };
+    }
+
+    public class MySplitBean {
+
+        public String hi(String s) {
+            return "hi " + s;
+        }
+
+    }
+
+}
\ No newline at end of file

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitWithEndTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitWithEndTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitWithNestedFilterShouldSkipFilteredExchanges.java
(from r783688, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitShouldSkipFilteredExchanges.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitWithNestedFilterShouldSkipFilteredExchanges.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitWithNestedFilterShouldSkipFilteredExchanges.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitShouldSkipFilteredExchanges.java&r1=783688&r2=784038&rev=784038&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitShouldSkipFilteredExchanges.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitWithNestedFilterShouldSkipFilteredExchanges.java
Fri Jun 12 09:00:33 2009
@@ -16,74 +16,35 @@
  */
 package org.apache.camel.processor;
 
-import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.camel.ContextTestSupport;
-import org.apache.camel.Exchange;
 import org.apache.camel.Predicate;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.processor.aggregate.AggregationStrategy;
 
 /**
  * Unit test to verify that Splitter aggregator does not included filtered exchanges.
  *
  * @version $Revision$
  */
-public class SplitShouldSkipFilteredExchanges extends ContextTestSupport {
-
-    public void testSplitWithFilter() throws Exception {
-        MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedBodiesReceived("Hello World,Bye World");
-
-        MockEndpoint filtered = getMockEndpoint("mock:filtered");
-        filtered.expectedBodiesReceived("Hello World", "Bye World");
-
-        List<String> body = new ArrayList<String>();
-        body.add("Hello World");
-        body.add("Hi there");
-        body.add("Bye World");
-        body.add("How do you do?");
-
-        template.sendBody("direct:start", body);
-
-        assertMockEndpointsSatisfied();
-    }
+public class SplitWithNestedFilterShouldSkipFilteredExchanges extends SplitShouldSkipFilteredExchanges
{
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("direct:start")
-                    .to("direct:split")
-                    .to("mock:result");
-
                 Predicate goodWord = body().contains("World");
-                from("direct:split")
+
+                from("direct:start")
                     .split(body(List.class), new MyAggregationStrategy())
+                        .to("mock:split")
                         .filter(goodWord)
-                        .to("mock:filtered");
+                            .to("mock:filtered")
+                        .end()
+                    .end()
+                .to("mock:result");
             }
         };
     }
 
-    private class MyAggregationStrategy implements AggregationStrategy {
-
-        public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
-            String newBody = newExchange.getIn().getBody(String.class);
-            assertTrue("Should have been filtered: " + newBody, newBody.contains("World"));
-
-            if (oldExchange == null) {
-                return newExchange;
-            }
-
-            String body = oldExchange.getIn().getBody(String.class);
-            body = body + "," + newBody;
-            oldExchange.getIn().setBody(body);
-            return oldExchange;
-        }
-
-    }
-}
+}
\ No newline at end of file

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorTest.java?rev=784038&r1=784037&r2=784038&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorTest.java
Fri Jun 12 09:00:33 2009
@@ -33,6 +33,7 @@
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(0);
 
+        getMockEndpoint("mock:last").expectedMessageCount(1);
         getMockEndpoint("mock:finally").expectedMessageCount(1);
 
         sendBody("direct:start", "<test>Hello World!</test>");
@@ -52,7 +53,8 @@
                         .process(new ProcessorHandle())
                     .doFinally()
                         .to("mock:finally")
-                    .end();
+                    .end()
+                    .to("mock:last");
             }
         };
     }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromWhenWithChoiceTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromWhenWithChoiceTest.java?rev=784038&r1=784037&r2=784038&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromWhenWithChoiceTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptFromWhenWithChoiceTest.java
Fri Jun 12 09:00:33 2009
@@ -68,7 +68,7 @@
                     .when(toPredicate(simple("${body} contains 'Goofy'")))
                         .choice()
                             .when(body().contains("Hello")).to("mock:hello")
-                            .otherwise().to("mock:goofy")
+                            .otherwise().to("log:foo").to("mock:goofy")
                         .end()
                     .stop();
 

Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringComplexBlockWithEndTest.java
(from r783977, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringAggregatorWithCustomStrategyTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringComplexBlockWithEndTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringComplexBlockWithEndTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringAggregatorWithCustomStrategyTest.java&r1=783977&r2=784038&rev=784038&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringAggregatorWithCustomStrategyTest.java
(original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringComplexBlockWithEndTest.java
Fri Jun 12 09:00:33 2009
@@ -18,30 +18,63 @@
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.processor.AggregatorTest;
+import org.apache.camel.processor.aggregate.AggregationStrategy;
 import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
 
 /**
  * @version $Revision$
  */
-public class SpringAggregatorWithCustomStrategyTest extends ContextTestSupport {
+public class SpringComplexBlockWithEndTest extends ContextTestSupport {
 
-    public void testSendingMessagesWithCustomAggregator() throws Exception {
-        MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
+    public void testHello() throws Exception {
+        getMockEndpoint("mock:hello").expectedMessageCount(1);
+        getMockEndpoint("mock:bye").expectedMessageCount(0);
+        getMockEndpoint("mock:otherwise").expectedMessageCount(0);
+        getMockEndpoint("mock:result").expectedMessageCount(1);
 
-        resultEndpoint.expectedBodiesReceived("message:1 message:2 message:3");
+        template.sendBody("direct:start", "Hello World");
 
-        // lets send a large batch of messages
-        for (int i = 1; i <= 3; i++) {
-            String body = "message:" + i;
-            template.sendBodyAndHeader("direct:start", body, "cheese", 123);
-        }
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testBye() throws Exception {
+        getMockEndpoint("mock:hello").expectedMessageCount(0);
+        getMockEndpoint("mock:bye").expectedMessageCount(1);
+        getMockEndpoint("mock:otherwise").expectedMessageCount(0);
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Bye World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testOther() throws Exception {
+        getMockEndpoint("mock:hello").expectedMessageCount(0);
+        getMockEndpoint("mock:bye").expectedMessageCount(0);
+        getMockEndpoint("mock:otherwise").expectedMessageCount(1);
+        getMockEndpoint("mock:trapped").expectedMessageCount(1);
+        getMockEndpoint("mock:result").expectedBodiesReceived("Cowboys");
+        getMockEndpoint("mock:split").expectedBodiesReceived("Hi The good", "Hi The ugly");
 
-        resultEndpoint.assertIsSatisfied();
+        template.sendBody("direct:start", "The good,The bad,The ugly");
+
+        assertMockEndpointsSatisfied();
     }
 
     protected CamelContext createCamelContext() throws Exception {
-        return createSpringCamelContext(this, "org/apache/camel/spring/processor/aggregator-custom-strategy.xml");
+        return createSpringCamelContext(this, "org/apache/camel/spring/processor/SpringComplexBlockWithEndTest.xml");
     }
+
+    public static class SplitAggregate implements AggregationStrategy {
+
+        public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+            newExchange.getOut().setBody("Cowboys");
+            return newExchange;
+        }
+
+    }
+
 }
\ No newline at end of file

Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringComplexBlockWithEndTest.xml
(from r783977, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/multicast.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringComplexBlockWithEndTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringComplexBlockWithEndTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/multicast.xml&r1=783977&r2=784038&rev=784038&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/multicast.xml
(original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringComplexBlockWithEndTest.xml
Fri Jun 12 09:00:33 2009
@@ -22,36 +22,47 @@
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
 
+    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+        <route>
+            <from uri="direct:start"/>
+            <choice>
+                <when>
+                    <simple>${in.body} contains 'Hello'</simple>
+                    <pipeline>
+                        <to uri="log:hello"/>
+                        <to uri="mock:hello"/>
+                    </pipeline>
+                </when>
+                <when>
+                    <simple>${in.body} contains 'Bye'</simple>
+                    <multicast parallelProcessing="true">
+                        <to uri="log:bye"/>
+                        <to uri="mock:bye"/>
+                    </multicast>
+                </when>
+                <otherwise>
+                    <to uri="log:otherwise"/>
+                    <to uri="mock:otherwise"/>
+                    <multicast streaming="true">
+                        <wireTap uri="mock:trapped"/>
+                        <split strategyRef="splitAggregate">
+                            <tokenize token=","/>
+                            <filter>
+                                <simple>${in.body} not contains 'bad'</simple>
+                                <transform>
+                                    <simple>Hi ${in.body}</simple>
+                                </transform>
+                                <to uri="mock:split"/>
+                            </filter>
+                        </split>
+                    </multicast>
+                </otherwise>
+            </choice>
+            <to uri="log:result"/>
+            <to uri="mock:result"/>
+        </route>
+    </camelContext>
 
-  <!-- START SNIPPET: example -->
-
-  <bean id="attachStringProcessor" class="org.apache.camel.processor.AppendingProcessor"/>
-
-  <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
-    <route>
-      <from uri="direct:a"/>
-      <multicast>
-          <to uri="direct:x"/>
-          <to uri="direct:y"/>
-          <to uri="direct:z"/>
-      </multicast>
-    </route>
-    <route>
-      <from uri="direct:x"/>
-      <process ref="attachStringProcessor"/>
-      <to uri="mock:x"/>
-    </route>
-    <route>
-      <from uri="direct:y"/>
-      <process ref="attachStringProcessor"/>
-      <to uri="mock:y"/>
-    </route>
-    <route>
-      <from uri="direct:z"/>
-      <process ref="attachStringProcessor"/>
-      <to uri="mock:z"/>
-    </route>
-  </camelContext>
-  <!-- END SNIPPET: example -->
+    <bean id="splitAggregate" class="org.apache.camel.spring.processor.SpringComplexBlockWithEndTest$SplitAggregate"/>
 
 </beans>



Mime
View raw message