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.junit4.FunctionalTestCase;
19
20 import org.junit.Test;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertNull;
25
26 public abstract class AbstractClientRemotingTestCase extends FunctionalTestCase
27 {
28
29 public abstract String getRemoteEndpointUri();
30
31 @Test
32 public void testClientSendToRemoteComponent() throws Exception
33 {
34
35 MuleClient client = new MuleClient(muleContext);
36
37 RemoteDispatcher dispatcher = client.getRemoteDispatcher(getRemoteEndpointUri());
38 MuleMessage message = dispatcher.sendToRemoteComponent("TestReceiverUMO", "Test Client Send message", null);
39 assertNotNull(message);
40 assertEquals("Test Client Send message Received", message.getPayload());
41 }
42
43 @Test
44 public void testClientRequestResponseOnEndpoint() throws Exception
45 {
46
47 MuleClient client = new MuleClient(muleContext);
48
49 RemoteDispatcher dispatcher = client.getRemoteDispatcher(getRemoteEndpointUri());
50 MuleMessage message = dispatcher.sendRemote("vm://remote.endpoint?connector=vmRemoteConnector", "foo",
51 null);
52 assertNotNull(message);
53 assertEquals("received from remote component", message.getPayloadAsString());
54 }
55
56
57
58
59
60
61 @Test
62 public void testClientSendAndReceiveRemote() throws Exception
63 {
64 String remoteEndpoint = "vm://remote.queue?connector=vmRemoteQueueConnector";
65
66 MuleClient client = new MuleClient(muleContext);
67
68 RemoteDispatcher dispatcher = client.getRemoteDispatcher(getRemoteEndpointUri());
69
70
71 MuleMessage message = dispatcher.receiveRemote(remoteEndpoint,MuleEvent.TIMEOUT_NOT_SET_VALUE);
72 assertNull(message);
73
74
75 dispatcher.sendRemote(remoteEndpoint, "Test Remote Message 2", null);
76
77
78 message = dispatcher.receiveRemote(remoteEndpoint, RECEIVE_TIMEOUT * 2);
79 assertNotNull(message);
80 assertEquals("Test Remote Message 2", message.getPayload());
81 }
82
83 }