svn commit: r734805 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/model/language/ camel-core/src/test/java/org/apache/camel/processor/ components/camel-spring/src/test/java/org/apache/camel/spring/processor/ components/camel-spr...

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r734805 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/model/language/ camel-core/src/test/java/org/apache/camel/processor/ components/camel-spring/src/test/java/org/apache/camel/spring/processor/ components/camel-spr...

davsclaus-2
Author: davsclaus
Date: Thu Jan 15 12:25:51 2009
New Revision: 734805

URL: http://svn.apache.org/viewvc?rev=734805&view=rev
Log:
CAMEL-1261: expression renamed to languageExpression. Added unit test for using methodCall expression for splitter.

Added:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterMethodCallTest.java   (contents, props changed)
      - copied, changed from r734613, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterTest.java
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSplitterMethodCallTest.java   (contents, props changed)
      - copied, changed from r734613, activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringChoiceTest.java
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/splitterMethodCallTest.xml   (contents, props changed)
      - copied, changed from r734613, activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/choice.xml
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/LanguageExpression.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCallExpression.java
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/delayer.xml

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/LanguageExpression.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/LanguageExpression.java?rev=734805&r1=734804&r2=734805&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/LanguageExpression.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/LanguageExpression.java Thu Jan 15 12:25:51 2009
@@ -27,7 +27,7 @@
  *
  * @version $Revision$
  */
-@XmlRootElement(name = "expression")
+@XmlRootElement(name = "languageExpression")
 @XmlAccessorType(XmlAccessType.FIELD)
 public class LanguageExpression extends ExpressionType {
     @XmlAttribute

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCallExpression.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCallExpression.java?rev=734805&r1=734804&r2=734805&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCallExpression.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/MethodCallExpression.java Thu Jan 15 12:25:51 2009
@@ -81,4 +81,9 @@
         }
         return getExpression();
     }
+
+    @Override
+    public String toString() {
+        return "bean{" + beanName() + (method != null ? ", method=" + method : "") + "}";
+    }
 }

