1
2
3
4
5
6
7 package org.mule;
8
9 import org.mule.api.MuleMessage;
10 import org.mule.api.transport.PropertyScope;
11 import org.mule.module.client.MuleClient;
12 import org.mule.tck.junit4.FunctionalTestCase;
13 import org.mule.test.filters.FilterCounter;
14
15 import org.junit.Test;
16
17 import static org.junit.Assert.assertEquals;
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertNull;
20 import static org.junit.Assert.assertTrue;
21
22
23
24
25
26
27 public class Mule4412TestCase extends FunctionalTestCase
28 {
29 private int RECEIVE_TIMEOUT_MS = 3000;
30
31 @Override
32 protected String getConfigResources()
33 {
34 return "mule-4412.xml";
35 }
36
37 @Override
38 protected void doSetUp() throws Exception
39 {
40 super.doSetUp();
41
42 FilterCounter.counter.set(0);
43 }
44
45 @Override
46 protected void doTearDown() throws Exception
47 {
48 super.doTearDown();
49
50 FilterCounter.counter.set(0);
51 }
52
53
54
55
56
57
58 @Test
59 public void testFilterOnce() throws Exception
60 {
61 DefaultMuleMessage msg = new DefaultMuleMessage(TEST_MESSAGE, muleContext);
62 msg.setOutboundProperty("pass", "true");
63 MuleClient client = new MuleClient(muleContext);
64 client.send("vm://async", msg);
65 MuleMessage reply = client.request("vm://asyncResponse", RECEIVE_TIMEOUT_MS);
66 int times = FilterCounter.counter.get();
67 assertTrue("did not filter one time as expected, times filtered " + times, times == 1);
68 assertNotNull(reply);
69 assertEquals("wrong message received : " + reply.getPayloadAsString(), TEST_MESSAGE,
70 reply.getPayloadAsString());
71 assertEquals("'pass' property value not correct", "true", reply.getInboundProperty("pass"));
72
73
74 assertNull(client.request("vm://asyncResponse", RECEIVE_TIMEOUT_MS));
75 }
76
77
78
79
80
81
82 @Test
83 public void testWrongPropertyKey() throws Exception
84 {
85 DefaultMuleMessage msg = new DefaultMuleMessage(TEST_MESSAGE, muleContext);
86 msg.setProperty("fail", "true", PropertyScope.INVOCATION);
87 MuleClient client = new MuleClient(muleContext);
88 client.send("vm://async", msg);
89 MuleMessage reply = client.request("vm://asyncResponse", RECEIVE_TIMEOUT_MS);
90 assertNull(reply);
91 assertTrue("should not have filtered", FilterCounter.counter.get() == 0);
92 }
93
94
95
96
97
98
99
100 @Test
101 public void testWrongPropertyValue() throws Exception
102 {
103 DefaultMuleMessage msg = new DefaultMuleMessage(TEST_MESSAGE, muleContext);
104 msg.setInboundProperty("pass", "false");
105 MuleClient client = new MuleClient(muleContext);
106 client.send("vm://async", msg);
107 MuleMessage reply = client.request("vm://asyncResponse", RECEIVE_TIMEOUT_MS);
108 assertNull(reply);
109 assertTrue("should not have filtered", FilterCounter.counter.get() == 0);
110 }
111
112
113
114
115
116
117
118 @Test
119 public void testNoProperty() throws Exception
120 {
121 DefaultMuleMessage msg = new DefaultMuleMessage(TEST_MESSAGE, muleContext);
122 MuleClient client = new MuleClient(muleContext);
123 client.send("vm://async", msg);
124 MuleMessage reply = client.request("vm://asyncResponse", RECEIVE_TIMEOUT_MS);
125 assertNull(reply);
126 assertTrue("should not have filtered", FilterCounter.counter.get() == 0);
127 }
128 }