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