activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r530738 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/builder/ main/java/org/apache/camel/impl/ test/java/org/apache/camel/ test/java/org/apache/camel/processor/
Date Fri, 20 Apr 2007 10:55:27 GMT
Author: jstrachan
Date: Fri Apr 20 03:55:26 2007
New Revision: 530738

URL: http://svn.apache.org/viewvc?view=rev&rev=530738
Log:
added a useful base class for testing; ContextTestSupport along with test cases for multicast,
pipeline, splitter

Added:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
  (with props)
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MulticastTest.java
  (with props)
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/PipelineTest.java
  (with props)
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterTest.java
  (with props)
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/SplitterBuilder.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceTest.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java?view=diff&rev=530738&r1=530737&r2=530738
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java
Fri Apr 20 03:55:26 2007
@@ -145,13 +145,13 @@
     }
 
     /**
-     * Adds the custom processor to this destination
+     * Adds the custom processor to this destination which could be a final destination,
or could be a transformation in a pipeline
      */
     @Fluent
-    public ConstantProcessorBuilder<E> process(@FluentArg("ref")Processor<E>
processor) {
+    public FromBuilder<E> process(@FluentArg("ref")Processor<E> processor) {
         ConstantProcessorBuilder<E> answer = new ConstantProcessorBuilder<E>(processor);
         addProcessBuilder(answer);
-        return answer;
+        return this;
     }
 
     /**
@@ -204,6 +204,20 @@
      */
     @Fluent
     public SplitterBuilder<E> splitter(@FluentArg(value = "recipients", element = true)ValueBuilder<E>
receipients) {
+        SplitterBuilder<E> answer = new SplitterBuilder<E>(this, receipients.getExpression());
+        addProcessBuilder(answer);
+        return answer;
+    }
+
+    /**
+     * A builder for the <a href="http://activemq.apache.org/camel/splitter.html">Splitter</a>
pattern
+     * where an expression is evaluated to iterate through each of the parts of a message
and then each part is then send to some endpoint.
+     *
+     * @param receipients the expression on which to split
+     * @return the builder
+     */
+    @Fluent
+    public SplitterBuilder<E> splitter(@FluentArg(value = "recipients", element = true)
Expression<E> receipients) {
         SplitterBuilder<E> answer = new SplitterBuilder<E>(this, receipients);
         addProcessBuilder(answer);
         return answer;

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/SplitterBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/SplitterBuilder.java?view=diff&rev=530738&r1=530737&r2=530738
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/SplitterBuilder.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/SplitterBuilder.java
Fri Apr 20 03:55:26 2007
@@ -29,17 +29,16 @@
  * @version $Revision$
  */
 public class SplitterBuilder<E extends Exchange> extends FromBuilder<E> {
-    private final ExpressionFactory<E> expressionFactory;
+    private final Expression<E> expression;
 
-    public SplitterBuilder(FromBuilder<E> parent, ExpressionFactory<E> expressionFactory)
{
+    public SplitterBuilder(FromBuilder<E> parent, Expression<E> expression) {
         super(parent);
-        this.expressionFactory = expressionFactory;
+        this.expression = expression;
     }
 
     public Processor<E> createProcessor() throws Exception {
         // lets create a single processor for all child predicates
         Processor<E> destination = super.createProcessor();
-        Expression<E> expression = expressionFactory.createExpression();
         return new Splitter<E>(destination, expression);
     }
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java?view=diff&rev=530738&r1=530737&r2=530738
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
Fri Apr 20 03:55:26 2007
@@ -36,8 +36,6 @@
     private String endpointUri;
     private final Component component;
     private CamelContext context;
-    protected AtomicBoolean activated = new AtomicBoolean(false);
-    protected AtomicBoolean deactivated = new AtomicBoolean(false);
 
     protected DefaultEndpoint(String endpointUri, Component component) {
         this.endpointUri = endpointUri;

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java?view=auto&rev=530738
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
Fri Apr 20 03:55:26 2007
@@ -0,0 +1,61 @@
+/**
+ *
+ * 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;
+
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.util.ProducerCache;
+import org.apache.camel.util.CamelClient;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * A useful base class which creates a {@link CamelContext} with some routes along with a
{@link CamelClient}
+ * for use in the test case
+ *
+ * @version $Revision: 1.1 $
+ */
+public abstract class ContextTestSupport extends TestSupport {
+    protected CamelContext context;
+    protected CamelClient<Exchange> client;
+
+    @Override
+    protected void setUp() throws Exception {
+        context = createCamelContext();
+        client = new CamelClient<Exchange>(context);
+
+        context.addRoutes(createRouteBuilder());
+
+        context.start();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        client.stop();
+        context.stop();
+    }
+
+    protected CamelContext createCamelContext() {
+        return new DefaultCamelContext();
+    }
+
+    protected abstract RouteBuilder createRouteBuilder();
+
+    protected Endpoint<Exchange> resolveMandatoryEndpoint(String uri) {
+        return resolveMandatoryEndpoint(context, uri);
+    }
+}

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

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceTest.java?view=diff&rev=530738&r1=530737&r2=530738
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceTest.java
Fri Apr 20 03:55:26 2007
@@ -24,6 +24,7 @@
 import org.apache.camel.Message;
 import org.apache.camel.Processor;
 import org.apache.camel.TestSupport;
+import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.component.queue.QueueEndpoint;
@@ -37,9 +38,7 @@
 /**
  * @version $Revision: 1.1 $
  */
-public class ChoiceTest extends TestSupport {
-    protected CamelContext context = new DefaultCamelContext();
-    protected ProducerCache<Exchange> client = new ProducerCache<Exchange>();
+public class ChoiceTest extends ContextTestSupport {
     protected Endpoint<Exchange> startEndpoint;
     protected MockEndpoint x, y, z;
 
@@ -83,15 +82,13 @@
 
     @Override
     protected void setUp() throws Exception {
-        context.addRoutes(createRouteBuilder());
+        super.setUp();
 
-        startEndpoint = resolveMandatoryEndpoint(context, "direct:a");
+        startEndpoint = resolveMandatoryEndpoint("direct:a");
 
         x = (MockEndpoint) resolveMandatoryEndpoint(context, "mock:x");
         y = (MockEndpoint) resolveMandatoryEndpoint(context, "mock:y");
         z = (MockEndpoint) resolveMandatoryEndpoint(context, "mock:z");
-
-        context.start();
     }
 
     protected RouteBuilder createRouteBuilder() {
@@ -105,9 +102,4 @@
         };
     }
 
-    @Override
-    protected void tearDown() throws Exception {
-        client.stop();
-        context.stop();
-    }
 }

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MulticastTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MulticastTest.java?view=auto&rev=530738
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MulticastTest.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MulticastTest.java
Fri Apr 20 03:55:26 2007
@@ -0,0 +1,83 @@
+/**
+ *
+ * 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.Exchange;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Processor;
+import org.apache.camel.Message;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import static org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class MulticastTest extends ContextTestSupport {
+    protected Endpoint<Exchange> startEndpoint;
+    protected MockEndpoint x, y, z;
+
+    public void testSendingAMessageUsingMulticastReceivesItsOwnExchange() throws Exception
{
+        x.expectedBodiesReceived("input+output");
+        y.expectedBodiesReceived("input+output");
+        z.expectedBodiesReceived("input+output");
+
+        client.send("direct:a", new Processor<Exchange>() {
+            public void process(Exchange exchange) {
+                Message in = exchange.getIn();
+                in.setBody("input");
+                in.setHeader("foo", "bar");
+            }
+        });
+
+        assertIsSatisfied(x, y, z);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        x = (MockEndpoint) resolveMandatoryEndpoint(context, "mock:x");
+        y = (MockEndpoint) resolveMandatoryEndpoint(context, "mock:y");
+        z = (MockEndpoint) resolveMandatoryEndpoint(context, "mock:z");
+    }
+
+    protected RouteBuilder createRouteBuilder() {
+        final Processor<Exchange> processor = new Processor<Exchange>() {
+            public void process(Exchange exchange) {
+                // lets transform the IN message
+                Message in = exchange.getIn();
+                String body = in.getBody(String.class);
+                in.setBody(body + "+output");
+            }
+        };
+
+        return new RouteBuilder<Exchange>() {
+            public void configure() {
+                from("direct:a").to("direct:x", "direct:y", "direct:z");
+
+                from("direct:x").process(processor).to("mock:x");
+                from("direct:y").process(processor).to("mock:y");
+                from("direct:z").process(processor).to("mock:z");
+            }
+        };
+
+    }
+
+}

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

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/PipelineTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/PipelineTest.java?view=auto&rev=530738
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/PipelineTest.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/PipelineTest.java
Fri Apr 20 03:55:26 2007
@@ -0,0 +1,81 @@
+/**
+ *
+ * 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.Exchange;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Processor;
+import org.apache.camel.Message;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class PipelineTest extends ContextTestSupport {
+    protected MockEndpoint resultEndpoint;
+
+    public void testSendMessageThroughAPipeline() throws Exception {
+        resultEndpoint.expectedBodiesReceived(4);
+
+        client.send("direct:a", new Processor<Exchange>() {
+            public void process(Exchange exchange) {
+                // now lets fire in a message
+                Message in = exchange.getIn();
+                in.setBody(1);
+                in.setHeader("foo", "bar");
+            }
+        });
+
+        resultEndpoint.assertIsSatisfied();
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        resultEndpoint = (MockEndpoint) resolveMandatoryEndpoint(context, "mock:result");
+    }
+
+    protected RouteBuilder createRouteBuilder() {
+        final Processor<Exchange> processor = new Processor<Exchange>() {
+            public void process(Exchange exchange) {
+                Integer number = exchange.getIn().getBody(Integer.class);
+                if (number == null) {
+                    number = 0;
+                }
+                // todo set the endpoint name we were received from
+                //exchange.setProperty(exchange.get);
+                number = number + 1;
+                exchange.getOut().setBody(number);
+            }
+        };
+
+        return new RouteBuilder<Exchange>() {
+            public void configure() {
+                from("direct:a").pipeline("direct:x", "direct:y", "direct:z", "mock:result");
+
+                from("direct:x").process(processor);
+                from("direct:y").process(processor);
+                from("direct:z").process(processor);
+            }
+        };
+    }
+
+}

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

Added: 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/SplitterTest.java?view=auto&rev=530738
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterTest.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterTest.java
Fri Apr 20 03:55:26 2007
@@ -0,0 +1,63 @@
+/**
+ *
+ * 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.Endpoint;
+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;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class SplitterTest extends ContextTestSupport {
+    protected Endpoint<Exchange> startEndpoint;
+    protected MockEndpoint resultEndpoint;
+
+    public void testSendingAMessageUsingMulticastReceivesItsOwnExchange() throws Exception
{
+        resultEndpoint.expectedBodiesReceived("James", "Guillaume", "Hiram", "Rob");
+
+        client.send("direct:a", new Processor<Exchange>() {
+            public void process(Exchange exchange) {
+                Message in = exchange.getIn();
+                in.setBody("James,Guillaume,Hiram,Rob");
+                in.setHeader("foo", "bar");
+            }
+        });
+
+        resultEndpoint.assertIsSatisfied();
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        resultEndpoint = (MockEndpoint) resolveMandatoryEndpoint(context, "mock:result");
+    }
+
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder<Exchange>() {
+            public void configure() {
+                from("direct:a").splitter(body().tokenize(",")).to("mock:result");
+            }
+        };
+    }
+}

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



Mime
View raw message