camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r762400 - in /camel/branches/camel-1.x/components/camel-spring/src/test: java/org/apache/camel/spring/interceptor/ resources/org/apache/camel/spring/interceptor/
Date Mon, 06 Apr 2009 15:51:09 GMT
Author: davsclaus
Date: Mon Apr  6 15:51:08 2009
New Revision: 762400

URL: http://svn.apache.org/viewvc?rev=762400&view=rev
Log:
Transacted routes with Spring DSL seems to not work with JDBC resources. Added a unit test
to demonstrate this.

Added:
    camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/SpringTransactionalClientDataSourceTest.java
      - copied, changed from r762047, camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTest.java
    camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/springTransactionalClientDataSource.xml
      - copied, changed from r762047, camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/transactionalClientDataSource.xml
Modified:
    camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTest.java

Copied: camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/SpringTransactionalClientDataSourceTest.java
(from r762047, camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTest.java)
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/SpringTransactionalClientDataSourceTest.java?p2=camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/SpringTransactionalClientDataSourceTest.java&p1=camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTest.java&r1=762047&r2=762400&rev=762400&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTest.java
(original)
+++ camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/SpringTransactionalClientDataSourceTest.java
Mon Apr  6 15:51:08 2009
@@ -19,10 +19,7 @@
 import javax.sql.DataSource;
 
 import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.spring.SpringRouteBuilder;
 import org.apache.camel.spring.SpringTestSupport;
-import org.apache.camel.spring.spi.SpringTransactionPolicy;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 import org.springframework.jdbc.core.JdbcTemplate;
@@ -30,51 +27,39 @@
 /**
  * Unit test to demonstrate the transactional client pattern.
  */
-public class TransactionalClientDataSourceTest extends SpringTestSupport {
+public class SpringTransactionalClientDataSourceTest extends SpringTestSupport {
 
     protected JdbcTemplate jdbc;
-    protected boolean useTransactionErrorHandler = true;
 
     protected AbstractXmlApplicationContext createApplicationContext() {
         return new ClassPathXmlApplicationContext(
-            "/org/apache/camel/spring/interceptor/transactionalClientDataSource.xml");
-    }
-
-    protected int getExpectedRouteCount() {
-        return 0;
+            "/org/apache/camel/spring/interceptor/springTransactionalClientDataSource.xml");
     }
 
     @Override
     protected void setUp() throws Exception {
-        this.disableJMX();
         super.setUp();
 
-        // START SNIPPET: e5
         // create database and insert dummy data
         final DataSource ds = getMandatoryBean(DataSource.class, "dataSource");
         jdbc = new JdbcTemplate(ds);
         jdbc.execute("create table books (title varchar(50))");
         jdbc.update("insert into books (title) values (?)", new Object[] {"Camel in Action"});
-        // END SNIPPET: e5
     }
 
     @Override
     protected void tearDown() throws Exception {
         super.tearDown();
         jdbc.execute("drop table books");
-        this.enableJMX();
     }
 
-    // START SNIPPET: e3
     public void testTransactionSuccess() throws Exception {
         template.sendBody("direct:okay", "Hello World");
 
         int count = jdbc.queryForInt("select count(*) from books");
         assertEquals("Number of books", 3, count);
     }
-    // END SNIPPET: e3
 
-    // START SNIPPET: e4
     public void testTransactionRollback() throws Exception {
         try {
             template.sendBody("direct:fail", "Hello World");
@@ -85,47 +70,8 @@
         }
 
         int count = jdbc.queryForInt("select count(*) from books");
-        assertEquals("Number of books", 1, count);
-    }
-    // END SNIPPET: e4
-
-    protected RouteBuilder createRouteBuilder() throws Exception {
-        // START SNIPPET: e1
-        // Notice that we use the SpringRouteBuilder that has a few more features than
-        // the standard RouteBuilder
-        return new SpringRouteBuilder() {
-            public void configure() throws Exception {
-                // START SNIPPET: e1
-                // setup the transaction policy
-                SpringTransactionPolicy required = context.getRegistry()
-                    .lookup("PROPAGATION_REQUIRED", SpringTransactionPolicy.class);
-
-                // use this error handler instead of DeadLetterChannel that is the default
-                // Notice: transactionErrorHandler is in SpringRouteBuilder
-                if (useTransactionErrorHandler) {
-                    // useTransactionErrorHandler is only used for unit testing to reuse
code
-                    // for doing a 2nd test without this transaction error handler, so ignore
-                    // this. For spring based transaction, end users are encouraged to use
the
-                    // transaction error handler instead of the default DeadLetterChannel.
-                    errorHandler(transactionErrorHandler(required).
-                        // notice that the builder has builder methods for chained configuration
-                        delay(5 * 1000L));
-                }
-                // END SNIPPET: e1
-
-                // START SNIPPET: e2
-                // set the required policy for this route
-                from("direct:okay").policy(required).
-                    setBody(constant("Tiger in Action")).beanRef("bookService").
-                    setBody(constant("Elephant in Action")).beanRef("bookService");
-
-                // set the required policy for this route
-                from("direct:fail").policy(required).
-                    setBody(constant("Tiger in Action")).beanRef("bookService").
-                    setBody(constant("Donkey in Action")).beanRef("bookService");
-                // END SNIPPET: e2
-            }
-        };
+        // TODO: Fix this bug with Spring DSL not working with TX policies
+        // assertEquals("Number of books", 1, count);
     }
 
-}
+}
\ No newline at end of file

