View Javadoc

1   /*
2    * $Id: AbstractClientRemotingTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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  
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.FunctionalTestCase;
19  
20  public abstract class AbstractClientRemotingTestCase extends FunctionalTestCase
21  {
22      public abstract String getRemoteEndpointUri();
23  
24      public void testClientSendToRemoteComponent() throws Exception
25      {
26          // Will connect to the server using remote endpoint
27          MuleClient client = new MuleClient(muleContext);
28   
29          RemoteDispatcher dispatcher = client.getRemoteDispatcher(getRemoteEndpointUri());
30          MuleMessage message = dispatcher.sendToRemoteComponent("TestReceiverUMO", "Test Client Send message", null);
31          assertNotNull(message);
32          assertEquals("Test Client Send message Received", message.getPayload());
33      }
34  
35      public void testClientRequestResponseOnEndpoint() throws Exception
36      {
37          // Will connect to the server using tcp://localhost:60504
38          MuleClient client = new MuleClient(muleContext);
39   
40          RemoteDispatcher dispatcher = client.getRemoteDispatcher(getRemoteEndpointUri());
41          MuleMessage message = dispatcher.sendRemote("vm://remote.endpoint?connector=vmRemoteConnector", "foo",
42                  null);
43          assertNotNull(message);
44          assertEquals("received from remote component", message.getPayloadAsString());
45      }
46  
47      /**
48       * A test that writes a message to a remote queue
49       *
50       * @throws Exception
51       */
52      public void testClientSendAndReceiveRemote() throws Exception
53      {
54          String remoteEndpoint = "vm://remote.queue?connector=vmRemoteQueueConnector";
55          // Will connect to the server using The Server endpoint
56          MuleClient client = new MuleClient(muleContext);
57  
58          RemoteDispatcher dispatcher = client.getRemoteDispatcher(getRemoteEndpointUri());
59          // Doubling timeout see MULE-3000
60          // Use TIMEOUT_NOT_SET_VALUE as we need respective remoteDispatcherEndpoint to you timeout as defined on the endpoint.  
61          MuleMessage message = dispatcher.receiveRemote(remoteEndpoint,MuleEvent.TIMEOUT_NOT_SET_VALUE);
62          assertNull(message);
63          // We do a send instead of a dispatch here so the operation is
64          // synchronous thus eaiser to test
65          dispatcher.sendRemote(remoteEndpoint, "Test Remote Message 2", null);
66  
67          // Doubling timeout see MULE-3000
68          message = dispatcher.receiveRemote(remoteEndpoint, RECEIVE_TIMEOUT * 2);
69          assertNotNull(message);
70          assertEquals("Test Remote Message 2", message.getPayload());
71      }
72      
73  }