1   /*
2    * $Id: AbstractClientRemotingTestCase.java 11371 2008-03-15 03:12:09Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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  
11  package org.mule.test.integration.client;
12  
13  
14  import org.mule.api.MuleMessage;
15  import org.mule.module.client.MuleClient;
16  import org.mule.module.client.RemoteDispatcher;
17  import org.mule.tck.FunctionalTestCase;
18  
19  public abstract class AbstractClientRemotingTestCase extends FunctionalTestCase
20  {
21      public abstract String getRemoteEndpointUri();
22  
23      public void testClientSendToRemoteComponent() throws Exception
24      {
25          // Will connect to the server using remote endpoint
26          MuleClient client = new MuleClient();
27   
28          RemoteDispatcher dispatcher = client.getRemoteDispatcher(getRemoteEndpointUri());
29          MuleMessage message = dispatcher.sendToRemoteComponent("TestReceiverUMO", "Test Client Send message", null);
30          assertNotNull(message);
31          assertEquals("Test Client Send message Received", message.getPayload());
32      }
33  
34      public void testClientRequestResponseOnEndpoint() throws Exception
35      {
36          // Will connect to the server using tcp://localhost:60504
37          MuleClient client = new MuleClient();
38   
39          RemoteDispatcher dispatcher = client.getRemoteDispatcher(getRemoteEndpointUri());
40          MuleMessage message = dispatcher.sendRemote("vm://remote.endpoint?connector=vmRemoteConnector", "foo",
41                  null);
42          assertNotNull(message);
43          assertEquals("received from remote component", message.getPayloadAsString());
44      }
45  
46      /**
47       * A test that writes a message to a remote queue
48       *
49       * @throws Exception
50       */
51      public void testClientSendAndReceiveRemote() throws Exception
52      {
53          String remoteEndpoint = "vm://remote.queue?connector=vmRemoteQueueConnector";
54          // Will connect to the server using The Server endpoint
55          MuleClient client = new MuleClient();
56  
57          RemoteDispatcher dispatcher = client.getRemoteDispatcher(getRemoteEndpointUri());
58          // Doubling timeout see MULE-3000
59          MuleMessage message = dispatcher.receiveRemote(remoteEndpoint, RECEIVE_TIMEOUT * 2);
60          assertNull(message);
61          // We do a send instead of a dispatch here so the operation is
62          // synchronous thus eaiser to test
63          dispatcher.sendRemote(remoteEndpoint, "Test Remote Message 2", null);
64  
65          // Doubling timeout see MULE-3000
66          message = dispatcher.receiveRemote(remoteEndpoint, RECEIVE_TIMEOUT * 2);
67          assertNotNull(message);
68          assertEquals("Test Remote Message 2", message.getPayload());
69      }
70      
71  }