View Javadoc

1   /*
2    * $Id$
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.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.FunctionalTestCase;
17  import org.mule.tck.functional.FunctionalTestComponent;
18  
19  import java.util.Map;
20  
21  public class PropertiesTestCase extends FunctionalTestCase
22  {
23      @Override
24      protected String getConfigResources()
25      {
26          return "org/mule/test/properties/properties-config.xml";
27      }
28  
29      /**
30       * Test that the VM transport correctly copies outbound to inbound properties both for requests amd responses
31       */
32      public void testProperties() throws Exception
33      {
34          MuleClient client = new MuleClient(muleContext);
35  
36          Map<String, FunctionalTestComponent> components = muleContext.getRegistry().lookupByType(FunctionalTestComponent.class);
37          MuleMessage msg1 = createOutboundMessage();
38          MuleMessage response = client.send("vm://in", msg1);
39          assertEquals(response.getPayloadAsString(), "OK(success)");
40          assertNull(response.getInboundProperty("outbound1"));
41          assertNull(response.getInboundProperty("outbound2"));
42          assertNull(response.getOutboundProperty("outbound1"));
43          assertNull(response.getOutboundProperty("outbound2"));
44          assertNull(response.<Object>getInvocationProperty("invocation1"));
45          assertNull(response.<Object>getInvocationProperty("invocation2"));
46          assertEquals("123", response.getInboundProperty("outbound3"));
47          assertEquals("456", response.getInboundProperty("outbound4"));
48          assertNull(response.<Object>getInvocationProperty("invocation3"));
49          assertNull(response.<Object>getInvocationProperty("invocation4"));
50  
51          MuleMessage msg2 = createOutboundMessage();
52          client.dispatch("vm://inQueue", msg2);
53          Thread.sleep(1000);
54          response = client.request("vm://outQueue", 0);
55          assertEquals(response.getPayloadAsString(), "OK");
56          assertEquals("yes", response.getInboundProperty("outbound1"));
57          assertEquals("no", response.getInboundProperty("outbound2"));
58          assertNull(response.getOutboundProperty("outbound1"));
59          assertNull(response.getOutboundProperty("outbound2"));
60          assertNull(response.<Object>getInvocationProperty("invocation1"));
61          assertNull(response.<Object>getInvocationProperty("invocation2"));
62  
63      }
64  
65      private MuleMessage createOutboundMessage()
66      {
67          MuleMessage msg = new DefaultMuleMessage("OK", muleContext);
68          msg.setOutboundProperty("outbound1", "yes");
69          msg.setOutboundProperty("outbound2", "no");
70          msg.setInvocationProperty("invocation1", "ja");
71          msg.setInvocationProperty("invocation2", "nein");
72          return msg;
73      }
74  
75      public static class Component
76      {
77          /**
78           * Create a message with outbound and invocation properties.  These should have been moved to the inbound scope
79           * by the time the message is received.  Invocation properties should have been removed
80           */
81          public MuleMessage process(Object payload)
82          {
83              MuleMessage msg = new DefaultMuleMessage(payload + "(success)", muleContext);
84              msg.setOutboundProperty("outbound3", "123");
85              msg.setOutboundProperty("outbound4", "456");
86              msg.setInvocationProperty("invocation3", "UVW");
87              msg.setInvocationProperty("invocation4", "XYZ");
88              return msg;
89          }
90      }
91  }