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