View Javadoc

1   /*
2    * $Id: CxfCustomHttpHeaderTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.module.cxf;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.api.config.MuleProperties;
15  import org.mule.api.context.notification.EndpointMessageNotificationListener;
16  import org.mule.api.context.notification.ServerNotification;
17  import org.mule.context.notification.EndpointMessageNotification;
18  import org.mule.module.client.MuleClient;
19  import org.mule.tck.FunctionalTestCase;
20  
21  import java.util.HashMap;
22  import java.util.concurrent.CountDownLatch;
23  
24  public class CxfCustomHttpHeaderTestCase extends FunctionalTestCase implements EndpointMessageNotificationListener
25  {
26      protected static final String endpointAddress = "http://localhost:63181/services/TestComponent?method=onReceive";
27  
28      private MuleMessage notificationMsg = null;
29      private CountDownLatch latch = null;
30  
31      protected void doSetUp() throws Exception
32      {
33          latch = new CountDownLatch(1);
34          muleContext.registerListener(this);
35      }
36  
37      protected void doTearDown() throws Exception
38      {
39          muleContext.unregisterListener(this);
40      }
41  
42      public void testCxf() throws Exception
43      {
44          Object payload = new Object[]{"Test String"};
45          String myProperty = "myProperty";
46  
47          HashMap<String, String> props = new HashMap<String, String>();
48          props.put(MuleProperties.MULE_USER_PROPERTY, "alan");
49          props.put(MuleProperties.MULE_METHOD_PROPERTY, "onReceive");
50          props.put(myProperty, myProperty);
51  
52          MuleClient client = new MuleClient(muleContext);
53          MuleMessage reply = client.send("cxf:" + endpointAddress, payload, props);
54  
55          assertNotNull(reply);
56          assertNotNull(reply.getPayload());
57          assertEquals("Test String Received", reply.getPayloadAsString());
58  
59          // make sure all notifications have trickled in
60          Thread.sleep(3000);
61  
62          // make sure we received a notification on cxf
63          assertNotNull(notificationMsg);
64  
65          // MULE_USER should be allowed in
66          assertEquals("alan", notificationMsg.getOutboundProperty(MuleProperties.MULE_USER_PROPERTY));
67  
68          // mule properties should be removed
69          assertNull(notificationMsg.getOutboundProperty(MuleProperties.MULE_IGNORE_METHOD_PROPERTY));
70  
71          // custom properties should be allowed in
72          assertEquals(myProperty, notificationMsg.getOutboundProperty(myProperty));
73      }
74  
75      public void onNotification(ServerNotification notification)
76      {
77          if (notification instanceof EndpointMessageNotification)
78          {
79              String uri = ((EndpointMessageNotification) notification).getEndpoint();
80              if (endpointAddress.equals(uri))
81              {
82                  notificationMsg = (MuleMessage) notification.getSource();
83                  latch.countDown();
84              }
85          }
86          else
87          {
88              fail("invalid notification: " + notification);
89          }
90      }
91  
92      protected String getConfigResources()
93      {
94          return "headers-conf.xml";
95      }
96  
97  }