1
2
3
4
5
6
7
8
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.junit4.FunctionalTestCase;
18
19 import org.junit.Test;
20
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertNotNull;
23 import static org.junit.Assert.assertNull;
24
25
26
27
28 public class PropertyScopesTestCase extends FunctionalTestCase
29 {
30
31 @Override
32 protected String getConfigResources()
33 {
34 return "vm/property-scopes.xml";
35 }
36
37 @Test
38 public void testInboundScopeSynchronous() throws Exception
39 {
40 MuleClient client = muleContext.getClient();
41 MuleMessage message = new DefaultMuleMessage(TEST_MESSAGE, muleContext);
42 message.setProperty("foo", "bar", PropertyScope.INBOUND);
43
44 MuleMessage response = client.send("vm://in-synch", message);
45 assertNotNull(response);
46 assertNull("Property should not have been propogated for this scope", response.getProperty("foo", PropertyScope.INBOUND));
47 }
48
49 @Test
50 public void testOutboundScopeSynchronous() throws Exception
51 {
52 MuleClient client = muleContext.getClient();
53 MuleMessage message = new DefaultMuleMessage(TEST_MESSAGE, muleContext);
54 message.setProperty("foo", "bar", PropertyScope.OUTBOUND);
55
56 MuleMessage response = client.send("vm://in-synch", message);
57 assertNotNull(response);
58 assertNull("Property should not have been propogated for this scope", response.getProperty("foo", PropertyScope.OUTBOUND));
59 }
60
61 @Test
62 public void testInvocationScopeSynchronous() throws Exception
63 {
64 MuleClient client = muleContext.getClient();
65 MuleMessage message = new DefaultMuleMessage(TEST_MESSAGE, muleContext);
66 message.setProperty("foo", "bar", PropertyScope.INVOCATION);
67
68 MuleMessage response = client.send("vm://in-synch", message);
69 assertNotNull(response);
70 assertEquals("bar", response.getProperty("foo", PropertyScope.INVOCATION));
71 }
72
73 @Test
74 public void testSessionScopeSynchronous() throws Exception
75 {
76 MuleClient client = muleContext.getClient();
77 MuleMessage message = new DefaultMuleMessage(TEST_MESSAGE, muleContext);
78 message.setProperty("foo", "bar", PropertyScope.SESSION);
79
80 MuleMessage response = client.send("vm://in-synch", message);
81 assertNotNull(response);
82 assertEquals("bar", response.getProperty("foo", PropertyScope.SESSION));
83 }
84
85 @Test
86 public void testInboundScopeAsynchronous() throws Exception
87 {
88 MuleClient client = muleContext.getClient();
89 MuleMessage message = new DefaultMuleMessage(TEST_MESSAGE, muleContext);
90 message.setProperty("foo", "bar", PropertyScope.INBOUND);
91 client.dispatch("vm://in-asynch", message);
92 MuleMessage response = client.request("vm://out-asynch", 1000);
93 assertNotNull(response);
94 assertNull("Property should not have been propogated for this scope", response.getProperty("foo", PropertyScope.INBOUND));
95 }
96
97 @Test
98 public void testOutboundScopeAsynchronous() throws Exception
99 {
100 MuleClient client = muleContext.getClient();
101 MuleMessage message = new DefaultMuleMessage(TEST_MESSAGE, muleContext);
102 message.setProperty("foo", "bar", PropertyScope.OUTBOUND);
103 client.dispatch("vm://in-asynch", message);
104 MuleMessage response = client.request("vm://out-asynch", 1000);
105 assertNotNull(response);
106 assertNull("Property should not have been propogated for this scope", response.getProperty("foo", PropertyScope.OUTBOUND));
107 }
108
109 @Test
110 public void testInvocationScopeAsynchronous() throws Exception
111 {
112 MuleClient client = muleContext.getClient();
113 MuleMessage message = new DefaultMuleMessage(TEST_MESSAGE, muleContext);
114 message.setProperty("foo", "bar", PropertyScope.INVOCATION);
115 client.dispatch("vm://in-asynch", message);
116 MuleMessage response = client.request("vm://out-asynch", 1000);
117 assertNotNull(response);
118 assertEquals("bar", response.getProperty("foo", PropertyScope.INVOCATION));
119 }
120
121 @Test
122 public void testSessionScopeAsynchronous() throws Exception
123 {
124 MuleClient client = muleContext.getClient();
125 MuleMessage message = new DefaultMuleMessage(TEST_MESSAGE, muleContext);
126 message.setProperty("foo", "bar", PropertyScope.SESSION);
127 client.dispatch("vm://in-asynch", message);
128 MuleMessage response = client.request("vm://out-asynch", 1000);
129 assertNotNull(response);
130 assertEquals("bar", response.getProperty("foo", PropertyScope.SESSION));
131 }
132 }
133
134