1   /*
2    * $Id: VmTransactionTestCase.java 10427 2008-01-21 15:16:44Z 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.providers.vm.functional;
11  
12  import org.mule.extras.client.MuleClient;
13  import org.mule.tck.FunctionalTestCase;
14  import org.mule.transaction.TransactionCoordination;
15  import org.mule.umo.UMOMessage;
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 success = true;
23      protected static final Log logger = LogFactory.getLog(VmTransactionTestCase.class);
24  
25      protected String getConfigResources()
26      {
27          return "vm-transaction.xml";
28      }
29  
30      public void testTransactionQueueEventsTrue() throws Exception
31      {
32          success = true;
33          MuleClient client = new MuleClient();
34          client.dispatch("vm://in?connector=vm", "TEST", null);
35          UMOMessage message = client.receive("vm://out?connector=vm", 10000);
36          assertNotNull(message);
37          assertTrue(success);
38  
39      }
40  
41      public void testTransactionSyncEndpoint() throws Exception
42      {
43          success = true;
44          MuleClient client = new MuleClient();
45          UMOMessage message = client.send("vm://sync?connector=vm", "TEST", null);
46          assertNotNull(message);
47          assertTrue(success);
48  
49      }
50  
51      public void testTransactionQueueEventsFalse() throws Exception
52      {
53          success = true;
54          MuleClient client = new MuleClient();
55          client.dispatch("vm://int3?connector=vmOnFly", "TEST", null);
56          UMOMessage message = client.receive("vm://outt3?connector=vm", 10000);
57          assertNotNull(message);
58          assertTrue(success);
59  
60      }
61  
62  
63      public static class TestComponent
64      {
65  
66          public Object process(Object a) throws Exception
67          {
68              if (TransactionCoordination.getInstance().getTransaction() == null)
69              {
70                  success = false;
71                  logger.error("Transction is null");
72              }
73              return a;
74          }
75  
76      }
77  
78  }