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