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/09/04 07:48:47 UTC
svn commit: r811223 -
/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/
Author: davsclaus
Date: Fri Sep 4 05:48:47 2009
New Revision: 811223
URL: http://svn.apache.org/viewvc?rev=811223&view=rev
Log:
Added unit test based on user forum issue
Added:
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileLocalOnExceptionTest.java (with props)
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileOnExceptionTest.java (with props)
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileTest.java (with props)
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithLocalOnExceptionTest.java
- copied, changed from r811214, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceWithOnExceptionTest.java
Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileLocalOnExceptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileLocalOnExceptionTest.java?rev=811223&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileLocalOnExceptionTest.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileLocalOnExceptionTest.java Fri Sep 4 05:48:47 2009
@@ -0,0 +1,45 @@
+/**
+ * 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.interceptor;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spring.SpringRouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class TransactionalClientDataSourceTransactedWithFileLocalOnExceptionTest extends TransactionalClientDataSourceTransactedWithFileOnExceptionTest {
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new SpringRouteBuilder() {
+ public void configure() throws Exception {
+
+ from("file://target/transacted/okay")
+ .transacted()
+ .setBody(constant("Tiger in Action")).beanRef("bookService")
+ .setBody(constant("Elephant in Action")).beanRef("bookService");
+
+ from("file://target/transacted/fail?moveFailed=../failed")
+ .transacted()
+ .onException(IllegalArgumentException.class).handled(false).to("mock:error")
+ .setBody(constant("Tiger in Action")).beanRef("bookService")
+ .setBody(constant("Donkey in Action")).beanRef("bookService");
+ }
+ };
+ }
+
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileLocalOnExceptionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileLocalOnExceptionTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileOnExceptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileOnExceptionTest.java?rev=811223&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileOnExceptionTest.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileOnExceptionTest.java Fri Sep 4 05:48:47 2009
@@ -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.spring.interceptor;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.SpringRouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class TransactionalClientDataSourceTransactedWithFileOnExceptionTest extends TransactionalClientDataSourceTransactedWithFileTest {
+
+ public void testTransactionRollback() throws Exception {
+ MockEndpoint error = getMockEndpoint("mock:error");
+ error.expectedMessageCount(1);
+ error.message(0).header(Exchange.EXCEPTION_CAUGHT).isNotNull();
+ error.message(0).header(Exchange.EXCEPTION_CAUGHT).isInstanceOf(IllegalArgumentException.class);
+ error.expectedFileExists("target/transacted/failed/fail.txt");
+
+ template.sendBodyAndHeader("file://target/transacted/fail", "Hello World", Exchange.FILE_NAME, "fail.txt");
+
+ // wait for route to complete
+ Thread.sleep(2000);
+
+ // should not be able to process the file so we still got 1 book as we did from the start
+ int count = jdbc.queryForInt("select count(*) from books");
+ assertEquals("Number of books", 1, count);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new SpringRouteBuilder() {
+ public void configure() throws Exception {
+ onException(IllegalArgumentException.class).handled(false).to("mock:error");
+
+ from("file://target/transacted/okay")
+ .transacted()
+ .setBody(constant("Tiger in Action")).beanRef("bookService")
+ .setBody(constant("Elephant in Action")).beanRef("bookService");
+
+ from("file://target/transacted/fail?moveFailed=../failed")
+ .transacted()
+ .setBody(constant("Tiger in Action")).beanRef("bookService")
+ .setBody(constant("Donkey in Action")).beanRef("bookService");
+ }
+ };
+ }
+
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileOnExceptionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileOnExceptionTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileTest.java?rev=811223&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileTest.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileTest.java Fri Sep 4 05:48:47 2009
@@ -0,0 +1,71 @@
+/**
+ * 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.interceptor;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spring.SpringRouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class TransactionalClientDataSourceTransactedWithFileTest extends TransactionalClientDataSourceTransactedTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ deleteDirectory("target/transacted");
+ super.setUp();
+ }
+
+ public void testTransactionSuccess() throws Exception {
+ template.sendBodyAndHeader("file://target/transacted/okay", "Hello World", Exchange.FILE_NAME, "okay.txt");
+
+ // wait for route to complete
+ Thread.sleep(2000);
+
+ int count = jdbc.queryForInt("select count(*) from books");
+ assertEquals("Number of books", 3, count);
+ }
+
+ public void testTransactionRollback() throws Exception {
+ template.sendBodyAndHeader("file://target/transacted/fail", "Hello World", Exchange.FILE_NAME, "fail.txt");
+
+ // wait for route to complete
+ Thread.sleep(2000);
+
+ // should not be able to process the file so we still got 1 book as we did from the start
+ int count = jdbc.queryForInt("select count(*) from books");
+ assertEquals("Number of books", 1, count);
+ }
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new SpringRouteBuilder() {
+ public void configure() throws Exception {
+ from("file://target/transacted/okay")
+ .transacted()
+ .setBody(constant("Tiger in Action")).beanRef("bookService")
+ .setBody(constant("Elephant in Action")).beanRef("bookService");
+
+ from("file://target/transacted/fail")
+ .transacted()
+ .setBody(constant("Tiger in Action")).beanRef("bookService")
+ .setBody(constant("Donkey in Action")).beanRef("bookService");
+ }
+ };
+ }
+
+}
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithFileTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithLocalOnExceptionTest.java (from r811214, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceWithOnExceptionTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithLocalOnExceptionTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithLocalOnExceptionTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceWithOnExceptionTest.java&r1=811214&r2=811223&rev=811223&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceWithOnExceptionTest.java (original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedWithLocalOnExceptionTest.java Fri Sep 4 05:48:47 2009
@@ -16,65 +16,32 @@
*/
package org.apache.camel.spring.interceptor;
-import org.apache.camel.RuntimeCamelException;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.spring.SpringRouteBuilder;
-import org.apache.camel.spring.spi.SpringTransactionPolicy;
-import org.apache.camel.spring.spi.TransactedRuntimeCamelException;
/**
* Unit test to demonstrate the transactional client pattern.
*/
-public class TransactionalClientDataSourceWithOnExceptionTest extends TransactionalClientDataSourceTest {
-
- protected int getExpectedRouteCount() {
- return 0;
- }
-
- public void testTransactionRollback() throws Exception {
- MockEndpoint mock = getMockEndpoint("mock:error");
- mock.expectedMessageCount(1);
-
- try {
- template.sendBody("direct:fail", "Hello World");
- } catch (RuntimeCamelException e) {
- // expeced as we fail
- assertIsInstanceOf(TransactedRuntimeCamelException.class, e.getCause());
- assertTrue(e.getCause().getCause() instanceof IllegalArgumentException);
- assertEquals("We don't have Donkeys, only Camels", e.getCause().getCause().getMessage());
- }
-
- assertMockEndpointsSatisfied();
-
- int count = jdbc.queryForInt("select count(*) from books");
- assertEquals("Number of books", 1, count);
- }
+public class TransactionalClientDataSourceTransactedWithLocalOnExceptionTest extends TransactionalClientDataSourceWithOnExceptionTest {
protected RouteBuilder createRouteBuilder() throws Exception {
return new SpringRouteBuilder() {
public void configure() throws Exception {
- // use required as transaction policy
- SpringTransactionPolicy required = lookup("PROPAGATION_REQUIRED", SpringTransactionPolicy.class);
-
- // configure to use transaction error handler and pass on the required as it will fetch
- // the transaction manager from it that it needs
- errorHandler(transactionErrorHandler(required));
-
- // on exception is also supported
- onException(IllegalArgumentException.class).handled(false).to("mock:error");
-
from("direct:okay")
- .policy(required)
+ .transacted()
+ // use local on exception
+ .onException(IllegalArgumentException.class).handled(false).to("mock:error")
.setBody(constant("Tiger in Action")).beanRef("bookService")
.setBody(constant("Elephant in Action")).beanRef("bookService");
from("direct:fail")
- .policy(required)
+ .transacted()
+ // use local on exception
+ .onException(IllegalArgumentException.class).handled(false).to("mock:error")
.setBody(constant("Tiger in Action")).beanRef("bookService")
.setBody(constant("Donkey in Action")).beanRef("bookService");
}
};
}
-}
+}
\ No newline at end of file