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