View Javadoc

1   /*
2    * $Id: TcpRemoteSyncTestCase.java 19840 2010-10-05 18:32:45Z dzapata $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  package org.mule.transport.tcp;
11  
12  import org.mule.DefaultMuleMessage;
13  import org.mule.api.MuleMessage;
14  import org.mule.api.config.MuleProperties;
15  import org.mule.api.endpoint.InboundEndpoint;
16  import org.mule.module.client.MuleClient;
17  import org.mule.tck.DynamicPortTestCase;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  public class TcpRemoteSyncTestCase extends DynamicPortTestCase
23  {
24     
25     public static final String message = "mule";
26     
27     protected String getConfigResources() 
28     {
29         return "tcp-remotesync.xml";
30     }
31     
32     public void testTcpTcpRemoteSync() throws Exception
33     {
34         MuleClient client = new MuleClient(muleContext);
35         Map<String, Object> props = new HashMap<String, Object>();
36         
37         //must notify the client to wait for a response from the server
38         props.put(MuleProperties.MULE_REMOTE_SYNC_PROPERTY, Boolean.TRUE);
39         MuleMessage reply = client.send(((InboundEndpoint) client.getMuleContext().getRegistry().lookupObject("echoInTcp")).getAddress(),
40             new DefaultMuleMessage(message, muleContext), props);
41  
42         assertNotNull(reply);
43         assertNotNull(reply.getPayload());
44         assertEquals("Received: " + message, reply.getPayloadAsString());
45     }
46      
47      public void testTcpVmRemoteSync() 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          
55          MuleMessage reply = client.send(((InboundEndpoint) client.getMuleContext().getRegistry().lookupObject("echo2InTcp")).getAddress(), 
56              new DefaultMuleMessage(message, muleContext), props);
57  
58          assertNotNull(reply);
59          assertNotNull(reply.getPayload());
60          assertEquals("Received: " + message, reply.getPayloadAsString());
61      }
62  
63      @Override
64      protected int getNumPortsToFind()
65      {
66          return 3;
67      }
68  }