View Javadoc

1   /*
2    * $Id: PropertyScopesTestCase.java 19381 2010-09-06 19:12:46Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.transport.vm.functional;
12  
13  import org.mule.DefaultMuleMessage;
14  import org.mule.api.MuleMessage;
15  import org.mule.api.client.MuleClient;
16  import org.mule.api.transport.PropertyScope;
17  import org.mule.tck.FunctionalTestCase;
18  
19  /**
20   * Test the propagation of a property in different scopes and in synchronous vs. asynchronous flows.
21   */
22  public class PropertyScopesTestCase extends FunctionalTestCase
23  {
24      @Override
25      protected String getConfigResources()
26      {
27          return "vm/property-scopes.xml";
28      }
29      
30      public void testInboundScopeSynchronous() throws Exception
31      {
32          MuleClient client = muleContext.getClient();
33          MuleMessage message = new DefaultMuleMessage(TEST_MESSAGE, muleContext);
34          message.setProperty("foo", "bar", PropertyScope.INBOUND);
35          
36          MuleMessage response = client.send("vm://in-synch", message);
37          assertNotNull(response);
38          assertNull("Property should not have been propogated for this scope", response.getProperty("foo", PropertyScope.INBOUND));
39      }
40  
41      public void testOutboundScopeSynchronous() throws Exception
42      {
43          MuleClient client = muleContext.getClient();
44          MuleMessage message = new DefaultMuleMessage(TEST_MESSAGE, muleContext);
45          message.setProperty("foo", "bar", PropertyScope.OUTBOUND);
46  
47          MuleMessage response = client.send("vm://in-synch", message);
48          assertNotNull(response);
49          assertNull("Property should not have been propogated for this scope", response.getProperty("foo", PropertyScope.OUTBOUND));
50      }
51  
52      public void testInvocationScopeSynchronous() throws Exception
53      {
54          MuleClient client = muleContext.getClient();
55          MuleMessage message = new DefaultMuleMessage(TEST_MESSAGE, muleContext);
56          message.setProperty("foo", "bar", PropertyScope.INVOCATION);
57          
58          MuleMessage response = client.send("vm://in-synch", message);
59          assertNotNull(response);
60          assertEquals("bar", response.getProperty("foo", PropertyScope.INVOCATION));
61      }
62  
63      public void testSessionScopeSynchronous() throws Exception
64      {
65          MuleClient client = muleContext.getClient();
66          MuleMessage message = new DefaultMuleMessage(TEST_MESSAGE, muleContext);
67          message.setProperty("foo", "bar", PropertyScope.SESSION);
68  
69          MuleMessage response = client.send("vm://in-synch", message);
70          assertNotNull(response);
71          assertEquals("bar", response.getProperty("foo", PropertyScope.SESSION));
72      }
73  
74      public void testInboundScopeAsynchronous() throws Exception
75      {
76          MuleClient client = muleContext.getClient();
77          MuleMessage message = new DefaultMuleMessage(TEST_MESSAGE, muleContext);
78          message.setProperty("foo", "bar", PropertyScope.INBOUND);
79          client.dispatch("vm://in-asynch", message);
80          MuleMessage response = client.request("vm://out-asynch", 1000);
81          assertNotNull(response);
82          assertNull("Property should not have been propogated for this scope", response.getProperty("foo", PropertyScope.INBOUND));
83      }
84  
85      public void testOutboundScopeAsynchronous() throws Exception
86      {
87          MuleClient client = muleContext.getClient();
88          MuleMessage message = new DefaultMuleMessage(TEST_MESSAGE, muleContext);
89          message.setProperty("foo", "bar", PropertyScope.OUTBOUND);
90          client.dispatch("vm://in-asynch", message);
91          MuleMessage response = client.request("vm://out-asynch", 1000);
92          assertNotNull(response);
93          assertNull("Property should not have been propogated for this scope", response.getProperty("foo", PropertyScope.OUTBOUND));
94      }
95  
96      public void testInvocationScopeAsynchronous() throws Exception
97      {
98          MuleClient client = muleContext.getClient();
99          MuleMessage message = new DefaultMuleMessage(TEST_MESSAGE, muleContext);
100         message.setProperty("foo", "bar", PropertyScope.INVOCATION);
101         client.dispatch("vm://in-asynch", message);
102         MuleMessage response = client.request("vm://out-asynch", 1000);
103         assertNotNull(response);
104         assertEquals("bar", response.getProperty("foo", PropertyScope.INVOCATION));
105     }
106 
107     public void testSessionScopeAsynchronous() throws Exception
108     {
109         MuleClient client = muleContext.getClient();
110         MuleMessage message = new DefaultMuleMessage(TEST_MESSAGE, muleContext);
111         message.setProperty("foo", "bar", PropertyScope.SESSION);
112         client.dispatch("vm://in-asynch", message);
113         MuleMessage response = client.request("vm://out-asynch", 1000);
114         assertNotNull(response);
115         assertEquals("bar", response.getProperty("foo", PropertyScope.SESSION));
116     }
117 }
118 
119