View Javadoc

1   /*
2    * $Id: CustomTransactionManagerTestCase.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.config.spring.parsers;
11  
12  import org.mule.tck.FunctionalTestCase;
13  import org.mule.tck.testmodels.mule.TestTransactionManagerFactory;
14  
15  import java.lang.reflect.Proxy;
16  import java.util.Map;
17  
18  import javax.transaction.TransactionManager;
19  
20  public class CustomTransactionManagerTestCase extends FunctionalTestCase
21  {
22      public String getConfigResources()
23      {
24          return "test-custom-transaction-manager.xml";
25      }
26  
27      public void testCustomTransactionManager() throws Exception
28      {
29          TransactionManager transactionManager = muleContext.getTransactionManager();
30          assertTrue(transactionManager instanceof Proxy);
31          Proxy proxy = (Proxy) transactionManager;
32          TestTransactionManagerFactory.InternalInvocationHandler ihandler =
33                  (TestTransactionManagerFactory.InternalInvocationHandler) Proxy.getInvocationHandler(proxy);
34          assertTrue(ihandler.getParent() instanceof TestTransactionManagerFactory);
35          TestTransactionManagerFactory factory = ihandler.getParent();
36          Map properties = factory.getEnvironment();
37          assertEquals(properties.size(), 2);
38          assertEquals(properties.get("property1"), "true");
39          assertEquals(properties.get("property2"), "Test");
40      }
41  
42  
43      /*
44       * Attention: this test only runs successful when it's the only one. As soon
45       * as the test above is added, muleContext contains more than one transaction
46       * manager and all kinds of havoc happen here.
47       
48      public void testWeblogicTransactionManager() throws Exception
49      {
50          TransactionManager transactionManager = muleContext.getTransactionManager();
51          assertNotNull(transactionManager);
52          transactionManager.begin();
53          Transaction transaction = transactionManager.getTransaction();
54          assertNotNull(transaction);
55          transactionManager.rollback();
56          assertNull(transactionManager.getTransaction());
57      }
58      */
59  
60  }