View Javadoc

1   /*
2    * $Id: VmTransactionTestCase.java 22449 2011-07-19 07:40:43Z justin.calleja $
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 static org.junit.Assert.assertNotNull;
13  import static org.junit.Assert.assertTrue;
14  
15  import java.util.Arrays;
16  import java.util.Collection;
17  
18  import org.apache.commons.logging.Log;
19  import org.apache.commons.logging.LogFactory;
20  import org.junit.Test;
21  import org.junit.runners.Parameterized.Parameters;
22  import org.mule.api.MuleMessage;
23  import org.mule.module.client.MuleClient;
24  import org.mule.tck.AbstractServiceAndFlowTestCase;
25  import org.mule.transaction.TransactionCoordination;
26  
27  public class VmTransactionTestCase extends AbstractServiceAndFlowTestCase
28  {    
29      protected static volatile boolean serviceComponentAck = false;
30      protected static final Log logger = LogFactory.getLog(VmTransactionTestCase.class);
31  
32      public VmTransactionTestCase(ConfigVariant variant, String configResources)
33      {
34          super(variant, configResources);
35      }
36      
37      @Parameters
38      public static Collection<Object[]> parameters()
39      {
40          return Arrays.asList(new Object[][]{
41              {ConfigVariant.SERVICE, "vm/vm-transaction-service.xml"},
42              {ConfigVariant.FLOW, "vm/vm-transaction-flow.xml"}
43          });
44      }
45     
46      @Test
47      public void testDispatch() throws Exception
48      {
49          serviceComponentAck = false;
50          MuleClient client = new MuleClient(muleContext);
51          client.dispatch("vm://dispatchIn", "TEST", null);
52          MuleMessage message = client.request("vm://out", 10000);
53          assertNotNull("Message", message);
54      }
55  
56      @Test
57      public void testSend() throws Exception
58      {
59          serviceComponentAck = false;
60          MuleClient client = new MuleClient(muleContext);
61          MuleMessage message = client.send("vm://sendRequestIn", "TEST", null);
62          assertNotNull("Message", message);
63          assertTrue("Service component acknowledgement", serviceComponentAck);
64      }
65  
66      public static class TestComponent
67      {
68  
69          public Object process(Object message) throws Exception
70          {
71              if (TransactionCoordination.getInstance().getTransaction() != null)
72              {
73                  serviceComponentAck = true;
74              }
75              return message;
76          }
77  
78      }
79  
80  }