1
2
3
4
5
6
7
8
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 testDispatchWithQueueEvent() throws Exception
31 {
32 serviceComponentAck = false;
33 MuleClient client = new MuleClient();
34 client.dispatch("vm://dispatchInQueue?connector=vmQueue", "TEST", null);
35 MuleMessage message = client.request("vm://out?connector=vmQueue", 10000);
36 assertNotNull("Message", message);
37 assertTrue("Service component acknowledgement", serviceComponentAck);
38 }
39
40 public void testDispatchWithoutQueueEvent() throws Exception
41 {
42 serviceComponentAck = false;
43 MuleClient client = new MuleClient();
44 client.dispatch("vm://dispatchInNoQueue?connector=vmNoQueue", "TEST", null);
45 MuleMessage message = client.request("vm://out?connector=vmQueue", 10000);
46 assertNotNull("Message", message);
47 assertTrue("Service component acknowledgement", serviceComponentAck);
48 }
49
50 public void testSendWithQueueEvent() throws Exception
51 {
52 serviceComponentAck = false;
53 MuleClient client = new MuleClient();
54 MuleMessage message = client.send("vm://sendRequestInQueue?connector=vmQueue", "TEST", null);
55 assertNotNull("Message", message);
56 assertTrue("Service component acknowledgement", serviceComponentAck);
57 }
58
59 public void testSendWithoutQueueEvent() throws Exception
60 {
61 serviceComponentAck = false;
62 MuleClient client = new MuleClient();
63 MuleMessage message = client.send("vm://sendRequestInNoQueue?connector=vmNoQueue", "TEST", null);
64 assertNotNull("Message", message);
65 assertTrue("Service component acknowledgement", serviceComponentAck);
66 }
67
68 public static class TestComponent
69 {
70
71 public Object process(Object message) throws Exception
72 {
73 if (TransactionCoordination.getInstance().getTransaction() != null)
74 {
75 serviceComponentAck = true;
76 }
77 return message;
78 }
79
80 }
81
82 }