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.properties;
8   
9   import static org.junit.Assert.assertEquals;
10  
11  import org.mule.DefaultMuleEvent;
12  import org.mule.DefaultMuleMessage;
13  import org.mule.api.MuleEvent;
14  import org.mule.api.MuleMessage;
15  import org.mule.api.transport.PropertyScope;
16  import org.mule.construct.SimpleFlowConstruct;
17  import org.mule.tck.functional.FlowAssert;
18  import org.mule.tck.junit4.rule.DynamicPort;
19  import org.mule.tck.testmodels.fruit.Apple;
20  import org.mule.tck.testmodels.fruit.Banana;
21  import org.mule.tck.testmodels.fruit.Fruit;
22  import org.mule.tck.testmodels.fruit.Orange;
23  
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  import org.junit.After;
28  import org.junit.Rule;
29  import org.junit.Test;
30  
31  public class InvocationPropertiesTestCase extends org.mule.tck.junit4.FunctionalTestCase
32  {
33  
34      @Rule
35      public DynamicPort dynamicPort = new DynamicPort("port1");
36  
37      @Rule
38      public DynamicPort dynamicPort2 = new DynamicPort("port2");
39  
40      @After
41      public void clearFlowAssertions()
42      {
43          FlowAssert.reset();
44      }
45  
46      @Test
47      public void setInvocationPropertyUsingAPIGetInFlow() throws Exception
48      {
49          MuleMessage message = new DefaultMuleMessage("data", muleContext);
50          MuleEvent event = new DefaultMuleEvent(message, getTestInboundEndpoint(""), getTestSession(
51              getTestService(), muleContext));
52  
53          message.setProperty("P1", "P1_VALUE", PropertyScope.INVOCATION);
54  
55          testFlow("GetInvocationPropertyInFlow", event);
56      }
57  
58      @Test
59      public void setInvocationPropertyInFlowGetUsingAPI() throws Exception
60      {
61          MuleMessage message = new DefaultMuleMessage("data", muleContext);
62          MuleEvent event = new DefaultMuleEvent(message, getTestInboundEndpoint(""), getTestSession(
63              getTestService(), muleContext));
64  
65          SimpleFlowConstruct flowA = (SimpleFlowConstruct) muleContext.getRegistry().lookupFlowConstruct(
66              "SetInvocationPropertyInFlow");
67          MuleEvent result = flowA.process(event);
68  
69          assertEquals("P1_VALUE", result.getMessage().getProperty("P1", PropertyScope.INVOCATION));
70      }
71  
72      @Test
73      public void overwritePropertyValueInFlow() throws Exception
74      {
75          MuleMessage message = new DefaultMuleMessage("data", muleContext);
76          MuleEvent event = new DefaultMuleEvent(message, getTestInboundEndpoint(""), getTestSession(
77              getTestService(), muleContext));
78  
79          message.setProperty("P1", "P1_VALUE", PropertyScope.INVOCATION);
80  
81          testFlow("OverwritePropertyValueInFlow", event);
82  
83          assertEquals("P1_VALUE_NEW", event.getMessage().getProperty("P1", PropertyScope.INVOCATION));
84      }
85  
86      @Test
87      public void propagationInSameFlow() throws Exception
88      {
89          testFlow("propagationInSameFlow");
90      }
91  
92      @Test
93      public void noPropagationInDifferentFlowVMRequestResponse() throws Exception
94      {
95          testFlow("noPropagationInDifferentFlowVMRequestResponse");
96          FlowAssert.verify("noPropagationInDifferentFlowVMRequestResponse-2");
97      }
98  
99      @Test
100     public void noPropagationInDifferentFlowVMOneWay() throws Exception
101     {
102         testFlow("noPropagationInDifferentFlowVMOneWay");
103         FlowAssert.verify("noPropagationInDifferentFlowVMOneWay-2");
104     }
105 
106     @Test
107     public void noPropagationInDifferentFlowHttp() throws Exception
108     {
109         testFlow("noPropagationInDifferentFlowHttp");
110         FlowAssert.verify("noPropagationInDifferentFlowHttp-2");
111     }
112 
113     @Test
114     public void propagationThroughOneWayFlowSedaQueue() throws Exception
115     {
116         MuleMessage message = new DefaultMuleMessage("data", muleContext);
117 
118         muleContext.getClient().dispatch("vm://AsyncFlow", message);
119 
120         FlowAssert.verify("AsyncFlow");
121     }
122 
123     @Test
124     public void propagationWithVMRequestResponseOutboundEndpointMidFlow() throws Exception
125     {
126         testFlow("VMRequestResponseEndpointFlowMidFlow");
127     }
128 
129     @Test
130     public void propagationWithHTTPRequestResponseOutboundEndpointMidFlow() throws Exception
131     {
132         testFlow("HTTPRequestResponseEndpointFlowMidFlow");
133     }
134 
135     @Test
136     public void propagationThroughFlowRefToFlow() throws Exception
137     {
138         testFlow("propagationThroughFlowRefToFlow");
139         FlowAssert.verify("FlowRef-1");
140         FlowAssert.verify("FlowRef-2");
141         FlowAssert.verify("FlowRef-3");
142     }
143 
144     @Test
145     public void overwritePropertyValueInFlowViaFlowRef() throws Exception
146     {
147         testFlow("OverwriteInFlowRef");
148     }
149 
150     @Test
151     public void propagationThroughFlowRefToSubFlow() throws Exception
152     {
153         testFlow("propagationThroughFlowRefToSubFlow");
154     }
155 
156     @Test
157     public void overwritePropertyValueInSubFlowViaFlowRef() throws Exception
158     {
159         testFlow("OverwriteInSubFlowRef");
160     }
161 
162     @Test
163     public void propagationThroughAsyncElement() throws Exception
164     {
165         testFlow("propagationThroughAsyncElement");
166     }
167 
168     @Test
169     public void propertyAddedInAsyncElementNotAddedinFlow() throws Exception
170     {
171         testFlow("propertyAddedInAsyncElementNotAddedinFlow");
172     }
173 
174     @Test
175     public void propagationThroughWireTap() throws Exception
176     {
177         testFlow("propagationThroughWireTap");
178     }
179 
180     @Test
181     public void propertyAddedInWireTapNotAddedinFlow() throws Exception
182     {
183         testFlow("propertyAddedInWireTapNotAddedinFlow");
184     }
185 
186     @Test
187     public void propagationThroughEnricher() throws Exception
188     {
189         testFlow("propagationThroughEnricher");
190     }
191 
192     @Test
193     public void propertyAddedInEnricherNotAddedinFlow() throws Exception
194     {
195         testFlow("propertyAddedInEnricherNotAddedinFlow");
196     }
197 
198     @Test
199     public void propagateToRoutesInAll() throws Exception
200     {
201         testFlow("propagateToRoutesInAll");
202     }
203 
204     @Test
205     public void propagateThroughAllRouterWithResults() throws Exception
206     {
207         testFlow("propagateThroughAllRouterWithResults");
208     }
209 
210     @Test
211     public void propagateThroughAllRouterWithNoResults() throws Exception
212     {
213         testFlow("propagateThroughAllRouterWithNoResults");
214     }
215 
216     @Test
217     public void noPropagateBetweenRoutes() throws Exception
218     {
219         testFlow("noPropagateBetweenRoutes");
220     }
221 
222     @Test
223     public void noPropagateFromRouteToNextProcessorSingleRoute() throws Exception
224     {
225         testFlow("noPropagateFromRouteToNextProcessorSingleRoute");
226     }
227 
228     @Test
229     public void noPropagateFromRouteToNextProcessorMultipleRoutes() throws Exception
230     {
231         testFlow("noPropagateFromRouteToNextProcessorMultipleRoutes");
232     }
233 
234     @Test
235     public void noPropagateFromRouteToNextProcessorNoResult() throws Exception
236     {
237         testFlow("noPropagateFromRouteToNextProcessorNoResult");
238     }
239 
240     @Test
241     public void allAsync() throws Exception
242     {
243         testFlow("AllAsync");
244     }
245 
246     @Test
247     public void propogationOfPropertiesInMessageSplitWithSplitter() throws Exception
248     {
249         List<Fruit> fruitList = new ArrayList<Fruit>();
250         fruitList.add(new Apple());
251         fruitList.add(new Orange());
252         fruitList.add(new Banana());
253         testFlow("propogationOfPropertiesInMessageSplitWithSplitter", getTestEvent(fruitList));
254     }
255 
256     @Test
257     public void aggregationOfPropertiesFromMultipleMessageWithAggregator() throws Exception
258     {
259         List<Fruit> fruitList = new ArrayList<Fruit>();
260         fruitList.add(new Apple());
261         fruitList.add(new Orange());
262         fruitList.add(new Banana());
263         testFlow("aggregationOfPropertiesFromMultipleMessageWithAggregator", getTestEvent(fruitList));
264         FlowAssert.verify("Split");
265     }
266     
267     @Test
268     public void defaultExceptionStrategy() throws Exception
269     {
270         testFlow("defaultExceptionStrategy");
271     }
272 
273     @Override
274     protected String getConfigResources()
275     {
276         return "org/mule/properties/invocation-properties-config.xml";
277     }
278 
279 }