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.routing.filters.WildcardFilter;
16 import org.mule.service.DefaultServiceExceptionStrategy;
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
26 private DefaultServiceExceptionStrategy strategy;
27 private Transaction tx;
28
29
30 protected void doSetUp() throws Exception
31 {
32 strategy = new DefaultServiceExceptionStrategy();
33 strategy.setCommitTxFilter(new WildcardFilter("java.io.*"));
34 strategy.setRollbackTxFilter(new WildcardFilter("org.mule.*, javax.*"));
35
36 tx = new TestTransaction();
37 TransactionCoordination.getInstance().bindTransaction(tx);
38 }
39
40
41 protected void doTearDown() throws Exception
42 {
43 TransactionCoordination.getInstance().unbindTransaction(tx);
44 }
45
46 public void testCommit() throws Exception
47 {
48 strategy.exceptionThrown(new FileNotFoundException());
49 assertFalse(tx.isRollbackOnly());
50
51
52 }
53
54 public void testRollback() throws Exception
55 {
56 strategy.exceptionThrown(new DefaultMuleException(CoreMessages.agentsRunning()));
57 assertTrue(tx.isRollbackOnly());
58
59 assertFalse(tx.isCommitted());
60 }
61
62 public void testRollbackByDefault() throws Exception
63 {
64 strategy.exceptionThrown(new IllegalAccessException());
65 assertTrue(tx.isRollbackOnly());
66
67 assertFalse(tx.isCommitted());
68 }
69 }