View Javadoc

1   /*
2    * $Id: ExceptionRollbackTestCase.java 20321 2010-11-24 15:21:24Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
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          //There is nothing to actually commit the transaction since we are not running in a real tx
52          //assertTrue(tx.isCommitted());
53      }
54  
55      public void testRollback() throws Exception
56      {
57          strategy.handleException(new DefaultMuleException(CoreMessages.agentsRunning()));
58          assertTrue(tx.isRollbackOnly());
59          //There is nothing to actually commit the transaction since we are not running in a real tx
60          assertFalse(tx.isCommitted());
61      }
62  
63      public void testRollbackByDefault() throws Exception
64      {
65          strategy.handleException(new IllegalAccessException());
66          assertTrue(tx.isRollbackOnly());
67          //There is nothing to actually commit the transaction since we are not running in a real tx
68          assertFalse(tx.isCommitted());
69      }
70  }