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