1   /*
2    * $Id: JmsXATransactionComponentTestCase.java 9655 2007-11-08 11:09:07Z 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.extras.client.MuleClient;
14  import org.mule.tck.functional.EventCallback;
15  import org.mule.tck.functional.FunctionalTestComponent;
16  import org.mule.transaction.TransactionCoordination;
17  import org.mule.umo.UMOEventContext;
18  import org.mule.umo.UMOMessage;
19  import org.mule.umo.UMOTransaction;
20  
21  /**
22   * Get transaction status inside component
23   */
24  public class JmsXATransactionComponentTestCase extends AbstractJmsFunctionalTestCase
25  {
26      public static final String MODEL_NAME = "TEST";
27      public static final String COMPONENT_NAME = "Part";
28      /**
29       * Every Transaction has to be one instance
30       */
31      private UMOTransaction umoTransaction = null;
32  
33      protected String getConfigResources()
34      {
35          return "providers/activemq/jms-xa-tx-component.xml";
36      }
37  
38      public void testOneGlobalTx() throws Exception
39      {
40          EventCallback callback = new EventCallback()
41          {
42              public void eventReceived(UMOEventContext context, Object component) throws Exception
43              {
44                  if (umoTransaction == null)
45                  {
46                      umoTransaction = TransactionCoordination.getInstance().getTransaction();
47                  }
48                  else
49                  {
50                      logger.error("Transactiuon: " + TransactionCoordination.getInstance().getTransaction());
51                      assertTrue(TransactionCoordination.getInstance().getTransaction().equals(umoTransaction));
52                  }
53              }
54          };
55  
56          for (int i = 1; i < 5; i++)
57          {
58              ((FunctionalTestComponent) MuleManager.getInstance().lookupModel(MODEL_NAME).getComponent(COMPONENT_NAME + i).getDescriptor().getImplementation()).
59                      setEventCallback(callback);
60          }
61  
62          MuleClient client = new MuleClient();
63          client.dispatch("vm://in", DEFAULT_INPUT_MESSAGE, null);
64          UMOMessage result = client.receive("vm://out", TIMEOUT);
65          assertNotNull(result);
66          client.dispose();
67      }
68  
69  }