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.vm.functional;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.module.client.MuleClient;
11  import org.mule.tck.junit4.FunctionalTestCase;
12  import org.mule.transaction.TransactionCoordination;
13  
14  import org.apache.commons.logging.Log;
15  import org.apache.commons.logging.LogFactory;
16  import org.junit.Test;
17  
18  import static org.junit.Assert.assertNotNull;
19  import static org.junit.Assert.assertTrue;
20  
21  public class VmTransactionTestCase extends FunctionalTestCase
22  {
23      protected static volatile boolean serviceComponentAck = false;
24      protected static final Log logger = LogFactory.getLog(VmTransactionTestCase.class);
25  
26      @Override
27      protected String getConfigResources()
28      {
29          return "vm/vm-transaction.xml";
30      }
31  
32      @Test
33      public void testDispatch() throws Exception
34      {
35          serviceComponentAck = false;
36          MuleClient client = new MuleClient(muleContext);
37          client.dispatch("vm://dispatchIn", "TEST", null);
38          MuleMessage message = client.request("vm://out", 10000);
39          assertNotNull("Message", message);
40      }
41  
42      @Test
43      public void testSend() throws Exception
44      {
45          serviceComponentAck = false;
46          MuleClient client = new MuleClient(muleContext);
47          MuleMessage message = client.send("vm://sendRequestIn", "TEST", null);
48          assertNotNull("Message", message);
49          assertTrue("Service component acknowledgement", serviceComponentAck);
50      }
51  
52      public static class TestComponent
53      {
54  
55          public Object process(Object message) throws Exception
56          {
57              if (TransactionCoordination.getInstance().getTransaction() != null)
58              {
59                  serviceComponentAck = true;
60              }
61              return message;
62          }
63  
64      }
65  
66  }