View Javadoc

1   /*
2    * $Id: MessagePropertiesPropagationTestCase.java 19386 2010-09-06 21:57:44Z mike.schilling $
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.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  public class MessagePropertiesPropagationTestCase extends FunctionalTestCase
24  {
25      public MessagePropertiesPropagationTestCase()
26      {
27          super();
28          
29          // Do not fail test case upon timeout because this probably just means
30          // that the 3rd-party web service is off-line.
31          setFailOnTimeout(false);
32      }
33      
34      /**
35       * If a simple call to the web service indicates that it is not responding properly,
36       * we disable the test case so as to not report a test failure which has nothing to do
37       * with Mule.
38       */
39      @Override
40      protected boolean isDisabledInThisEnvironment()
41      {
42          return !WebServiceOnlineCheck.isWebServiceOnline();
43      }
44  
45      @Override
46      protected String getConfigResources()
47      {
48          return "org/mule/test/integration/messaging/meps/message-properties-propagation.xml";
49      }
50  
51      /**
52       * As per EE-1613, the Correlation-related properties _should_ be propagated to the response message by default.
53       */
54      public void testPropagatedPropertiesWithHttpTransport() throws Exception
55      {
56          MuleClient client = new MuleClient(muleContext);
57          
58          Map<String, Object> props = new HashMap<String, Object>();
59          props.put("Content-Type", "application/x-www-form-urlencoded");
60          props.put(MuleProperties.MULE_CORRELATION_ID_PROPERTY, "TestID");
61          props.put(MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY, "TestGroupSize");
62          props.put(MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY, "TestSequence");
63          
64          MuleMessage response = client.send("vm://httpService1", "symbol=IBM", props);
65          assertNotNull(response);
66          assertTrue(response.getPayloadAsString().contains("PreviousClose"));
67          assertEquals("TestID", response.getOutboundProperty(MuleProperties.MULE_CORRELATION_ID_PROPERTY));
68          assertEquals("TestGroupSize", response.getOutboundProperty(MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY));
69          assertEquals("TestSequence", response.getOutboundProperty(MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY));
70      }
71  
72      /**
73       * As per EE-1613, the Correlation-related properties _should_ be propagated to the response message by default.
74       */
75      public void testPropagatedPropertiesWithCxfTransport() throws Exception
76      {
77          MuleClient client = new MuleClient(muleContext);
78  
79          Map<String, Object> props = new HashMap<String, Object>();
80          props.put(MuleProperties.MULE_CORRELATION_ID_PROPERTY, "TestID");
81          props.put(MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY, "TestGroupSize");
82          props.put(MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY, "TestSequence");
83  
84          MuleMessage response = client.send("vm://cxfService1", "IBM", props);
85          assertNotNull(response);
86          assertTrue(response.getPayloadAsString().contains("PreviousClose"));
87          assertEquals("TestID", response.getOutboundProperty(MuleProperties.MULE_CORRELATION_ID_PROPERTY));
88          assertEquals("TestGroupSize", response.getOutboundProperty(MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY));
89          assertEquals("TestSequence", response.getOutboundProperty(MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY));
90      }
91  
92      /**
93       * As per EE-1611/MULE-4302, custom properties and non-Correlation-related properties _should not_ be propagated
94       * to the response message by default.
95       */
96      public void testNotPropagatedPropertiesWithHttpTransport() throws Exception
97      {
98          MuleClient client = new MuleClient(muleContext);
99  
100         Map<String, Object> props = new HashMap<String, Object>();
101         props.put("Content-Type", "application/x-www-form-urlencoded");
102         props.put("some", "thing");
103         props.put("other", "stuff");
104         props.put(HttpConstants.HEADER_CONTENT_TYPE, "text/bizarre;charset=utf-16");
105 
106         MuleMessage response = client.send("vm://httpService1", "symbol=IBM", props);
107         assertNotNull(response);
108         assertNull(response.getInboundProperty("some"));
109         assertNull(response.getInboundProperty("other"));
110         assertEquals("text/plain; charset=utf-8", response.getInboundProperty(HttpConstants.HEADER_CONTENT_TYPE));
111         assertEquals("utf-8", response.getEncoding());
112     }
113 
114     /**
115      * As per EE-1611/MULE-4302, custom properties and non-Correlation-related properties _should not_ be propagated
116      * to the response message by default.
117      */
118     public void testNotPropagatedPropertiesWithCxfTransport() throws Exception
119     {
120         MuleClient client = new MuleClient(muleContext);
121 
122         Map<String, Object> props = new HashMap<String, Object>();
123         props.put("some", "thing");
124         props.put("other", "stuff");
125         props.put(HttpConstants.HEADER_CONTENT_TYPE, "text/bizarre;charset=utf-16");
126 
127         MuleMessage response = client.send("vm://cxfService1", "IBM", props);
128         assertNotNull(response);
129         assertNull(response.getInboundProperty("some"));
130         assertNull(response.getInboundProperty("other"));
131         assertEquals("text/xml; charset=utf-8", response.getInboundProperty(HttpConstants.HEADER_CONTENT_TYPE));
132         assertEquals("utf-8", response.getEncoding());
133     }
134 
135     /**
136      * Force the properties to be propagated to the response message.
137      */
138     public void testForcePropagatedPropertiesWithHttpTransport() throws Exception
139     {
140         MuleClient client = new MuleClient(muleContext);
141 
142         Map<String, Object> props = new HashMap<String, Object>();
143         props.put("Content-Type", "application/x-www-form-urlencoded");
144         props.put("some", "thing");
145         props.put("other", "stuff");
146 
147         MuleMessage response = client.send("vm://httpService2", "symbol=IBM", props);
148         assertNotNull(response);
149         assertTrue(response.getPayloadAsString().contains("PreviousClose"));
150         assertEquals("thing", response.getInboundProperty("some"));
151         assertEquals("stuff", response.getInboundProperty("other"));
152     }
153 
154     /**
155      * Force the properties to be propagated to the response message.
156      * MULE-4986
157      */
158     public void xtestForcePropagatedPropertiesWithCxfTransport() throws Exception
159     {
160         MuleClient client = new MuleClient(muleContext);
161 
162         Map<String, Object> props = new HashMap<String, Object>();
163         props.put("some", "thing");
164         props.put("other", "stuff");
165 
166         MuleMessage response = client.send("vm://cxfService2", "symbol=IBM", props);
167         assertNotNull(response);
168         assertTrue(response.getPayloadAsString().contains("PreviousClose"));
169         assertEquals("thing", response.getOutboundProperty("some"));
170         assertEquals("stuff", response.getOutboundProperty("other"));
171     }
172 }