Author: davsclaus Date: Fri Sep 4 04:50:52 2009 New Revision: 811217 URL: http://svn.apache.org/viewvc?rev=811217&view=rev Log: Added unit test based on user forum issue
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/issues/CharlesSplitAndTryCatchRollbackIssueTest.java (with props) camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SpringCharlesSplitAndTryCatchRollbackIssueTest.java (with props) camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringCharlesSplitAndTryCatchRollbackIssueTest.xml - copied, changed from r811214, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringTryCatchWithSplitIssueTest.xml Added: camel/trunk/camel-core/src/test/java/org/apache/camel/issues/CharlesSplitAndTryCatchRollbackIssueTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/CharlesSplitAndTryCatchRollbackIssueTest.java?rev=811217&view=auto ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/issues/CharlesSplitAndTryCatchRollbackIssueTest.java (added) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/issues/CharlesSplitAndTryCatchRollbackIssueTest.java Fri Sep 4 04:50:52 2009 @@ -0,0 +1,136 @@ +/** + * 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.issues; + +import org.apache.camel.CamelExchangeException; +import org.apache.camel.CamelExecutionException; +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.RollbackExchangeException; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; + +/** + * @version $Revision$ + */ +public class CharlesSplitAndTryCatchRollbackIssueTest extends ContextTestSupport { + + public void testSplitWithTryCatchAndRollbackOK() throws Exception { + MockEndpoint split = getMockEndpoint("mock:split"); + MockEndpoint ile = getMockEndpoint("mock:ile"); + MockEndpoint exception = getMockEndpoint("mock:exception"); + + split.expectedBodiesReceived("A", "B", "C"); + ile.expectedMessageCount(0); + exception.expectedMessageCount(0); + + template.sendBody("direct:start", "A,B,C"); + + assertMockEndpointsSatisfied(); + } + + public void testSplitWithTryCatchAndRollbackILE() throws Exception { + MockEndpoint split = getMockEndpoint("mock:split"); + MockEndpoint ile = getMockEndpoint("mock:ile"); + MockEndpoint exception = getMockEndpoint("mock:exception"); + + split.expectedBodiesReceived("A", "B", "C"); + ile.expectedMessageCount(1); + exception.expectedMessageCount(0); + + template.sendBody("direct:start", "A,B,Forced,C"); + + assertMockEndpointsSatisfied(); + } + + public void testSplitWithTryCatchAndRollbackException() throws Exception { + MockEndpoint split = getMockEndpoint("mock:split"); + MockEndpoint ile = getMockEndpoint("mock:ile"); + MockEndpoint exception = getMockEndpoint("mock:exception"); + + split.expectedBodiesReceived("A", "B"); + ile.expectedMessageCount(0); + exception.expectedMessageCount(1); + + try { + template.sendBody("direct:start", "A,B,Kaboom,C"); + fail("Should thrown an exception"); + } catch (CamelExecutionException e) { + CamelExchangeException ee = assertIsInstanceOf(CamelExchangeException.class, e.getCause()); + assertEquals("Sequiental processing failed for number 2 on the exchange: Exchange[Message: Kaboom]", ee.getMessage()); + RollbackExchangeException re = assertIsInstanceOf(RollbackExchangeException.class, ee.getCause()); + assertEquals("Intended rollback on the exchange: Exchange[Message: Kaboom]", re.getMessage()); + } + + assertMockEndpointsSatisfied(); + } + + public void testSplitWithTryCatchAndRollbacILEAndException() throws Exception { + MockEndpoint split = getMockEndpoint("mock:split"); + MockEndpoint ile = getMockEndpoint("mock:ile"); + MockEndpoint exception = getMockEndpoint("mock:exception"); + + split.expectedBodiesReceived("A", "B"); + ile.expectedMessageCount(1); + exception.expectedMessageCount(1); + + try { + template.sendBody("direct:start", "A,Forced,B,Kaboom,C"); + fail("Should thrown an exception"); + } catch (CamelExecutionException e) { + CamelExchangeException ee = assertIsInstanceOf(CamelExchangeException.class, e.getCause()); + assertEquals("Sequiental processing failed for number 3 on the exchange: Exchange[Message: Kaboom]", ee.getMessage()); + RollbackExchangeException re = assertIsInstanceOf(RollbackExchangeException.class, ee.getCause()); + assertEquals("Intended rollback on the exchange: Exchange[Message: Kaboom]", re.getMessage()); + } + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .split(body().tokenize(",")).stopOnException() + .doTry() + .process(new MyProcessor()) + .to("mock:split") + .doCatch(IllegalArgumentException.class) + .to("mock:ile") + .doCatch(Exception.class) + .to("mock:exception") + .rollback() + .end(); + } + }; + } + + public static class MyProcessor implements Processor { + + public void process(Exchange exchange) throws Exception { + String body = exchange.getIn().getBody(String.class); + if ("Forced".equals(body)) { + throw new IllegalArgumentException("Forced"); + } else if ("Kaboom".equals(body)) { + throw new Exception("Kaboom"); + } + } + } +} Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/issues/CharlesSplitAndTryCatchRollbackIssueTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/issues/CharlesSplitAndTryCatchRollbackIssueTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SpringCharlesSplitAndTryCatchRollbackIssueTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SpringCharlesSplitAndTryCatchRollbackIssueTest.java?rev=811217&view=auto ============================================================================== --- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SpringCharlesSplitAndTryCatchRollbackIssueTest.java (added) +++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SpringCharlesSplitAndTryCatchRollbackIssueTest.java Fri Sep 4 04:50:52 2009 @@ -0,0 +1,32 @@ +/** + * 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.issues; + +import org.apache.camel.CamelContext; +import org.apache.camel.issues.CharlesSplitAndTryCatchRollbackIssueTest; +import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext; + +/** + * @version $Revision$ + */ +public class SpringCharlesSplitAndTryCatchRollbackIssueTest extends CharlesSplitAndTryCatchRollbackIssueTest { + + protected CamelContext createCamelContext() throws Exception { + return createSpringCamelContext(this, "org/apache/camel/spring/issues/SpringCharlesSplitAndTryCatchRollbackIssueTest.xml"); + } + +} Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SpringCharlesSplitAndTryCatchRollbackIssueTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SpringCharlesSplitAndTryCatchRollbackIssueTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringCharlesSplitAndTryCatchRollbackIssueTest.xml (from r811214, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringTryCatchWithSplitIssueTest.xml) URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringCharlesSplitAndTryCatchRollbackIssueTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringCharlesSplitAndTryCatchRollbackIssueTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringTryCatchWithSplitIssueTest.xml&r1=811214&r2=811217&rev=811217&view=diff ============================================================================== --- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringTryCatchWithSplitIssueTest.xml (original) +++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringCharlesSplitAndTryCatchRollbackIssueTest.xml Fri Sep 4 04:50:52 2009 @@ -22,18 +22,24 @@ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd "> - <bean id="error" class="org.apache.camel.issues.TryCatchWithSplitIssueTest$GenerateError"/> + <bean id="myProcessor" class="org.apache.camel.issues.CharlesSplitAndTryCatchRollbackIssueTest$MyProcessor"/> <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="direct:start"/> - <split><tokenize token="@"/> + <split stopOnException="true"> + <tokenize token=","/> <doTry> - <to uri="bean:error"/> - <to uri="mock:result"/> + <process ref="myProcessor"/> + <to uri="mock:split"/> + <doCatch> + <exception>java.lang.IllegalArgumentException</exception> + <to uri="mock:ile"/> + </doCatch> <doCatch> <exception>java.lang.Exception</exception> - <to uri="mock:error"/> + <to uri="mock:exception"/> + <rollback/> </doCatch> </doTry> </split>