1
2
3
4
5
6
7
8
9
10
11 package org.mule.test.integration.messaging.meps;
12
13 import org.mule.api.MuleMessage;
14 import org.mule.api.config.MuleProperties;
15 import org.mule.module.client.MuleClient;
16 import org.mule.tck.junit4.FunctionalTestCase;
17 import org.mule.tck.util.WebServiceOnlineCheck;
18 import org.mule.transport.http.HttpConstants;
19
20 import java.util.HashMap;
21 import java.util.Map;
22
23 import org.junit.Test;
24
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertNull;
28 import static org.junit.Assert.assertTrue;
29
30 public class MessagePropertiesPropagationTestCase extends FunctionalTestCase
31 {
32
33 @Override
34 protected boolean isFailOnTimeout()
35 {
36
37
38 return false;
39 }
40
41
42
43
44
45
46 @Override
47 protected boolean isDisabledInThisEnvironment()
48 {
49 return !WebServiceOnlineCheck.isWebServiceOnline();
50 }
51
52 @Override
53 protected String getConfigResources()
54 {
55 return "org/mule/test/integration/messaging/meps/message-properties-propagation.xml";
56 }
57
58
59
60
61 @Test
62 public void testPropagatedPropertiesWithHttpTransport() throws Exception
63 {
64 MuleClient client = new MuleClient(muleContext);
65
66 Map<String, Object> props = new HashMap<String, Object>();
67 props.put("Content-Type", "application/x-www-form-urlencoded");
68 props.put(MuleProperties.MULE_CORRELATION_ID_PROPERTY, "TestID");
69 props.put(MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY, "TestGroupSize");
70 props.put(MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY, "TestSequence");
71
72 MuleMessage response = client.send("vm://httpService1", "symbol=IBM", props);
73 assertNotNull(response);
74 checkPayLoad(response.getPayloadAsString());
75 assertEquals("TestID", response.getOutboundProperty(MuleProperties.MULE_CORRELATION_ID_PROPERTY));
76 assertEquals("TestGroupSize", response.getOutboundProperty(MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY));
77 assertEquals("TestSequence", response.getOutboundProperty(MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY));
78 }
79
80
81
82
83 @Test
84 public void testPropagatedPropertiesWithCxfTransport() throws Exception
85 {
86 MuleClient client = new MuleClient(muleContext);
87
88 Map<String, Object> props = new HashMap<String, Object>();
89 props.put(MuleProperties.MULE_CORRELATION_ID_PROPERTY, "TestID");
90 props.put(MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY, "TestGroupSize");
91 props.put(MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY, "TestSequence");
92
93 MuleMessage response = client.send("vm://cxfService1", "IBM", props);
94 assertNotNull(response);
95 checkPayLoad(response.getPayloadAsString());
96 assertEquals("TestID", response.getOutboundProperty(MuleProperties.MULE_CORRELATION_ID_PROPERTY));
97 assertEquals("TestGroupSize", response.getOutboundProperty(MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY));
98 assertEquals("TestSequence", response.getOutboundProperty(MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY));
99 }
100
101
102
103
104
105 @Test
106 public void testNotPropagatedPropertiesWithHttpTransport() throws Exception
107 {
108 MuleClient client = new MuleClient(muleContext);
109
110 Map<String, Object> props = new HashMap<String, Object>();
111 props.put("Content-Type", "application/x-www-form-urlencoded");
112 props.put("some", "thing");
113 props.put("other", "stuff");
114 props.put(HttpConstants.HEADER_CONTENT_TYPE, "text/bizarre;charset=utf-16");
115
116 MuleMessage response = client.send("vm://httpService1", "symbol=IBM", props);
117 assertNotNull(response);
118 assertNull(response.getInboundProperty("some"));
119 assertNull(response.getInboundProperty("other"));
120 assertEquals("text/plain; charset=utf-8", response.getInboundProperty(HttpConstants.HEADER_CONTENT_TYPE));
121 assertEquals("utf-8", response.getEncoding());
122 }
123
124
125
126
127
128 @Test
129 public void testNotPropagatedPropertiesWithCxfTransport() throws Exception
130 {
131 MuleClient client = new MuleClient(muleContext);
132
133 Map<String, Object> props = new HashMap<String, Object>();
134 props.put("some", "thing");
135 props.put("other", "stuff");
136 props.put(HttpConstants.HEADER_CONTENT_TYPE, "text/bizarre;charset=utf-16");
137
138 MuleMessage response = client.send("vm://cxfService1", "IBM", props);
139 assertNotNull(response);
140 assertNull(response.getInboundProperty("some"));
141 assertNull(response.getInboundProperty("other"));
142 assertEquals("text/xml; charset=utf-8", response.getInboundProperty(HttpConstants.HEADER_CONTENT_TYPE));
143 assertEquals("utf-8", response.getEncoding());
144 }
145
146
147
148
149 @Test
150 public void testForcePropagatedPropertiesWithHttpTransport() throws Exception
151 {
152 MuleClient client = new MuleClient(muleContext);
153
154 Map<String, Object> props = new HashMap<String, Object>();
155 props.put("Content-Type", "application/x-www-form-urlencoded");
156 props.put("some", "thing");
157 props.put("other", "stuff");
158
159 MuleMessage response = client.send("vm://httpService2", "symbol=IBM", props);
160 assertNotNull(response);
161 checkPayLoad(response.getPayloadAsString());
162 assertEquals("thing", response.getInboundProperty("some"));
163 assertEquals("stuff", response.getInboundProperty("other"));
164 }
165
166
167
168
169
170 public void xtestForcePropagatedPropertiesWithCxfTransport() throws Exception
171 {
172 MuleClient client = new MuleClient(muleContext);
173
174 Map<String, Object> props = new HashMap<String, Object>();
175 props.put("some", "thing");
176 props.put("other", "stuff");
177
178 MuleMessage response = client.send("vm://cxfService2", "symbol=IBM", props);
179 assertNotNull(response);
180 checkPayLoad(response.getPayloadAsString());
181 assertEquals("thing", response.getOutboundProperty("some"));
182 assertEquals("stuff", response.getOutboundProperty("other"));
183 }
184
185 private void checkPayLoad(String payload)
186 {
187 assertNotNull("payload is null", payload);
188 assertTrue("payload does not contain 'PreviousClose': " + payload, payload.contains("PreviousClose"));
189 }
190 }