View Javadoc

1   /*
2    * $Id: MessagePropertiesPropagationTestCase.java 22422 2011-07-15 08:22:16Z dirk.olmes $
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.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          // Do not fail test case upon timeout because this probably just means
37          // that the 3rd-party web service is off-line.
38          return false;
39      }
40      
41      /**
42       * If a simple call to the web service indicates that it is not responding properly,
43       * we disable the test case so as to not report a test failure which has nothing to do
44       * with Mule.
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       * As per EE-1613, the Correlation-related properties _should_ be propagated to the response message by default.
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       * As per EE-1613, the Correlation-related properties _should_ be propagated to the response message by default.
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      * As per EE-1611/MULE-4302, custom properties and non-Correlation-related properties _should not_ be propagated
103      * to the response message by default.
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      * As per EE-1611/MULE-4302, custom properties and non-Correlation-related properties _should not_ be propagated
126      * to the response message by default.
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      * Force the properties to be propagated to the response message.
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      * Force the properties to be propagated to the response message.
168      * MULE-4986
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 }