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 2009/10/26 13:36:13 UTC

svn commit: r829770 - in /camel/trunk/components/camel-jms/src/test: java/org/apache/camel/component/jms/tx/RouteIdTransactedTest.java resources/org/apache/camel/component/jms/tx/RouteIdTransactedTest.xml

Author: davsclaus
Date: Mon Oct 26 12:36:12 2009
New Revision: 829770

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

Added:
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/RouteIdTransactedTest.java   (with props)
    camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/RouteIdTransactedTest.xml
      - copied, changed from r829743, camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/TransactionMinimalConfigurationTest.xml

Added: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/RouteIdTransactedTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/RouteIdTransactedTest.java?rev=829770&view=auto
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/RouteIdTransactedTest.java (added)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/RouteIdTransactedTest.java Mon Oct 26 12:36:12 2009
@@ -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.component.jms.tx;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision$
+ */
+public class RouteIdTransactedTest extends CamelSpringTestSupport {
+
+    protected ClassPathXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext(
+            "/org/apache/camel/component/jms/tx/RouteIdTransactedTest.xml");
+    }
+
+    protected int getExpectedRouteCount() {
+        return 0;
+    }
+
+    @Test
+    public void testRouteId() throws Exception {
+        getMockEndpoint("mock:error").expectedMessageCount(0);
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        template.sendBody("activemq:queue:foo", "Hello World");
+
+        assertMockEndpointsSatisfied();
+
+        String id = context.getRouteDefinitions().get(0).getId();
+        assertEquals("myCoolRoute", id);
+    }
+
+    @Test
+    public void testRouteIdFailed() throws Exception {
+        getMockEndpoint("mock:error").expectedMessageCount(1);
+        getMockEndpoint("mock:result").expectedMessageCount(0);
+
+        template.sendBody("activemq:queue:foo", "Kabom");
+
+        assertMockEndpointsSatisfied();
+
+        String id = context.getRouteDefinitions().get(0).getId();
+        assertEquals("myCoolRoute", id);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("activemq:queue:foo?transacted=true").id("myCoolRoute")
+                    .onException(IllegalArgumentException.class).handled(true).to("log:bar").to("mock:error").end()
+                    .transacted()
+                    .choice()
+                        .when(body().contains("Kabom")).throwException(new IllegalArgumentException("Damn"))
+                    .otherwise()
+                        .to("mock:result")
+                    .end();
+
+            }
+        };
+    }
+}

Propchange: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/RouteIdTransactedTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/RouteIdTransactedTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/RouteIdTransactedTest.xml (from r829743, camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/TransactionMinimalConfigurationTest.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/RouteIdTransactedTest.xml?p2=camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/RouteIdTransactedTest.xml&p1=camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/TransactionMinimalConfigurationTest.xml&r1=829743&r2=829770&rev=829770&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/TransactionMinimalConfigurationTest.xml (original)
+++ camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/RouteIdTransactedTest.xml Mon Oct 26 12:36:12 2009
@@ -22,45 +22,18 @@
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
          http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
 
-    <!-- START SNIPPET: e1 -->
-    <!-- setup JMS connection factory -->
     <bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
         <property name="brokerURL" value="vm://localhost?broker.persistent=false&amp;broker.useJmx=false"/>
     </bean>
 
-    <!-- setup spring jms TX manager -->
     <bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
         <property name="connectionFactory" ref="jmsConnectionFactory"/>
     </bean>
 
-    <!-- define our activemq component -->
     <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
         <property name="connectionFactory" ref="jmsConnectionFactory"/>
-        <!-- define the jms consumer/producer as transacted -->
         <property name="transacted" value="true"/>
-        <!-- setup the transaction manager to use -->
-        <!-- if not provided then Camel will automatic use a JmsTransactionManager, however if you
-             for instance use a JTA transaction manager then you must configure it -->
         <property name="transactionManager" ref="jmsTransactionManager"/>
     </bean>
-    <!-- END SNIPPET: e1 -->
-
-    <!-- START SNIPPET: e2 -->
-    <camelContext xmlns="http://camel.apache.org/schema/spring">
-        <route>
-            <!-- 1: from the jms queue -->
-            <from uri="activemq:queue:okay"/>
-            <!-- 2: mark this route as transacted -->
-            <transacted/>
-            <!-- 3: call our business logic that is myProcessor -->
-            <process ref="myProcessor"/>
-            <!-- 4: if success then send it to the mock -->
-            <to uri="mock:result"/>
-        </route>
-    </camelContext>
-
-    <bean id="myProcessor" class="org.apache.camel.component.jms.tx.JMSTransactionalClientTest$MyProcessor"/>
-    <!-- END SNIPPET: e2 -->
-
 
 </beans>