1
2
3
4
5
6
7 package org.mule.test.properties;
8
9 import org.mule.DefaultMuleMessage;
10 import org.mule.api.MuleMessage;
11 import org.mule.module.client.MuleClient;
12 import org.mule.tck.junit4.FunctionalTestCase;
13 import org.mule.tck.functional.FunctionalTestComponent;
14
15 import java.util.Map;
16
17 import org.junit.Test;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNotNull;
21 import static org.junit.Assert.assertNull;
22
23 public class PropertiesTestCase extends FunctionalTestCase
24 {
25
26 @Override
27 protected String getConfigResources()
28 {
29 return "org/mule/test/properties/properties-config.xml";
30 }
31
32
33
34
35 @Test
36 public void testProperties() throws Exception
37 {
38 MuleClient client = new MuleClient(muleContext);
39
40 Map<String, FunctionalTestComponent> components = muleContext.getRegistry().lookupByType(FunctionalTestComponent.class);
41 MuleMessage msg1 = createOutboundMessage();
42 MuleMessage response = client.send("vm://in", msg1);
43 assertEquals(response.getPayloadAsString(), "OK(success)");
44 assertNull(response.getInboundProperty("outbound1"));
45 assertNull(response.getInboundProperty("outbound2"));
46 assertNull(response.getOutboundProperty("outbound1"));
47 assertNull(response.getOutboundProperty("outbound2"));
48 assertNotNull(response.<Object>getInvocationProperty("invocation1"));
49 assertNotNull(response.<Object>getInvocationProperty("invocation2"));
50 assertEquals("123", response.getInboundProperty("outbound3"));
51 assertEquals("456", response.getInboundProperty("outbound4"));
52 assertNull(response.<Object>getInvocationProperty("invocation3"));
53 assertNull(response.<Object>getInvocationProperty("invocation4"));
54
55 MuleMessage msg2 = createOutboundMessage();
56 client.dispatch("vm://inQueue", msg2);
57 Thread.sleep(1000);
58 response = client.request("vm://outQueue", 0);
59 assertEquals(response.getPayloadAsString(), "OK");
60 assertEquals("yes", response.getInboundProperty("outbound1"));
61 assertEquals("no", response.getInboundProperty("outbound2"));
62 assertNull(response.getOutboundProperty("outbound1"));
63 assertNull(response.getOutboundProperty("outbound2"));
64 assertNull(response.<Object>getInvocationProperty("invocation1"));
65 assertNull(response.<Object>getInvocationProperty("invocation2"));
66
67 }
68
69 private MuleMessage createOutboundMessage()
70 {
71 MuleMessage msg = new DefaultMuleMessage("OK", muleContext);
72 msg.setOutboundProperty("outbound1", "yes");
73 msg.setOutboundProperty("outbound2", "no");
74 msg.setInvocationProperty("invocation1", "ja");
75 msg.setInvocationProperty("invocation2", "nein");
76 return msg;
77 }
78
79 public static class Component
80 {
81
82
83
84
85 public MuleMessage process(Object payload)
86 {
87 MuleMessage msg = new DefaultMuleMessage(payload + "(success)", muleContext);
88 msg.setOutboundProperty("outbound3", "123");
89 msg.setOutboundProperty("outbound4", "456");
90 msg.setInvocationProperty("invocation3", "UVW");
91 msg.setInvocationProperty("invocation4", "XYZ");
92 return msg;
93 }
94 }
95 }