View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.config.spring.parsers;
8   
9   import org.mule.tck.junit4.FunctionalTestCase;
10  import org.mule.tck.testmodels.mule.TestTransactionManagerFactory;
11  
12  import java.lang.reflect.Proxy;
13  import java.util.Map;
14  
15  import javax.transaction.TransactionManager;
16  
17  import org.junit.Test;
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.assertTrue;
21  
22  public class CustomTransactionManagerTestCase extends FunctionalTestCase
23  {
24  
25      @Override
26      public String getConfigResources()
27      {
28          return "test-custom-transaction-manager.xml";
29      }
30  
31      @Test
32      public void testCustomTransactionManager() throws Exception
33      {
34          TransactionManager transactionManager = muleContext.getTransactionManager();
35          assertTrue(transactionManager instanceof Proxy);
36          Proxy proxy = (Proxy) transactionManager;
37          TestTransactionManagerFactory.InternalInvocationHandler ihandler =
38                  (TestTransactionManagerFactory.InternalInvocationHandler) Proxy.getInvocationHandler(proxy);
39          assertTrue(ihandler.getParent() instanceof TestTransactionManagerFactory);
40          TestTransactionManagerFactory factory = ihandler.getParent();
41          Map properties = factory.getEnvironment();
42          assertEquals(properties.size(), 2);
43          assertEquals(properties.get("property1"), "true");
44          assertEquals(properties.get("property2"), "Test");
45      }
46  
47  
48      /*
49       * Attention: this test only runs successful when it's the only one. As soon
50       * as the test above is added, muleContext contains more than one transaction
51       * manager and all kinds of havoc happen here.
52  
53      @Test
54      public void testWeblogicTransactionManager() throws Exception
55      {
56          TransactionManager transactionManager = muleContext.getTransactionManager();
57          assertNotNull(transactionManager);
58          transactionManager.begin();
59          Transaction transaction = transactionManager.getTransaction();
60          assertNotNull(transaction);
61          transactionManager.rollback();
62          assertNull(transactionManager.getTransaction());
63      }
64      */
65  
66  }