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