You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/09/19 08:36:46 UTC

svn commit: r998598 - in /camel/trunk/components/camel-jms/src/test: java/org/apache/camel/component/jms/ resources/org/apache/camel/component/jms/

Author: davsclaus
Date: Sun Sep 19 06:36:46 2010
New Revision: 998598

URL: http://svn.apache.org/viewvc?rev=998598&view=rev
Log:
Added test based on user forum issue

Added:
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsXPathHeaderTest.java
      - copied, changed from r998593, camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDeadLetterQueueTest.java
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/SpringJmsXPathHeaderTest.java
    camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/SpringJmsXPathHeaderTest.xml
      - copied, changed from r998593, camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/jmsRouteUsingSpring.xml

Copied: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsXPathHeaderTest.java (from r998593, camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDeadLetterQueueTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsXPathHeaderTest.java?p2=camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsXPathHeaderTest.java&p1=camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDeadLetterQueueTest.java&r1=998593&r2=998598&rev=998598&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDeadLetterQueueTest.java (original)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsXPathHeaderTest.java Sun Sep 19 06:36:46 2010
@@ -20,46 +20,47 @@ import javax.jms.ConnectionFactory;
 
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.camel.CamelContext;
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
+
 import static org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge;
 
 /**
- * Unit test for using JMS as DLQ
+ * JMS with XPath
  *
  * @version $Revision$
  */
-public class JmsDeadLetterQueueTest extends CamelTestSupport {
+public class JmsXPathHeaderTest extends CamelTestSupport {
+
+    @Test
+    public void testTrue() throws Exception {
+        getMockEndpoint("mock:true").expectedMessageCount(1);
+        getMockEndpoint("mock:other").expectedMessageCount(0);
+
+        template.sendBodyAndHeader("activemq:queue:in", "<hello>World</hello>", "foo", "true");
 
-    protected String getUri() {
-        return "activemq:queue:dead";
+        assertMockEndpointsSatisfied();
     }
 
     @Test
-    public void testOk() throws Exception {
-        MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedBodiesReceived("Hello World");
+    public void testFalse() throws Exception {
+        getMockEndpoint("mock:true").expectedMessageCount(0);
+        getMockEndpoint("mock:other").expectedMessageCount(1);
 
-        template.sendBody("direct:start", "Hello World");
+        template.sendBodyAndHeader("activemq:queue:in", "<hello>World</hello>", "foo", "false");
 
         assertMockEndpointsSatisfied();
     }
 
     @Test
-    public void testKabom() throws Exception {
-        MockEndpoint mock = getMockEndpoint("mock:dead");
-        mock.expectedBodiesReceived("Kabom");
+    public void testNoHeader() throws Exception {
+        getMockEndpoint("mock:true").expectedMessageCount(0);
+        getMockEndpoint("mock:other").expectedMessageCount(1);
 
-        template.sendBody("direct:start", "Kabom");
+        template.sendBody("activemq:queue:in", "<hello>World</hello>");
 
         assertMockEndpointsSatisfied();
-
-        // the cause exception is gone in the transformation below
-        assertNull(mock.getReceivedExchanges().get(0).getProperty(Exchange.EXCEPTION_CAUGHT));
     }
 
     protected CamelContext createCamelContext() throws Exception {
@@ -76,20 +77,16 @@ public class JmsDeadLetterQueueTest exte
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                errorHandler(deadLetterChannel("seda:dead").disableRedelivery());
-
-                from("direct:start").process(new Processor() {
-                    public void process(Exchange exchange) throws Exception {
-                        String body = exchange.getIn().getBody(String.class);
-                        if ("Kabom".equals(body)) {
-                            throw new IllegalArgumentException("Kabom");
-                        }
-                    }
-                }).to("mock:result");
-
-                from("seda:dead").transform(exceptionMessage()).to(getUri());
+                from("activemq:queue:in")
+                    .choice()
+                        .when().xpath("$foo = 'true'")
+                            .to("activemq:queue:true")
+                        .otherwise()
+                            .to("activemq:queue:other")
+                        .end();
 
-                from(getUri()).to("mock:dead");
+                from("activemq:queue:true").to("mock:true");
+                from("activemq:queue:other").to("mock:other");
             }
         };
     }

Added: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/SpringJmsXPathHeaderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/SpringJmsXPathHeaderTest.java?rev=998598&view=auto
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/SpringJmsXPathHeaderTest.java (added)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/SpringJmsXPathHeaderTest.java Sun Sep 19 06:36:46 2010
@@ -0,0 +1,66 @@
+/**
+ * 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.component.jms;
+
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * JMS with XPath
+ *
+ * @version $Revision: 827439 $
+ */
+public class SpringJmsXPathHeaderTest extends CamelSpringTestSupport {
+
+    @Test
+    public void testTrue() throws Exception {
+        getMockEndpoint("mock:true").expectedMessageCount(1);
+        getMockEndpoint("mock:other").expectedMessageCount(0);
+
+        template.sendBodyAndHeader("activemq:queue:in", "<hello>World</hello>", "foo", "true");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testFalse() throws Exception {
+        getMockEndpoint("mock:true").expectedMessageCount(0);
+        getMockEndpoint("mock:other").expectedMessageCount(1);
+
+        template.sendBodyAndHeader("activemq:queue:in", "<hello>World</hello>", "foo", "false");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testNoHeader() throws Exception {
+        getMockEndpoint("mock:true").expectedMessageCount(0);
+        getMockEndpoint("mock:other").expectedMessageCount(1);
+
+        template.sendBody("activemq:queue:in", "<hello>World</hello>");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/component/jms/SpringJmsXPathHeaderTest.xml");
+    }
+
+}
\ No newline at end of file

Copied: camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/SpringJmsXPathHeaderTest.xml (from r998593, camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/jmsRouteUsingSpring.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/SpringJmsXPathHeaderTest.xml?p2=camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/SpringJmsXPathHeaderTest.xml&p1=camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/jmsRouteUsingSpring.xml&r1=998593&r2=998598&rev=998598&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/jmsRouteUsingSpring.xml (original)
+++ camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/SpringJmsXPathHeaderTest.xml Sun Sep 19 06:36:46 2010
@@ -22,17 +22,39 @@
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
 
-  <!-- START SNIPPET: example -->
-  <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
-  </camelContext>
-
-  <bean id="activemq" class="org.apache.camel.component.jms.JmsComponent">
-    <property name="connectionFactory">
-      <bean class="org.apache.activemq.ActiveMQConnectionFactory">
-        <property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
-      </bean>
-    </property>
-  </bean>
-  <!-- END SNIPPET: example -->
+    <bean id="activemq" class="org.apache.camel.component.jms.JmsComponent">
+        <property name="connectionFactory">
+            <bean class="org.apache.activemq.ActiveMQConnectionFactory">
+                <property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
+            </bean>
+        </property>
+    </bean>
+
+    <camelContext xmlns="http://camel.apache.org/schema/spring">
+
+        <route>
+            <from uri="activemq:queue:in"/>
+            <choice>
+                <when>
+                    <xpath>$foo = 'true'</xpath>
+                    <to uri="activemq:queue:true"/>
+                </when>
+                <otherwise>
+                    <to uri="activemq:queue:other"/>
+                </otherwise>
+            </choice>
+        </route>
+
+        <route>
+            <from uri="activemq:queue:true"/>
+            <to uri="mock:true"/>
+        </route>
+
+        <route>
+            <from uri="activemq:queue:other"/>
+            <to uri="mock:other"/>
+        </route>
+
+    </camelContext>
 
 </beans>