View Javadoc

1   /*
2    * $Id: CustomTransactionManagerTestCase.java 22414 2011-07-14 13:24:46Z dirk.olmes $
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.junit4.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  import org.junit.Test;
21  
22  import static org.junit.Assert.assertEquals;
23  import static org.junit.Assert.assertTrue;
24  
25  public class CustomTransactionManagerTestCase extends FunctionalTestCase
26  {
27  
28      @Override
29      public String getConfigResources()
30      {
31          return "test-custom-transaction-manager.xml";
32      }
33  
34      @Test
35      public void testCustomTransactionManager() throws Exception
36      {
37          TransactionManager transactionManager = muleContext.getTransactionManager();
38          assertTrue(transactionManager instanceof Proxy);
39          Proxy proxy = (Proxy) transactionManager;
40          TestTransactionManagerFactory.InternalInvocationHandler ihandler =
41                  (TestTransactionManagerFactory.InternalInvocationHandler) Proxy.getInvocationHandler(proxy);
42          assertTrue(ihandler.getParent() instanceof TestTransactionManagerFactory);
43          TestTransactionManagerFactory factory = ihandler.getParent();
44          Map properties = factory.getEnvironment();
45          assertEquals(properties.size(), 2);
46          assertEquals(properties.get("property1"), "true");
47          assertEquals(properties.get("property2"), "Test");
48      }
49  
50  
51      /*
52       * Attention: this test only runs successful when it's the only one. As soon
53       * as the test above is added, muleContext contains more than one transaction
54       * manager and all kinds of havoc happen here.
55  
56      @Test
57      public void testWeblogicTransactionManager() throws Exception
58      {
59          TransactionManager transactionManager = muleContext.getTransactionManager();
60          assertNotNull(transactionManager);
61          transactionManager.begin();
62          Transaction transaction = transactionManager.getTransaction();
63          assertNotNull(transaction);
64          transactionManager.rollback();
65          assertNull(transactionManager.getTransaction());
66      }
67      */
68  
69  }