1
2
3
4
5
6
7
8
9
10 package org.mule.transport.jms.integration;
11
12 import org.hamcrest.core.Is;
13 import org.hamcrest.core.IsNull;
14 import org.junit.Test;
15 import org.junit.runners.Parameterized;
16 import org.mule.api.MuleMessage;
17 import org.mule.api.config.MuleProperties;
18 import org.mule.api.transport.PropertyScope;
19 import org.mule.module.client.MuleClient;
20 import org.mule.tck.AbstractServiceAndFlowTestCase;
21
22 import java.util.Arrays;
23 import java.util.Collection;
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import static org.hamcrest.core.Is.is;
28 import static org.junit.Assert.assertThat;
29
30 public class JmsResponseElementTestCase extends AbstractServiceAndFlowTestCase
31 {
32
33 public static final String MESSAGE = "A Message";
34 public static final String EXPECTED_MODIFIED_MESSAGE = "A Message jms flow content";
35 public static final int TIMEOUT = 3000;
36 public static final int TINY_TIMEOUT = 300;
37
38 public JmsResponseElementTestCase(ConfigVariant variant, String configResources)
39 {
40 super(variant, configResources);
41 }
42
43 @Parameterized.Parameters
44 public static Collection<Object[]> parameters()
45 {
46 return Arrays.asList(new Object[][]{
47 {ConfigVariant.SERVICE, "integration/jms-response-element-config-service.xml"},
48 {ConfigVariant.FLOW, "integration/jms-response-element-config-flow.xml"}
49 });
50 }
51
52 @Test
53 public void testOutboundEndpointResponse() throws Exception
54 {
55 MuleClient client = new MuleClient(muleContext);
56 MuleMessage response = client.send("vm://vminbound", "some message", null);
57 assertThat(response.getPayloadAsString(), is(EXPECTED_MODIFIED_MESSAGE));
58 assertThat(response.<String>getProperty("test", PropertyScope.INBOUND), Is.is("test"));
59 assertThat(response.getExceptionPayload(), IsNull.<Object>nullValue());
60 }
61
62 @Test
63 public void testInboundEndpointResponse() throws Exception
64 {
65 MuleClient client = new MuleClient(muleContext);
66 MuleMessage response = client.send("vm://vminbound2", MESSAGE, null);
67 assertThat(response.getPayloadAsString(), is(EXPECTED_MODIFIED_MESSAGE));
68 assertThat(response.getExceptionPayload(), IsNull.<Object>nullValue());
69 }
70
71 @Test
72 public void testInboundEndpointResponseWithReplyTo() throws Exception
73 {
74 MuleClient client = new MuleClient(muleContext);
75 Map messageProperties = new HashMap();
76 String replyToUri = "jms://out2";
77 messageProperties.put(MuleProperties.MULE_REPLY_TO_PROPERTY, replyToUri);
78 client.dispatch("jms://out", MESSAGE, messageProperties);
79 MuleMessage response = client.request(replyToUri, TIMEOUT);
80 assertThat(response.getPayloadAsString(), is(EXPECTED_MODIFIED_MESSAGE));
81 assertThat(response.getExceptionPayload(), IsNull.<Object>nullValue());
82 response = client.request(replyToUri, TINY_TIMEOUT);
83 assertThat(response, IsNull.<Object>nullValue());
84 }
85
86 @Test
87 public void testInboundEndpointOneWay() throws Exception
88 {
89 MuleClient client = new MuleClient(muleContext);
90 MuleMessage response = client.send("jms://in3", MESSAGE, null);
91 assertThat(response.getPayloadAsString(), is(EXPECTED_MODIFIED_MESSAGE));
92 assertThat(response.getExceptionPayload(), IsNull.<Object>nullValue());
93 }
94
95
96
97 }
98