View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.tcp;
8   
9   import org.mule.DefaultMuleMessage;
10  import org.mule.api.MuleMessage;
11  import org.mule.api.config.MuleProperties;
12  import org.mule.api.endpoint.InboundEndpoint;
13  import org.mule.module.client.MuleClient;
14  import org.mule.tck.junit4.FunctionalTestCase;
15  import org.mule.tck.junit4.rule.DynamicPort;
16  
17  import java.util.HashMap;
18  import java.util.Map;
19  
20  import org.junit.Rule;
21  import org.junit.Test;
22  
23  import static org.junit.Assert.assertEquals;
24  import static org.junit.Assert.assertNotNull;
25  
26  public class TcpRemoteSyncTestCase extends FunctionalTestCase
27  {
28  
29      public static final String message = "mule";
30  
31      @Rule
32      public DynamicPort dynamicPort1 = new DynamicPort("port1");
33  
34      @Rule
35      public DynamicPort dynamicPort2 = new DynamicPort("port2");
36  
37      @Rule
38      public DynamicPort dynamicPort3 = new DynamicPort("port3");
39  
40      @Override
41      protected String getConfigResources()
42      {
43          return "tcp-remotesync.xml";
44      }
45  
46      @Test
47      public void testTcpTcpRemoteSync() throws Exception
48      {
49          MuleClient client = new MuleClient(muleContext);
50          Map<String, Object> props = new HashMap<String, Object>();
51  
52          //must notify the client to wait for a response from the server
53          props.put(MuleProperties.MULE_REMOTE_SYNC_PROPERTY, Boolean.TRUE);
54          MuleMessage reply = client.send(((InboundEndpoint) client.getMuleContext().getRegistry().lookupObject("echoInTcp")).getAddress(),
55                                          new DefaultMuleMessage(message, muleContext), props);
56  
57          assertNotNull(reply);
58          assertNotNull(reply.getPayload());
59          assertEquals("Received: " + message, reply.getPayloadAsString());
60      }
61  
62      @Test
63      public void testTcpVmRemoteSync() throws Exception
64      {
65          MuleClient client = new MuleClient(muleContext);
66          Map<String, Object> props = new HashMap<String, Object>();
67  
68          //must notify the client to wait for a response from the server
69          props.put(MuleProperties.MULE_REMOTE_SYNC_PROPERTY, Boolean.TRUE);
70  
71          MuleMessage reply = client.send(((InboundEndpoint) client.getMuleContext().getRegistry().lookupObject("echo2InTcp")).getAddress(),
72                                          new DefaultMuleMessage(message, muleContext), props);
73  
74          assertNotNull(reply);
75          assertNotNull(reply.getPayload());
76          assertEquals("Received: " + message, reply.getPayloadAsString());
77      }
78  
79  }