1   /*
2    * $Id: MuleClientTestCase.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.tck.FunctionalTestCase;
17  
18  public class MuleClientTestCase extends FunctionalTestCase
19  {
20  
21      protected String getConfigResources()
22      {
23          return "org/mule/test/integration/client/test-client-mule-config.xml";
24      }
25  
26      public void testClientSendDirect() throws Exception
27      {
28          MuleClient client = new MuleClient();
29  
30          MuleMessage message = client.sendDirect("TestReceiverUMO", null, "Test Client Send message", null);
31          assertNotNull(message);
32          assertEquals("Test Client Send message Received", message.getPayload());
33      }
34  
35      public void testClientDispatchDirect() throws Exception
36      {
37          MuleClient client = new MuleClient();
38  
39          client.dispatchDirect("TestReceiverUMO", "Test Client dispatch message", null);
40      }
41  
42      public void testClientSendGlobalEndpoint() throws Exception
43      {
44          MuleClient client = new MuleClient();
45  
46          MuleMessage message = client.send("vmEndpoint", "Test Client Send message", null);
47          assertNotNull(message);
48          assertEquals("Test Client Send message Received", message.getPayload());
49      }
50  
51      public void testClientSend() throws Exception
52      {
53          MuleClient client = new MuleClient();
54  
55          MuleMessage message = client.send(getDispatchUrl(), "Test Client Send message", null);
56          assertNotNull(message);
57          assertEquals("Test Client Send message Received", message.getPayload());
58      }
59  
60      public void testClientMultiSend() throws Exception
61      {
62          MuleClient client = new MuleClient();
63  
64          for (int i = 0; i < 100; i++)
65          {
66              MuleMessage message = client.send(getDispatchUrl(), "Test Client Send message " + i, null);
67              assertNotNull(message);
68              assertEquals("Test Client Send message " + i + " Received", message.getPayload());
69          }
70      }
71  
72      public void testClientMultidispatch() throws Exception
73      {
74          MuleClient client = new MuleClient();
75  
76          int i = 0;
77          // to init
78          client.dispatch(getDispatchUrl(), "Test Client Send message " + i, null);
79          long start = System.currentTimeMillis();
80          for (i = 0; i < 100; i++)
81          {
82              client.dispatch(getDispatchUrl(), "Test Client Send message " + i, null);
83          }
84          long time = System.currentTimeMillis() - start;
85          logger.debug(i + " took " + time + "ms to process");
86          Thread.sleep(1000);
87      }
88  
89      public String getDispatchUrl()
90      {
91          return "vm://test.queue";
92      }
93  }