activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r535136 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/builder/ camel-core/src/test/java/org/apache/camel/ camel-spring/src/test/java/org/apache/camel/spring/ camel-spring/sr...
Date Fri, 04 May 2007 09:18:27 GMT
Author: jstrachan
Date: Fri May  4 02:18:26 2007
New Revision: 535136

URL: http://svn.apache.org/viewvc?view=rev&rev=535136
Log:
added test case for bug found by Jeff Lansing

Added:
    activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/ContentBasedRouteTest.java
  (with props)
    activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/contentBasedRoute.xml
  (with props)
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelClient.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/WhenBuilder.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java
    activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/EndpointReferenceTest.java
    activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/SpringTestSupport.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelClient.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelClient.java?view=diff&rev=535136&r1=535135&r2=535136
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelClient.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelClient.java Fri May
 4 02:18:26 2007
@@ -17,18 +17,12 @@
  */
 package org.apache.camel;
 
-import org.apache.camel.Exchange;
-import org.apache.camel.CamelContext;
-import org.apache.camel.Endpoint;
-import org.apache.camel.NoSuchEndpointException;
-import org.apache.camel.Processor;
-import org.apache.camel.Producer;
-import org.apache.camel.util.ProducerCache;
 import org.apache.camel.impl.ServiceSupport;
+import org.apache.camel.util.ProducerCache;
 
 /**
  * A Client object for working with Camel and invoking {@link Endpoint} instances with {@link
Exchange} instances
- * 
+ *
  * @version $Revision$
  */
 public class CamelClient<E extends Exchange> extends ServiceSupport {
@@ -39,12 +33,11 @@
         this.context = context;
     }
 
