View Javadoc

1   /*
2    * $Id: VmTransactionTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.transport.vm.functional;
11  
12  import org.mule.api.MuleMessage;
13  import org.mule.module.client.MuleClient;
14  import org.mule.tck.FunctionalTestCase;
15  import org.mule.transaction.TransactionCoordination;
16  
17  import org.apache.commons.logging.Log;
18  import org.apache.commons.logging.LogFactory;
19  
20  public class VmTransactionTestCase extends FunctionalTestCase
21  {
22      protected static volatile boolean serviceComponentAck = false;
23      protected static final Log logger = LogFactory.getLog(VmTransactionTestCase.class);
24  
25      protected String getConfigResources()
26      {
27          return "vm/vm-transaction.xml";
28      }
29  
30      public void testDispatch() throws Exception
31      {
32          serviceComponentAck = false;
33          MuleClient client = new MuleClient(muleContext);
34          client.dispatch("vm://dispatchIn", "TEST", null);
35          MuleMessage message = client.request("vm://out", 10000);
36          assertNotNull("Message", message);
37      }
38  
39      public void testSend() throws Exception
40      {
41          serviceComponentAck = false;
42          MuleClient client = new MuleClient(muleContext);
43          MuleMessage message = client.send("vm://sendRequestIn", "TEST", null);
44          assertNotNull("Message", message);
45          assertTrue("Service component acknowledgement", serviceComponentAck);
46      }
47  
48      public static class TestComponent
49      {
50  
51          public Object process(Object message) throws Exception
52          {
53              if (TransactionCoordination.getInstance().getTransaction() != null)
54              {
55                  serviceComponentAck = true;
56              }
57              return message;
58          }
59  
60      }
61  
62  }