Copied: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterMethodCallTest.java (from r734613, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterMethodCallTest.java?p2=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterMethodCallTest.java&p1=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterTest.java&r1=734613&r2=734805&rev=734805&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterMethodCallTest.java Thu Jan 15 12:25:51 2009
@@ -16,217 +16,57 @@
  */
 package org.apache.camel.processor;
 
+import java.util.Arrays;
 import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
 
-import org.apache.camel.CamelException;
 import org.apache.camel.ContextTestSupport;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.processor.aggregate.UseLatestAggregationStrategy;
+import org.apache.camel.impl.JndiRegistry;
 
 /**
  * @version $Revision$
  */
-public class SplitterTest extends ContextTestSupport {
+public class SplitterMethodCallTest extends ContextTestSupport {
 
-    public void testSendingAMessageUsingMulticastReceivesItsOwnExchange() throws Exception {
+    public void testSplitUsingMethodCall() throws Exception {
         MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
-        resultEndpoint.expectedBodiesReceived("James", "Guillaume", "Hiram", "Rob");
+        resultEndpoint.expectedBodiesReceived("Claus", "James", "Willem");
 
-        // InOnly
-        template.send("direct:seqential", new Processor() {
-            public void process(Exchange exchange) {
-                Message in = exchange.getIn();
-                in.setBody("James,Guillaume,Hiram,Rob");
-                in.setHeader("foo", "bar");
-            }
-        });
-
-        assertMockEndpointsSatisfied();
-
-        List<Exchange> list = resultEndpoint.getReceivedExchanges();
-        for (int i = 0; i < 4; i++) {
-            Exchange exchange = list.get(i);
-            Message in = exchange.getIn();
-            assertMessageHeader(in, Splitter.SPLIT_COUNTER, i);
-            assertMessageHeader(in, Splitter.SPLIT_SIZE, 4);
-        }
-    }
-
-    public void testSpliterWithAggregationStrategy() throws Exception {
-        MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
-        resultEndpoint.expectedBodiesReceived("James", "Guillaume", "Hiram", "Rob", "Roman");
-
-        Exchange result = template.request("direct:seqential", new Processor() {
-            public void process(Exchange exchange) {
-                Message in = exchange.getIn();
-                in.setBody("James,Guillaume,Hiram,Rob,Roman");
-                in.setHeader("foo", "bar");
-            }
-        });
+        template.sendBody("direct:start", "Claus@James@Willem");
 
         assertMockEndpointsSatisfied();
-        Message out = result.getOut();
-        assertEquals("Roman", out.getBody());
-        assertMessageHeader(out, "foo", "bar");
-        assertMessageHeader(out, Splitter.SPLIT_COUNTER, 4);
-    }
-
-    public void testEmptyBody() {
-        Exchange result = template.request("direct:seqential", new Processor() {
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader("foo", "bar");
-            }
-        });
-
-        assertNull(result.getOut(false));
     }
 
-    public void testSendingAMessageUsingMulticastReceivesItsOwnExchangeParallel() throws Exception {
-        MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
-
-        resultEndpoint.expectsNoDuplicates(body());
-        resultEndpoint.expectedMessageCount(4);
-
-        // InOnly
-        template.send("direct:parallel", new Processor() {
-            public void process(Exchange exchange) {
-                Message in = exchange.getIn();
-                in.setBody("James,Guillaume,Hiram,Rob");
-                in.setHeader("foo", "bar");
-            }
-        });
-
-        assertMockEndpointsSatisfied();
-
-        List<Exchange> list = resultEndpoint.getReceivedExchanges();
-
-        Set<Integer> numbersFound = new TreeSet<Integer>();
-
-        final String[] names = {"James", "Guillaume", "Hiram", "Rob"};
-
-        for (int i = 0; i < 4; i++) {
-            Exchange exchange = list.get(i);
-            Message in = exchange.getIn();
-            Integer splitCounter = in.getHeader(Splitter.SPLIT_COUNTER, Integer.class);
-            numbersFound.add(splitCounter);
-            assertEquals(names[splitCounter], in.getBody());
-            assertMessageHeader(in, Splitter.SPLIT_SIZE, 4);
-        }
-
-        assertEquals(4, numbersFound.size());
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+        jndi.bind("splitterBean", new SplitWordsBean());
+        return jndi;
     }
 
-    public void testSpliterWithAggregationStrategyParallel() throws Exception {
-        MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
-        resultEndpoint.expectedMessageCount(5);
-
-        Exchange result = template.request("direct:parallel", new Processor() {
-            public void process(Exchange exchange) {
-                Message in = exchange.getIn();
-                in.setBody("James,Guillaume,Hiram,Rob,Roman");
-                in.setHeader("foo", "bar");
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                // START SNIPPET: e1
+                from("direct:start")
+                    .split().method("splitterBean", "splitWords")
+                    .to("mock:result");
+                // END SNIPPET: e1
             }
-        });
-
-        assertMockEndpointsSatisfied();
-        Message out = result.getOut();
-
-        assertMessageHeader(out, "foo", "bar");
-        assertEquals((Integer)5, result.getProperty("aggregated", Integer.class));
+        };
     }
-    
-    public void testSpliterWithAggregationStrategyParallelStreaming() throws Exception {
-        MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
-        resultEndpoint.expectedMessageCount(5);
-        resultEndpoint.expectedBodiesReceivedInAnyOrder("James", "Guillaume", "Hiram", "Rob", "Roman");
-
-        Exchange result = template.request("direct:parallel-streaming", new Processor() {
-            public void process(Exchange exchange) {
-                Message in = exchange.getIn();
-                in.setBody("James,Guillaume,Hiram,Rob,Roman");
-                in.setHeader("foo", "bar");
-            }
-        });
 
-        assertMockEndpointsSatisfied();
-        Message out = result.getOut();
-
-        assertMessageHeader(out, "foo", "bar");
-        assertEquals((Integer)5, result.getProperty("aggregated", Integer.class));
-    }
-    
-    public void testSplitterWithStreaming() throws Exception {
-        MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
-        resultEndpoint.expectedMessageCount(5);
-        resultEndpoint.expectedHeaderReceived("foo", "bar");
+    // START SNIPPET: e2
+    public static class SplitWordsBean {
 
-        template.request("direct:streaming", new Processor() {
-            public void process(Exchange exchange) {
-                Message in = exchange.getIn();
-                in.setBody("James,Guillaume,Hiram,Rob,Roman");
-                in.setHeader("foo", "bar");
-            }
-        });
-        
-        assertMockEndpointsSatisfied();
-        for (Exchange exchange : resultEndpoint.getReceivedExchanges()) {
-            assertNotNull(exchange.getIn().getHeader(Splitter.SPLIT_COUNTER));
-            //this header cannot be set when streaming is used
-            assertNull(exchange.getIn().getHeader(Splitter.SPLIT_SIZE));
+        public static List<String> splitWords(String body) {
+            // here we split the payload using java code
+            // we have the true power of Java to do the splitting
+            // as we like. As this is based on a unit test we just do it easy
+            return Arrays.asList(body.split("@"));
         }
 
     }
-    
-    public void testSplitterWithException() throws Exception {
-        MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
-        resultEndpoint.expectedMessageCount(4);
-        resultEndpoint.expectedHeaderReceived("foo", "bar");
-        
-        MockEndpoint failedEndpoint = getMockEndpoint("mock:failed");
-        failedEndpoint.expectedMessageCount(1);
-        failedEndpoint.expectedHeaderReceived("foo", "bar");
-        
-        Exchange result = template.request("direct:exception", new Processor() {
-            public void process(Exchange exchange) {
-                Message in = exchange.getIn();
-                in.setBody("James,Guillaume,Hiram,Rob,Exception");
-                in.setHeader("foo", "bar");
-            }
-        });
-        
-        assertTrue("The result exchange should have a camel exception", result.getException() instanceof CamelException);
-
-        assertMockEndpointsSatisfied();
-    }
-
-    protected RouteBuilder createRouteBuilder() {
-        return new RouteBuilder() {
-            public void configure() {
-                errorHandler(deadLetterChannel("mock:failed").maximumRedeliveries(0));
-                from("direct:seqential").split(body().tokenize(","), new UseLatestAggregationStrategy()).to("mock:result");
-                from("direct:parallel").split(body().tokenize(","), new MyAggregationStrategy()).parallelProcessing(true).to("mock:result");
-                from("direct:streaming").split(body().tokenize(",")).streaming().to("mock:result");
-                from("direct:parallel-streaming").split(body().tokenize(","), new MyAggregationStrategy()).parallelProcessing().streaming().to("mock:result");
-                from("direct:exception")
-                    .split(body().tokenize(","))
-                    .aggregationStrategy(new MyAggregationStrategy())
-                    .parallelProcessing(true).streaming()
-                    .process(new Processor() {
-                        public void process(Exchange exchange) throws Exception {
-                            String string = exchange.getIn().getBody(String.class);
-                            if ("Exception".equals(string)) {
-                                throw new CamelException("Just want to throw exception here");
-                            }
-                        
-                        }                    
-                    }).to("mock:result");
-            }
-        };
-    }
-}
+    // END SNIPPET: e2
+}
\ No newline at end of file

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

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

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterMethodCallTest.java
------------------------------------------------------------------------------
    svn:mergeinfo =

Copied: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSplitterMethodCallTest.java (from r734613, activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringChoiceTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSplitterMethodCallTest.java?p2=activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSplitterMethodCallTest.java&p1=activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringChoiceTest.java&r1=734613&r2=734805&rev=734805&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringChoiceTest.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSplitterMethodCallTest.java Thu Jan 15 12:25:51 2009
@@ -17,14 +17,14 @@
 package org.apache.camel.spring.processor;
 
 import org.apache.camel.CamelContext;
-import org.apache.camel.processor.ChoiceTest;
+import org.apache.camel.processor.SplitterMethodCallTest;
 import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
 
 /**
  * @version $Revision$
  */
-public class SpringChoiceTest extends ChoiceTest {
+public class SpringSplitterMethodCallTest extends SplitterMethodCallTest {
     protected CamelContext createCamelContext() throws Exception {
-        return createSpringCamelContext(this, "org/apache/camel/spring/processor/choice.xml");
+        return createSpringCamelContext(this, "org/apache/camel/spring/processor/splitterMethodCallTest.xml");
     }
 }
\ No newline at end of file

Propchange: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSplitterMethodCallTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSplitterMethodCallTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSplitterMethodCallTest.java
------------------------------------------------------------------------------
    svn:mergeinfo =

Modified: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/delayer.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/delayer.xml?rev=734805&r1=734804&r2=734805&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/delayer.xml (original)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/delayer.xml Thu Jan 15 12:25:51 2009
@@ -39,7 +39,7 @@
     <route>
       <from uri="seda:b"/>
       <delay>
-        <expression/>
+        <languageExpression/>
         <delayTime>3000</delayTime>
       </delay>
       <to uri="mock:result"/>

Copied: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/splitterMethodCallTest.xml (from r734613, activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/choice.xml)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/splitterMethodCallTest.xml?p2=activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/splitterMethodCallTest.xml&p1=activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/choice.xml&r1=734613&r2=734805&rev=734805&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/choice.xml (original)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/splitterMethodCallTest.xml Thu Jan 15 12:25:51 2009
@@ -22,25 +22,18 @@
        http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
     ">
 
-  <!-- START SNIPPET: example -->
-  <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
-    <route>
-      <from uri="direct:start"/>
-      <choice>
-        <when>
-          <xpath>$foo = 'bar'</xpath>
-          <to uri="mock:x"/>
-        </when>
-        <when>
-          <xpath>$foo = 'cheese'</xpath>
-          <to uri="mock:y"/>
-        </when>
-        <otherwise>
-          <to uri="mock:z"/>
-        </otherwise>
-      </choice>
-    </route>
-  </camelContext>
-  <!-- END SNIPPET: example -->
+    <!-- START SNIPPET: e1 -->
+    <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
+        <route>
+            <from uri="direct:start"/>
+            <split>
+                <method bean="splitWordsBean" method="splitWords"/>
+                <to uri="mock:result"/>
+            </split>
+        </route>
+    </camelContext>
+    <!-- END SNIPPET: e1 -->
+
+    <bean id="splitWordsBean" class="org.apache.camel.processor.SplitterMethodCallTest$SplitWordsBean"/>
 
 </beans>

Propchange: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/splitterMethodCallTest.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/splitterMethodCallTest.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/splitterMethodCallTest.xml
------------------------------------------------------------------------------
    svn:mergeinfo =

Propchange: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/splitterMethodCallTest.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml