1   /*
2    * $Id: XFireCustomHttpHeaderTestCase.java 7963 2007-08-21 08:53:15Z dirk.olmes $
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.providers.soap.xfire;
12  
13  import org.mule.MuleManager;
14  import org.mule.config.MuleProperties;
15  import org.mule.extras.client.MuleClient;
16  import org.mule.impl.internal.notifications.MessageNotification;
17  import org.mule.impl.internal.notifications.MessageNotificationListener;
18  import org.mule.tck.FunctionalTestCase;
19  import org.mule.umo.UMOMessage;
20  import org.mule.umo.manager.UMOServerNotification;
21  
22  import java.util.HashMap;
23  
24  public class XFireCustomHttpHeaderTestCase extends FunctionalTestCase implements MessageNotificationListener
25  {
26      protected static final String endpointAddress = "http://localhost:63181/services/TestComponent?method=onReceive";
27  
28      private UMOMessage notificationMsg = null;
29  
30      // @Override
31      protected void doPostFunctionalSetUp() throws Exception
32      {
33          super.doPostFunctionalSetUp();
34          MuleManager.getInstance().registerListener(this);
35      }
36  
37      // @Override
38      protected void doFunctionalTearDown() throws Exception
39      {
40          MuleManager.getInstance().unregisterListener(this);
41          super.doFunctionalTearDown();
42      }
43  
44      public void testXfire() throws Exception
45      {
46          Object payload = new Object[]{"Test String"};
47          String myProperty = "myProperty";
48  
49          HashMap props = new HashMap();
50          props.put(MuleProperties.MULE_USER_PROPERTY, "alan");
51          props.put(MuleProperties.MULE_METHOD_PROPERTY, "sayHello");
52          props.put(myProperty, myProperty);
53  
54          MuleClient client = new MuleClient();
55          UMOMessage reply = client.send("xfire:" + endpointAddress, payload, props);
56  
57          assertNotNull(reply);
58          assertNotNull(reply.getPayload());
59          assertEquals("Test String Received", reply.getPayloadAsString());
60  
61          // make sure all notifications have trickled in
62          Thread.sleep(3000);
63  
64          // make sure we received a notification on xfire
65          assertNotNull(notificationMsg);
66  
67          // MULE_USER should be allowed in
68          assertEquals("alan", notificationMsg.getProperty(MuleProperties.MULE_USER_PROPERTY));
69  
70          // mule properties should be removed
71          assertNull(notificationMsg.getProperty(MuleProperties.MULE_IGNORE_METHOD_PROPERTY));
72  
73          // custom properties should be allowed in
74          assertEquals(myProperty, notificationMsg.getProperty(myProperty));
75      }
76  
77      public void onNotification(UMOServerNotification notification)
78      {
79          if (notification instanceof MessageNotification)
80          {
81              String uri = ((MessageNotification)notification).getEndpoint().getEndpointURI().toString();
82              if (endpointAddress.equals(uri))
83              {
84                  notificationMsg = (UMOMessage)notification.getSource();
85              }
86          }
87      }
88  
89      protected String getConfigResources()
90      {
91          return "xfire-headers-conf.xml";
92      }
93  
94  }