1
2
3
4
5
6
7
8
9
10
11 package org.mule.test.integration.exceptions;
12
13 import org.mule.api.DefaultMuleException;
14 import org.mule.api.transaction.Transaction;
15 import org.mule.config.i18n.CoreMessages;
16 import org.mule.exception.DefaultSystemExceptionStrategy;
17 import org.mule.routing.filters.WildcardFilter;
18 import org.mule.tck.AbstractMuleTestCase;
19 import org.mule.tck.testmodels.mule.TestTransaction;
20 import org.mule.transaction.TransactionCoordination;
21
22 import java.io.FileNotFoundException;
23
24 public class ExceptionRollbackTestCase extends AbstractMuleTestCase
25 {
26 private DefaultSystemExceptionStrategy strategy;
27 private Transaction tx;
28
29 @Override
30 protected void doSetUp() throws Exception
31 {
32 strategy = new DefaultSystemExceptionStrategy(muleContext);
33 strategy.setCommitTxFilter(new WildcardFilter("java.io.*"));
34 strategy.setRollbackTxFilter(new WildcardFilter("org.mule.*, javax.*"));
35
36 initialiseObject(strategy);
37 tx = new TestTransaction(muleContext);
38 TransactionCoordination.getInstance().bindTransaction(tx);
39 }
40
41 @Override
42 protected void doTearDown() throws Exception
43 {
44 TransactionCoordination.getInstance().unbindTransaction(tx);
45 }
46
47 public void testCommit() throws Exception
48 {
49 strategy.handleException(new FileNotFoundException());
50 assertFalse(tx.isRollbackOnly());
51
52
53 }
54
55 public void testRollback() throws Exception
56 {
57 strategy.handleException(new DefaultMuleException(CoreMessages.agentsRunning()));
58 assertTrue(tx.isRollbackOnly());
59
60 assertFalse(tx.isCommitted());
61 }
62
63 public void testRollbackByDefault() throws Exception
64 {
65 strategy.handleException(new IllegalAccessException());
66 assertTrue(tx.isRollbackOnly());
67
68 assertFalse(tx.isCommitted());
69 }
70 }