View Javadoc

1   /*
2    * $Id: ExceptionRollbackTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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  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          //There is nothing to actually commit the transaction since we are not running in a real tx
51          //assertTrue(tx.isCommitted());
52      }
53  
54      public void testRollback() throws Exception
55      {
56          strategy.handleException(new DefaultMuleException(CoreMessages.agentsRunning()));
57          assertTrue(tx.isRollbackOnly());
58          //There is nothing to actually commit the transaction since we are not running in a real tx
59          assertFalse(tx.isCommitted());
60      }
61  
62      public void testRollbackByDefault() throws Exception
63      {
64          strategy.handleException(new IllegalAccessException());
65          assertTrue(tx.isRollbackOnly());
66          //There is nothing to actually commit the transaction since we are not running in a real tx
67          assertFalse(tx.isCommitted());
68      }
69  }