1   /*
2    * $Id:MuleTransactionConfigTestCase.java 7383 2007-07-07 22:21:30Z aperepel $
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  
11  package org.mule;
12  
13  import org.mule.api.transaction.TransactionConfig;
14  import org.mule.api.transaction.TransactionException;
15  import org.mule.tck.AbstractMuleTestCase;
16  import org.mule.tck.testmodels.mule.TestTransactionFactory;
17  import org.mule.transaction.MuleTransactionConfig;
18  
19  public class MuleTransactionConfigTestCase extends AbstractMuleTestCase
20  {
21      public void testActionAndStringConversion()
22      {
23          MuleTransactionConfig c = new MuleTransactionConfig();
24  
25          c.setAction(MuleTransactionConfig.ACTION_ALWAYS_BEGIN);
26          assertEquals(MuleTransactionConfig.ACTION_ALWAYS_BEGIN_STRING, c.getActionAsString());
27  
28          c.setAction(MuleTransactionConfig.ACTION_ALWAYS_JOIN);
29          assertEquals(MuleTransactionConfig.ACTION_ALWAYS_JOIN_STRING, c.getActionAsString());
30  
31          c.setAction(MuleTransactionConfig.ACTION_BEGIN_OR_JOIN);
32          assertEquals(MuleTransactionConfig.ACTION_BEGIN_OR_JOIN_STRING, c.getActionAsString());
33  
34          c.setAction(MuleTransactionConfig.ACTION_JOIN_IF_POSSIBLE);
35          assertEquals(MuleTransactionConfig.ACTION_JOIN_IF_POSSIBLE_STRING, c.getActionAsString());
36  
37          c.setAction(MuleTransactionConfig.ACTION_NONE);
38          assertEquals(MuleTransactionConfig.ACTION_NONE_STRING, c.getActionAsString());
39      }
40      
41      public void testTransactionJoinIfPossible() throws TransactionException
42      {      
43          MuleTransactionConfig txConfig = new MuleTransactionConfig();
44          txConfig.setAction(TransactionConfig.ACTION_JOIN_IF_POSSIBLE);
45          txConfig.setFactory(new TestTransactionFactory());
46          assertFalse(txConfig.isTransacted());
47      }
48      
49      public void testFailNoFactory()
50      {
51          MuleTransactionConfig txConfig = new MuleTransactionConfig();
52          txConfig.setAction(TransactionConfig.ACTION_ALWAYS_BEGIN);
53          // note how we don't set a factory here so the default in MTC is null
54          
55          try
56          {
57              txConfig.isTransacted();
58              fail("isTransacted must fail if no factory is set");
59          }
60          catch (RuntimeException re)
61          {
62              // this was expected
63          }
64      }
65  
66  }