View Javadoc

1   /*
2    * $Id:MuleTransactionConfigTestCase.java 7383 2007-07-07 22:21:30Z aperepel $
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;
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          c.setMuleContext(muleContext);
25  
26          c.setAction(MuleTransactionConfig.ACTION_ALWAYS_BEGIN);
27          assertEquals(MuleTransactionConfig.ACTION_ALWAYS_BEGIN_STRING, c.getActionAsString());
28  
29          c.setAction(MuleTransactionConfig.ACTION_ALWAYS_JOIN);
30          assertEquals(MuleTransactionConfig.ACTION_ALWAYS_JOIN_STRING, c.getActionAsString());
31  
32          c.setAction(MuleTransactionConfig.ACTION_BEGIN_OR_JOIN);
33          assertEquals(MuleTransactionConfig.ACTION_BEGIN_OR_JOIN_STRING, c.getActionAsString());
34  
35          c.setAction(MuleTransactionConfig.ACTION_JOIN_IF_POSSIBLE);
36          assertEquals(MuleTransactionConfig.ACTION_JOIN_IF_POSSIBLE_STRING, c.getActionAsString());
37  
38          c.setAction(MuleTransactionConfig.ACTION_NONE);
39          assertEquals(MuleTransactionConfig.ACTION_NONE_STRING, c.getActionAsString());
40      }
41  
42      public void testDefaults() throws Exception {
43          MuleTransactionConfig c = new MuleTransactionConfig();
44          c.setMuleContext(muleContext);
45          assertEquals("Wrong default TX timeout", 30000, c.getTimeout());
46      }
47  
48      public void testTransactionJoinIfPossible() throws TransactionException
49      {      
50          MuleTransactionConfig txConfig = new MuleTransactionConfig();
51          txConfig.setMuleContext(muleContext);
52          txConfig.setAction(TransactionConfig.ACTION_JOIN_IF_POSSIBLE);
53          txConfig.setFactory(new TestTransactionFactory());
54          assertFalse(txConfig.isTransacted());
55      }
56  
57      public void testFailNoFactory()
58      {
59          MuleTransactionConfig txConfig = new MuleTransactionConfig();
60          txConfig.setMuleContext(muleContext);
61          txConfig.setAction(TransactionConfig.ACTION_ALWAYS_BEGIN);
62          // note how we don't set a factory here so the default in MTC is null
63          
64          try
65          {
66              txConfig.isTransacted();
67              fail("isTransacted() must fail if no factory is set");
68          }
69          catch (RuntimeException re)
70          {
71              // this was expected
72          }
73      }
74  
75  }