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.transport.jms.integration;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.module.client.MuleClient;
11  
12  import org.junit.Test;
13  
14  import static org.junit.Assert.assertEquals;
15  import static org.junit.Assert.assertNotNull;
16  import static org.junit.Assert.assertNull;
17  
18  public class JmsXATransactionComponentTestCase extends AbstractJmsFunctionalTestCase
19  {
20  
21      public static final String CONNECTOR1_NAME = "jmsConnector";
22  
23      @Override
24      protected String getConfigResources()
25      {
26          return "integration/jms-xa-tx-component.xml";
27      }
28  
29      @Test
30      public void testOneGlobalTx() throws Exception
31      {
32          MuleMessage result;
33          MuleClient client = new MuleClient(muleContext);
34          client.dispatch("vm://in", DEFAULT_INPUT_MESSAGE, null);
35          result = client.request("vm://out", getTimeout());
36          assertNotNull(result);
37          result = client.request("vm://out", getSmallTimeout());
38          assertNull(result);
39          muleContext.getRegistry().lookupConnector(CONNECTOR1_NAME).stop();
40          assertEquals(muleContext.getRegistry().lookupConnector(CONNECTOR1_NAME).isStarted(), false);
41          logger.info(CONNECTOR1_NAME + " is stopped");
42          client.dispatch("vm://in", DEFAULT_INPUT_MESSAGE, null);
43          Thread.sleep(1000);
44          muleContext.getRegistry().lookupConnector(CONNECTOR1_NAME).start();
45          Thread.sleep(1000);
46          logger.info(CONNECTOR1_NAME + " is started");
47          result = client.request("vm://out", getTimeout());
48          assertNotNull(result);
49          result = client.request("vm://out", getSmallTimeout());
50          assertNull(result);
51      }
52  }