View Javadoc

1   /*
2    * $Id: MuleClientJmsTestCase.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  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.FunctionalTestCase;
16  import org.mule.transport.jms.JmsConstants;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  public class MuleClientJmsTestCase extends FunctionalTestCase
22  {
23      public static final int INTERATIONS = 1;
24  
25      protected String getConfigResources()
26      {
27          return "org/mule/test/integration/client/test-client-jms-mule-config.xml";
28      }
29  
30      public void testClientSendDirect() throws Exception
31      {
32          MuleClient client = new MuleClient(muleContext);
33  
34          MuleMessage message = client.sendDirect("TestReceiverUMO", null, "Test Client Send message", null);
35          assertNotNull(message);
36          assertEquals("Received: Test Client Send message", message.getPayload());
37      }
38  
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      public void testClientSend() throws Exception
47      {
48          MuleClient client = new MuleClient(muleContext);
49  
50          MuleMessage message = client.send(getDispatchUrl(), "Test Client Send message", null);
51          assertNotNull(message);
52          assertEquals("Received: Test Client Send message", message.getPayload());
53      }
54  
55      public void testClientMultiSend() throws Exception
56      {
57          MuleClient client = new MuleClient(muleContext);
58  
59          for (int i = 0; i < INTERATIONS; i++)
60          {
61              MuleMessage message = client.send(getDispatchUrl(), "Test Client Send message " + i, null);
62              assertNotNull(message);
63              assertEquals("Received: Test Client Send message " + i, message.getPayload());
64          }
65      }
66  
67      public void testClientMultiDispatch() throws Exception
68      {
69          MuleClient client = new MuleClient(muleContext);
70  
71          int i = 0;
72          // to init
73          client.dispatch(getDispatchUrl(), "Test Client Send message " + i, null);
74          long start = System.currentTimeMillis();
75          for (i = 0; i < INTERATIONS; i++)
76          {
77              client.dispatch(getDispatchUrl(), "Test Client Send message " + i, null);
78          }
79          long time = System.currentTimeMillis() - start;
80          logger.debug(i + " took " + time + "ms to process");
81          Thread.sleep(1000);
82      }
83  
84      public void testClientDispatchAndReceiveOnReplyTo() throws Exception
85      {
86          MuleClient client = new MuleClient(muleContext);
87  
88          Map props = new HashMap();
89          props.put(JmsConstants.JMS_REPLY_TO, "replyTo.queue");
90  
91          long start = System.currentTimeMillis();
92          int i = 0;
93          for (i = 0; i < INTERATIONS; i++)
94          {
95              logger.debug("Sending message " + i);
96              client.dispatch(getDispatchUrl(), "Test Client Dispatch message " + i, props);
97          }
98          long time = System.currentTimeMillis() - start;
99          logger.debug("It took " + time + " ms to send " + i + " messages");
100 
101         Thread.sleep(5000);
102         start = System.currentTimeMillis();
103         for (i = 0; i < INTERATIONS; i++)
104         {
105             MuleMessage message = client.request("jms://replyTo.queue", 5000);
106             assertNotNull("message should not be null from Reply queue", message);
107             logger.debug("Count is " + i);
108             logger.debug("ReplyTo Message is: " + message.getPayloadAsString());
109             assertTrue(message.getPayloadAsString().startsWith("Received"));
110         }
111         time = System.currentTimeMillis() - start;
112         logger.debug("It took " + time + "ms to receive " + i + " messages");
113     }
114 
115     public String getDispatchUrl()
116     {
117         return "jms://test.queue";
118     }
119 }