View Javadoc

1   /*
2    * $Id: AxisNamedParametersTestCase.java 19841 2010-10-05 23:17:20Z dzapata $
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.transport.soap.axis;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.api.config.MuleProperties;
15  import org.mule.module.client.MuleClient;
16  import org.mule.tck.DynamicPortTestCase;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  import javax.xml.namespace.QName;
22  import javax.xml.rpc.ParameterMode;
23  
24  public class AxisNamedParametersTestCase extends DynamicPortTestCase
25  {
26  
27      @Override
28      protected String getConfigResources()
29      {
30          return "axis-named-param-mule-config.xml";
31      }
32  
33      public void testNamedParameters() throws Exception
34      {
35          MuleClient client = new MuleClient(muleContext);
36          // The service itself will throw an exception if the parameters in the
37          // request SOAP message are not named
38          MuleMessage result = client.send("vm://mycomponent1", "Hello Named", null);
39          assertEquals("Hello Named", result.getPayload());
40      }
41  
42      public void testNamedParametersViaClient() throws Exception
43      {
44          MuleClient client = new MuleClient(muleContext);
45          Map props = new HashMap();
46          // create the soap method passing in the method name and return type
47          SoapMethod soapMethod = new SoapMethod(new QName("echo"), NamedParameter.XSD_STRING);
48          // add one or more parameters
49          soapMethod.addNamedParameter(new QName("value"), NamedParameter.XSD_STRING, ParameterMode.IN);
50          // set the soap method as a property and pass the properties
51          // when making the call
52          props.put(MuleProperties.MULE_SOAP_METHOD, soapMethod);
53  
54          MuleMessage result = client.send("axis:http://localhost:" + getPorts().get(0) + "/mule/mycomponent2?method=echo",
55              "Hello Named", props);
56          assertEquals("Hello Named", result.getPayload());
57      }
58  
59      @Override
60      protected int getNumPortsToFind()
61      {
62          return 1;
63      }
64  }