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.transport.jms.integration;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.module.client.MuleClient;
11  import org.mule.transport.NullPayload;
12  import org.mule.transport.jms.JmsConstants;
13  import org.mule.util.StringUtils;
14  
15  import org.junit.Test;
16  
17  import static org.junit.Assert.assertNotNull;
18  import static org.junit.Assert.assertTrue;
19  
20  
21  /**
22   * @see EE-1688/MULE-3059
23   */
24  public class JmsSynchronousResponseTestCase extends AbstractJmsFunctionalTestCase
25  {
26      
27      @Override
28      protected String getConfigResources()
29      {
30          return "integration/jms-synchronous-response.xml";
31      }
32  
33      @Test
34      public void testResponseWithoutReplyTo() throws Exception
35      {
36          MuleClient client = new MuleClient(muleContext);
37          
38          MuleMessage response = client.send("out1", "TEST_MESSAGE", null);
39          assertNotNull(response);
40          assertTrue("Response is not a JMS Message", response.getPayload() instanceof javax.jms.Message);
41          assertJmsMessageIdPresent(response);
42      }
43  
44      @Test
45      public void testResponseWithoutReplyToEndpointProperties() throws Exception
46      {
47          MuleClient client = new MuleClient(muleContext);
48          
49          MuleMessage response = client.send("out2", "TEST_MESSAGE", null);
50          assertNotNull(response);
51          assertTrue("Response is not a JMS Message", response.getPayload() instanceof javax.jms.Message);
52          assertJmsMessageIdPresent(response);
53      }
54  
55      @Test
56      public void testResponseWithReplyTo() throws Exception
57      {
58          MuleClient client = new MuleClient(muleContext);
59          
60          MuleMessage response = client.send("out3", "TEST_MESSAGE", null);
61          assertNotNull(response);
62          assertTrue("Response should be NullPayload", response.getPayload() instanceof NullPayload);
63      }
64  
65      private void assertJmsMessageIdPresent(MuleMessage message)
66      {
67          String messageId = message.getInboundProperty(JmsConstants.JMS_MESSAGE_ID);
68          assertTrue("JMSMessageID is missing", StringUtils.isNotBlank(messageId));
69      }
70  }