Modified: camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTest.java?rev=762400&r1=762399&r2=762400&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTest.java
(original)
+++ camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTest.java
Mon Apr  6 15:51:08 2009
@@ -46,9 +46,7 @@
 
     @Override
     protected void setUp() throws Exception {
-        this.disableJMX();
         super.setUp();
-
         // START SNIPPET: e5
         // create database and insert dummy data
         final DataSource ds = getMandatoryBean(DataSource.class, "dataSource");
@@ -62,7 +60,6 @@
     protected void tearDown() throws Exception {
         super.tearDown();
         jdbc.execute("drop table books");
-        this.enableJMX();
     }
 
     // START SNIPPET: e3

Copied: camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/springTransactionalClientDataSource.xml
(from r762047, camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/transactionalClientDataSource.xml)
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/springTransactionalClientDataSource.xml?p2=camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/springTransactionalClientDataSource.xml&p1=camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/transactionalClientDataSource.xml&r1=762047&r2=762400&rev=762400&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/transactionalClientDataSource.xml
(original)
+++ camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/springTransactionalClientDataSource.xml
Mon Apr  6 15:51:08 2009
@@ -21,29 +21,42 @@
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
          http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">
 
-    <!-- START SNIPPET: e1 -->
-    <!-- datasource to the database -->
-    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
-        <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
-        <property name="url" value="jdbc:hsqldb:mem:camel"/>
-        <property name="username" value="sa"/>
-        <property name="password" value=""/>
-    </bean>
-
-    <!-- spring transaction manager -->
-    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
-        <property name="dataSource" ref="dataSource"/>
-    </bean>
+    <import resource="transactionalClientDataSource.xml"/>
 
-    <!-- policy for required transaction used in our Camel routes -->
-    <bean id="PROPAGATION_REQUIRED" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
+    <bean id="required" class="org.springframework.transaction.support.TransactionTemplate">
         <property name="transactionManager" ref="txManager"/>
     </bean>
 
-    <!-- bean for book business logic -->
-    <bean id="bookService" class="org.apache.camel.spring.interceptor.BookService">
-        <property name="dataSource" ref="dataSource"/>
+    <bean id="errorHandler" class="org.apache.camel.spring.spi.TransactionErrorHandlerBuilder">
+        <property name="transactionTemplate" ref="required"/>
     </bean>
-    <!-- END SNIPPET: e1 -->
+
+    <camelContext errorHandlerRef="errorHandler" id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
+        <route>
+            <from uri="direct:okay"/>
+            <policy ref="PROPAGATION_REQUIRED"/>
+            <setBody>
+                <constant>Tiger in Action</constant>
+            </setBody>
+            <bean ref="bookService"/>
+            <setBody>
+                <constant>Elephant in Action</constant>
+            </setBody>
+            <bean ref="bookService"/>
+        </route>
+
+        <route>
+            <from uri="direct:fail"/>
+            <policy ref="PROPAGATION_REQUIRED"/>
+            <setBody>
+                <constant>Tiger in Action</constant>
+            </setBody>
+            <bean ref="bookService"/>
+            <setBody>
+                <constant>Donkey in Action</constant>
+            </setBody>
+            <bean ref="bookService"/>
+        </route>
+    </camelContext>
 
 </beans>



Mime
View raw message