View Javadoc

1   /*
2    * $Id: HeaderPropertiesTestCase.java 22450 2011-07-19 08:20:41Z dirk.olmes $
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.jaxws;
12  
13  import org.mule.api.MuleEventContext;
14  import org.mule.api.MuleMessage;
15  import org.mule.module.client.MuleClient;
16  import org.mule.tck.functional.EventCallback;
17  import org.mule.tck.functional.FunctionalTestComponent;
18  import org.mule.tck.junit4.FunctionalTestCase;
19  import org.mule.tck.junit4.rule.DynamicPort;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  import org.apache.hello_world_soap_http.GreeterImpl;
25  import org.junit.Rule;
26  import org.junit.Test;
27  
28  import static org.junit.Assert.assertEquals;
29  import static org.junit.Assert.assertNotNull;
30  
31  public class HeaderPropertiesTestCase extends FunctionalTestCase
32  {
33  
34      @Rule
35      public DynamicPort dynamicPort = new DynamicPort("port1");
36  
37      @Override
38      protected String getConfigResources()
39      {
40          return "header-conf.xml";
41      }
42  
43      private GreeterImpl getGreeter() throws Exception
44      {
45          Object instance = getComponent("greeterService");
46  
47          return (GreeterImpl) instance;
48      }
49  
50      @Test
51      public void testClientWithMuleClient() throws Exception
52      {
53          FunctionalTestComponent testComponent = getFunctionalTestComponent("testService");
54          assertNotNull(testComponent);
55  
56          EventCallback callback = new EventCallback()
57          {
58              public void eventReceived(final MuleEventContext context, final Object component) throws Exception
59              {
60                  MuleMessage msg = context.getMessage();
61                  assertEquals("BAR", msg.getInboundProperty("FOO"));
62              }
63          };
64          testComponent.setEventCallback(callback);
65  
66          MuleClient client = new MuleClient(muleContext);
67          Map<String, Object> props = new HashMap<String, Object>();
68          props.put("operation", "greetMe");
69          props.put("FOO", "BAR");
70          MuleMessage result = client.send("clientEndpoint", "Dan", props);
71          assertEquals("Hello Dan Received", result.getPayload());
72  
73          GreeterImpl impl = getGreeter();
74          assertEquals(1, impl.getInvocationCount());
75      }
76  }