camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1051428 - in /camel/trunk/tests/camel-itest/src/test: java/org/apache/camel/itest/jms/JmsPollingConsumerTest.java resources/org/apache/camel/itest/jms/JmsPollingConsumerTest-context.xml
Date Tue, 21 Dec 2010 09:30:11 GMT
Author: davsclaus
Date: Tue Dec 21 09:30:10 2010
New Revision: 1051428

URL: http://svn.apache.org/viewvc?rev=1051428&view=rev
Log:
CAMEL-2305: Added unit test.

Added:
    camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsPollingConsumerTest.java
    camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/JmsPollingConsumerTest-context.xml

Added: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsPollingConsumerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsPollingConsumerTest.java?rev=1051428&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsPollingConsumerTest.java
(added)
+++ camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsPollingConsumerTest.java
Tue Dec 21 09:30:10 2010
@@ -0,0 +1,106 @@
+/**
+ * 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.itest.jms;
+
+import org.apache.camel.ConsumerTemplate;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.Handler;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+/**
+ * @version $Revision$
+ */
+@ContextConfiguration
+public class JmsPollingConsumerTest extends AbstractJUnit4SpringContextTests {
+
+    @Produce(uri = "activemq:startConsumer")
+    protected ProducerTemplate startConsumer;
+
+    @Produce(uri = "direct:startConsumer")
+    protected ProducerTemplate startDirectConsumer;
+
+    @Produce(uri = "activemq:queue")
+    protected ProducerTemplate queue;
+
+    @EndpointInject(uri = "mock:result")
+    protected MockEndpoint result;
+
+    /**
+     * Fails:
+     * Consumer is expected to read two messages from activemq:queue and concatenate their
bodies.
+     * In this test, consumer bean is invoked from an activemq: route.
+     */
+    @Test
+    @DirtiesContext
+    @Ignore("CAMEL-2305")
+    public void testConsumerFromJMSRoute() throws Exception {
+        result.expectedBodiesReceived("foobar");
+
+        queue.sendBody("foo");
+        queue.sendBody("bar");
+
+        startConsumer.sendBody("go");
+
+        result.assertIsSatisfied();
+    }
+
+    /**
+     * Succeeds:
+     * Consumer is expected to read two messages from activemq:queue and concatenate their
bodies.
+     * In this test, consumer bean is invoked from a direct: route.
+     */
+    @Test
+    @DirtiesContext
+    public void testConsumerFromDirectRoute() throws Exception {
+        result.expectedBodiesReceived("foobar");
+
+        queue.sendBody("foo");
+        queue.sendBody("bar");
+
+        startDirectConsumer.sendBody("go");
+
+        result.assertIsSatisfied();
+    }
+
+    public static class Consumer {
+
+        @Autowired
+        protected ConsumerTemplate consumer;
+
+        @Handler
+        public String consume() {
+            StringBuilder result = new StringBuilder();
+
+            Exchange exchange;
+            while ((exchange = consumer.receive("activemq:queue", 2000)) != null) {
+                result.append(exchange.getIn().getBody(String.class));
+            }
+
+            return result.toString();
+
+        }
+    }
+}

Added: camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/JmsPollingConsumerTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/JmsPollingConsumerTest-context.xml?rev=1051428&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/JmsPollingConsumerTest-context.xml
(added)
+++ camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/JmsPollingConsumerTest-context.xml
Tue Dec 21 09:30:10 2010
@@ -0,0 +1,86 @@
+<?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"
+       xmlns:broker="http://activemq.apache.org/schema/core"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+       http://activemq.apache.org/schema/core http://activemq.org/config/1.0/1.0.xsd">
+
+    <!-- activemq broker -->
+    <broker:broker id="broker" useJmx="false" persistent="false" brokerName="localhost">
+        <broker:transportConnectors>
+            <broker:transportConnector name="tcp" uri="vm://localhost?broker.persistent=false"/>
+        </broker:transportConnectors>
+    </broker:broker>
+
+    <!-- camel stuff below to send and listen to broker with a spring JMS transaction
manager -->
+    <bean id="jmsFactory" class="org.apache.activemq.ActiveMQConnectionFactory" depends-on="broker">
+        <property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
+    </bean>
+
+    <bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
+        <property name="connectionFactory" ref="jmsFactory"/>
+    </bean>
+
+    <bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
+        <property name="connectionFactory" ref="jmsFactory"/>
+        <property name="transactionManager" ref="jmsTransactionManager"/>
+        <property name="transacted" value="true"/>
+        <property name="concurrentConsumers" value="1"/>
+    </bean>
+
+    <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
+        <property name="configuration" ref="jmsConfig"/>
+    </bean>
+
+    <!-- If we don't use transaction support defined in jmsConfig, test will succeed
+   <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
+       <property name="connectionFactory" ref="jmsFactory"/>
+   </bean>
+    -->
+
+    <bean id="consumer" class="org.apache.camel.itest.jms.JmsPollingConsumerTest$Consumer"/>
+
+    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+
+        <template id="camelTemplate"/>
+        <consumerTemplate id="consumerTemplate"/>
+
+        <route>
+            <from uri="activemq:startConsumer"/>
+            <delay>
+                <constant>1000</constant>
+            </delay>
+            <to uri="bean:consumer"/>
+            <to uri="mock:result"/>
+        </route>
+
+        <route>
+            <from uri="direct:startConsumer"/>
+            <delay>
+                <constant>1000</constant>
+            </delay>
+            <to uri="bean:consumer"/>
+            <to uri="mock:result"/>
+        </route>
+
+    </camelContext>
+
+</beans>
\ No newline at end of file



Mime
View raw message