-
     /**
      * Sends the exchange to the given endpoint
      *
      * @param endpointUri the endpoint URI to send the exchange to
-     * @param exchange the exchange to send
+     * @param exchange    the exchange to send
      */
     public E send(String endpointUri, E exchange) {
         Endpoint endpoint = resolveMandatoryEndpoint(endpointUri);
@@ -56,11 +49,11 @@
      * Sends an exchange to an endpoint using a supplied @{link Processor} to populate the
exchange
      *
      * @param endpointUri the endpoint URI to send the exchange to
-     * @param processor the transformer used to populate the new exchange
+     * @param processor   the transformer used to populate the new exchange
      */
     public E send(String endpointUri, Processor processor) {
         Endpoint endpoint = resolveMandatoryEndpoint(endpointUri);
-        return send(endpoint,  processor);
+        return send(endpoint, processor);
     }
 
     /**
@@ -78,27 +71,48 @@
     /**
      * Sends an exchange to an endpoint using a supplied @{link Processor} to populate the
exchange
      *
-     * @param endpoint the endpoint to send the exchange to
+     * @param endpoint  the endpoint to send the exchange to
      * @param processor the transformer used to populate the new exchange
      */
     public E send(Endpoint<E> endpoint, Processor processor) {
         return producerCache.send(endpoint, processor);
     }
-   
+
     /**
      * Send the body to an endpoint
+     *
      * @param endpointUri
-     * @param body = the payload 
+     * @param body        = the payload
      * @return the result
      */
-    public Object sendBody (String endpointUri,final Object body) {
-        E result =  send(endpointUri, new Processor() {
+    public Object sendBody(String endpointUri, final Object body) {
+        E result = send(endpointUri, new Processor() {
             public void process(Exchange exchange) {
                 Message in = exchange.getIn();
                 in.setBody(body);
             }
         });
-        return result != null ? result.getOut().getBody() : null;
+        return extractResultBody(result);
+    }
+
+    /**
+     * Sends the body to an endpoint with a specified header and header value
+     *
+     * @param endpointUri the endpoint URI to send to
+     * @param body        the payload send
+     * @param header      the header name
+     * @param headerValue the header value
+     * @return the result
+     */
+    public Object sendBody(String endpointUri, final Object body, final String header, final
Object headerValue) {
+        E result = send(endpointUri, new Processor() {
+            public void process(Exchange exchange) {
+                Message in = exchange.getIn();
+                in.setHeader(header, headerValue);
+                in.setBody(body);
+            }
+        });
+        return extractResultBody(result);
     }
 
     public Producer<E> getProducer(Endpoint<E> endpoint) {
@@ -123,5 +137,9 @@
 
     protected void doStop() throws Exception {
         producerCache.stop();
+    }
+
+    protected Object extractResultBody(E result) {
+        return result != null ? result.getOut().getBody() : null;
     }
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java?view=diff&rev=535136&r1=535135&r2=535136
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java
Fri May  4 02:18:26 2007
@@ -193,7 +193,7 @@
     }
 
     @Fluent
-    public DeadLetterChannelBuilder deadLetterChannel(@FluentArg("endpoint")Endpoint deadLetterEndpoint)
{
+    public DeadLetterChannelBuilder deadLetterChannel(@FluentArg("ref")Endpoint deadLetterEndpoint)
{
         return new DeadLetterChannelBuilder(new SendProcessor(deadLetterEndpoint));
     }
 

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/WhenBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/WhenBuilder.java?view=diff&rev=535136&r1=535135&r2=535136
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/WhenBuilder.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/WhenBuilder.java
Fri May  4 02:18:26 2007
@@ -33,7 +33,7 @@
 
     @Override
     @Fluent
-    public ChoiceBuilder to(@FluentArg("endpoint") Endpoint endpoint) {
+    public ChoiceBuilder to(@FluentArg("ref") Endpoint endpoint) {
         super.to(endpoint);
         return parent;
     }

Modified: 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=diff&rev=535136&r1=535135&r2=535136
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
Fri May  4 02:18:26 2007
@@ -86,11 +86,6 @@
      * Creates an exchange with the given body
      */
     protected Exchange createExchangeWithBody(Object body) {
-        Exchange exchange = new DefaultExchange(context);
-        Message message = exchange.getIn();
-        message.setHeader("testName", getName());
-        message.setHeader("testClass", getClass().getName());
-        message.setBody(body);
-        return exchange;
+        return createExchangeWithBody(context, body);
     }
 }

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java?view=diff&rev=535136&r1=535135&r2=535136
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java Fri May
 4 02:18:26 2007
@@ -20,6 +20,7 @@
 import junit.framework.TestCase;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.camel.impl.DefaultExchange;
 
 /**
  * A bunch of useful testing methods
@@ -117,5 +118,17 @@
         assertNotNull("No endpoint found for URI: " + uri, endpoint);
 
         return endpoint;
+    }
+
+    /**
+     * Creates an exchange with the given body
+     */
+    protected Exchange createExchangeWithBody(CamelContext camelContext, Object body) {
+        Exchange exchange = new DefaultExchange(camelContext);
+        Message message = exchange.getIn();
+        message.setHeader("testName", getName());
+        message.setHeader("testClass", getClass().getName());
+        message.setBody(body);
+        return exchange;
     }
 }

Added: activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/ContentBasedRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/ContentBasedRouteTest.java?view=auto&rev=535136
==============================================================================
--- activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/ContentBasedRouteTest.java
(added)
+++ activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/ContentBasedRouteTest.java
Fri May  4 02:18:26 2007
@@ -0,0 +1,62 @@
+/**
+ *
+ * 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;
+
+import static org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class ContentBasedRouteTest extends SpringTestSupport {
+    protected MockEndpoint matchedEndpoint;
+    protected MockEndpoint notMatchedEndpoint;
+    protected Object body = "<hello>world!</hello>";
+    protected String header = "destination";
+
+    public void testMatchesPredicate() throws Exception {
+        matchedEndpoint.expectedMessageCount(1);
+        notMatchedEndpoint.expectedMessageCount(0);
+
+        client.sendBody("direct:start", body, header, "firstChoice");
+
+        assertIsSatisfied(matchedEndpoint, notMatchedEndpoint);
+    }
+
+    public void testDoesNotMatchPredicate() throws Exception {
+        matchedEndpoint.expectedMessageCount(0);
+        notMatchedEndpoint.expectedMessageCount(1);
+
+        client.sendBody("direct:start", body, header, "notMatchedValue");
+
+        assertIsSatisfied(matchedEndpoint, notMatchedEndpoint);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        matchedEndpoint = (MockEndpoint) resolveMandatoryEndpoint(camelContext, "mock:matched");
+        notMatchedEndpoint = (MockEndpoint) resolveMandatoryEndpoint(camelContext, "mock:notMatched");
+    }
+
+    protected ClassPathXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/spring/contentBasedRoute.xml");
+    }
+}

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

Modified: activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/EndpointReferenceTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/EndpointReferenceTest.java?view=diff&rev=535136&r1=535135&r2=535136
==============================================================================
--- activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/EndpointReferenceTest.java
(original)
+++ activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/EndpointReferenceTest.java
Fri May  4 02:18:26 2007
@@ -45,19 +45,21 @@
 
         log.debug("Found dummy bean: " + dummyBean);
 
-        SpringCamelContext context = (SpringCamelContext) applicationContext.getBean("camel");
-        assertValidContext(context);
 
-        MockEndpoint resultEndpoint = (MockEndpoint) resolveMandatoryEndpoint(context, "mock:end");
+        MockEndpoint resultEndpoint = (MockEndpoint) resolveMandatoryEndpoint(camelContext,
"mock:end");
         resultEndpoint.expectedBodiesReceived(body);
 
         // now lets send a message
-        CamelClient<Exchange> client = new CamelClient<Exchange>(context);
+        CamelClient<Exchange> client = new CamelClient<Exchange>(camelContext);
         client.sendBody("direct:start", body);
 
         resultEndpoint.assertIsSatisfied();
     }
 
+    protected SpringCamelContext createCamelContext() {
+        return (SpringCamelContext) applicationContext.getBean("camel");
+    }
+
     public void testEndpointConfigurationAfterEnsuringThatTheStatementRouteBuilderWasCreated()
throws Exception {
         String[] names = applicationContext.getBeanDefinitionNames();
         for (String name : names) {
@@ -71,10 +73,9 @@
     }
 
     protected void assertValidContext(SpringCamelContext context) {
-        assertNotNull("No context found!", context);
+        super.assertValidContext(context);
 
         List<Route> routes = context.getRoutes();
-        assertNotNull("Should have some routes defined", routes);
         assertEquals("Number of routes defined", 1, routes.size());
     }
 

Modified: activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/SpringTestSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/SpringTestSupport.java?view=diff&rev=535136&r1=535135&r2=535136
==============================================================================
--- activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/SpringTestSupport.java
(original)
+++ activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/SpringTestSupport.java
Fri May  4 02:18:26 2007
@@ -18,15 +18,23 @@
 package org.apache.camel.spring;
 
 import org.apache.camel.TestSupport;
+import org.apache.camel.Route;
+import org.apache.camel.Exchange;
+import org.apache.camel.CamelClient;
+import org.apache.camel.Endpoint;
 import org.apache.camel.util.ObjectHelper;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 
+import java.util.List;
+
 /**
  * @version $Revision: 1.1 $
  */
 public abstract class SpringTestSupport extends TestSupport {
     protected AbstractXmlApplicationContext applicationContext;
+    protected SpringCamelContext camelContext;
+    protected CamelClient<Exchange> client;
 
     protected abstract ClassPathXmlApplicationContext createApplicationContext();
 
@@ -36,6 +44,11 @@
 
         applicationContext = createApplicationContext();
         assertNotNull("Should have created a valid spring context", applicationContext);
+
+        camelContext = createCamelContext();
+        assertValidContext(camelContext);
+
+        client = new CamelClient<Exchange>(camelContext);
     }
 
     @Override
@@ -60,4 +73,22 @@
             return null;
         }
     }
+
+    protected Endpoint resolveMandatoryEndpoint(String uri) {
+        return resolveMandatoryEndpoint(camelContext, uri);
+    }
+
+    protected void assertValidContext(SpringCamelContext context) {
+        assertNotNull("No context found!", context);
+
+        List<Route> routes = context.getRoutes();
+        assertNotNull("Should have some routes defined", routes);
+        assertTrue("Should have at least one route", routes.size() > 0);
+        log.debug("Camel Routes: " + routes);
+    }
+
+    protected SpringCamelContext createCamelContext() throws Exception {
+        return SpringCamelContext.springCamelContext(applicationContext);
+    }
+
 }

Added: activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/contentBasedRoute.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/contentBasedRoute.xml?view=auto&rev=535136
==============================================================================
--- activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/contentBasedRoute.xml
(added)
+++ activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/contentBasedRoute.xml
Fri May  4 02:18:26 2007
@@ -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-2.0.xsd
+       http://activemq.apache.org/camel/schema/camel-1.0.xsd http://activemq.apache.org/camel/schema/camel-1.0.xsd
+    ">
+
+  <!-- START SNIPPET: example -->
+  <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/camel-1.0.xsd">
+    <endpoint id="endpoint1" uri="direct:start"/>
+    <endpoint id="endpoint2" uri="mock:matched"/>
+    <endpoint id="endpoint3" uri="mock:notMatched"/>
+    <route>
+      <from ref="endpoint1"/>
+      <choice>
+        <when>
+          <predicate>
+            <header name="destination"/>
+            <isEqualTo value="firstChoice"/>
+          </predicate>
+          <to ref="endpoint2"/>
+        </when>
+        <otherwise>
+          <to ref="endpoint3"/>
+        </otherwise>
+      </choice>
+    </route>
+  </camelContext>
+  <!-- END SNIPPET: example -->
+
+</beans>

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



Mime
View raw message