1   /*
2    * $Id: ActiveMQJmsXaTransactionFunctionalTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
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.test.integration.providers.jms.activemq;
12  
13  import org.mule.MuleManager;
14  import org.mule.providers.jms.JmsConnector;
15  import org.mule.providers.jms.JmsConstants;
16  import org.mule.providers.jms.activemq.ActiveMqJmsConnector;
17  import org.mule.transaction.XaTransactionFactory;
18  import org.mule.umo.UMOTransactionFactory;
19  
20  import javax.jms.Connection;
21  import javax.jms.ConnectionFactory;
22  import javax.transaction.TransactionManager;
23  
24  import org.apache.activemq.ActiveMQConnectionFactory;
25  import org.apache.activemq.ActiveMQXAConnectionFactory;
26  import org.objectweb.jotm.Current;
27  import org.objectweb.jotm.Jotm;
28  
29  public class ActiveMQJmsXaTransactionFunctionalTestCase extends ActiveMQJmsTransactionFunctionalTestCase
30  {
31      private TransactionManager txManager;
32  
33      public ConnectionFactory getConnectionFactory() throws Exception
34      {
35          if (factory == null)
36          {
37              factory = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false&broker.useJmx=false");
38          }
39          return factory;
40      }
41  
42      public Connection getSenderConnection() throws Exception
43      {
44          factory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false&broker.useJmx=false");
45          return factory.createConnection();
46      }
47  
48      protected void doSetUp() throws Exception
49      {
50          // check for already active JOTM instance
51          txManager = Current.getCurrent();
52          // if none found, create new local JOTM instance
53          if (txManager == null)
54          {
55              new Jotm(true, false);
56              txManager = Current.getCurrent();
57          }
58          txManager.setTransactionTimeout(15000);
59          super.doSetUp();
60          MuleManager.getInstance().setTransactionManager(txManager);
61      }
62  
63      public JmsConnector createConnector() throws Exception
64      {
65          ActiveMqJmsConnector connector = new ActiveMqJmsConnector();
66          connector.setName(CONNECTOR_NAME);
67          connector.setSpecification(JmsConstants.JMS_SPECIFICATION_11);
68          connector.setConnectionFactoryJndiName("XAJmsQueueConnectionFactory");
69          return connector;
70      }
71  
72      public UMOTransactionFactory getTransactionFactory()
73      {
74          return new XaTransactionFactory();
75      }
76  
77      public void afterInitialise() throws Exception
78      {
79          Thread.sleep(5000);
80      }
81  
82      public void testSendNotTransacted() throws Exception
83      {
84          // Cannot send non transacted messages when the connection is an
85          // XAConnection
86      }
87  
88      public void testSendTransactedIfPossibleWithoutTransaction() throws Exception
89      {
90          // there will always be a transaction available if using an Xa connector
91          // so this will always fail
92      }
93  }