1
2
3
4
5
6
7
8
9
10
11 package org.mule.test.integration.client;
12
13
14 import org.mule.api.MuleEvent;
15 import org.mule.api.MuleMessage;
16 import org.mule.module.client.MuleClient;
17 import org.mule.module.client.RemoteDispatcher;
18 import org.mule.tck.FunctionalTestCase;
19
20 public abstract class AbstractClientRemotingTestCase extends FunctionalTestCase
21 {
22 public abstract String getRemoteEndpointUri();
23
24 public void testClientSendToRemoteComponent() throws Exception
25 {
26
27 MuleClient client = new MuleClient(muleContext);
28
29 RemoteDispatcher dispatcher = client.getRemoteDispatcher(getRemoteEndpointUri());
30 MuleMessage message = dispatcher.sendToRemoteComponent("TestReceiverUMO", "Test Client Send message", null);
31 assertNotNull(message);
32 assertEquals("Test Client Send message Received", message.getPayload());
33 }
34
35 public void testClientRequestResponseOnEndpoint() throws Exception
36 {
37
38 MuleClient client = new MuleClient(muleContext);
39
40 RemoteDispatcher dispatcher = client.getRemoteDispatcher(getRemoteEndpointUri());
41 MuleMessage message = dispatcher.sendRemote("vm://remote.endpoint?connector=vmRemoteConnector", "foo",
42 null);
43 assertNotNull(message);
44 assertEquals("received from remote component", message.getPayloadAsString());
45 }
46
47
48
49
50
51
52 public void testClientSendAndReceiveRemote() throws Exception
53 {
54 String remoteEndpoint = "vm://remote.queue?connector=vmRemoteQueueConnector";
55
56 MuleClient client = new MuleClient(muleContext);
57
58 RemoteDispatcher dispatcher = client.getRemoteDispatcher(getRemoteEndpointUri());
59
60
61 MuleMessage message = dispatcher.receiveRemote(remoteEndpoint,MuleEvent.TIMEOUT_NOT_SET_VALUE);
62 assertNull(message);
63
64
65 dispatcher.sendRemote(remoteEndpoint, "Test Remote Message 2", null);
66
67
68 message = dispatcher.receiveRemote(remoteEndpoint, RECEIVE_TIMEOUT * 2);
69 assertNotNull(message);
70 assertEquals("Test Remote Message 2", message.getPayload());
71 }
72
73 }