1   /*
2    * $Id: ExceptionRollbackTestCase.java 11468 2008-03-21 17:54:46Z rossmason $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.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      //@Override
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      //@Override
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          //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.exceptionThrown(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.exceptionThrown(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  }