1   /*
2    * $Id: JmsSingleTransactionComponentTestCase.java 10384 2008-01-18 11:35:23Z akuzmin $
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  package org.mule.test.integration.providers.jms.functional;
11  
12  import org.mule.MuleManager;
13  import org.mule.tck.functional.EventCallback;
14  import org.mule.tck.functional.FunctionalTestComponent;
15  import org.mule.transaction.TransactionCoordination;
16  import org.mule.umo.UMOEventContext;
17  import org.mule.umo.UMOTransaction;
18  
19  import java.util.HashSet;
20  import java.util.Set;
21  
22  
23  /**
24   * Get transaction status inside component
25   * There is a separate transaction for each component
26   * when single transaction(action: BEGIN_OR_JOIN) and jms transport are used
27   */
28  public class JmsSingleTransactionComponentTestCase extends AbstractJmsFunctionalTestCase
29  {
30      public static final String MODEL_NAME = "TEST";
31      public static final String COMPONENT_NAME = "Part";
32      /**
33       * Every Transaction has to be different instance
34       */
35      public final Set transactions = new HashSet();
36  
37      protected String getConfigResources()
38      {
39          return "providers/activemq/jms-single-tx-component.xml";
40      }
41  
42      public void testDifferentTx() throws Exception
43      {
44          EventCallback callback = new EventCallback()
45          {
46              public void eventReceived(UMOEventContext context, Object component) throws Exception
47              {
48                  UMOTransaction transaction = TransactionCoordination.getInstance().getTransaction();
49                  assertNotNull(transaction);
50                  assertFalse(transactions.contains(transaction));
51                  transactions.add(transaction);
52              }
53          };
54  
55          for (int i = 1; i < 5; i++)
56          {
57              ((FunctionalTestComponent) MuleManager.getInstance().lookupModel(MODEL_NAME).getComponent(COMPONENT_NAME + i).getDescriptor().getImplementation()).
58                      setEventCallback(callback);
59          }
60  
61          dispatchMessage();
62          recieveMessage();
63      }
64  }