View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.soap.axis;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.api.config.MuleProperties;
11  import org.mule.module.client.MuleClient;
12  import org.mule.tck.junit4.FunctionalTestCase;
13  import org.mule.tck.junit4.rule.DynamicPort;
14  
15  import java.util.HashMap;
16  import java.util.Map;
17  
18  import javax.xml.namespace.QName;
19  import javax.xml.rpc.ParameterMode;
20  
21  import org.junit.Rule;
22  import org.junit.Test;
23  
24  import static org.junit.Assert.assertEquals;
25  
26  public class AxisNamedParametersTestCase extends FunctionalTestCase
27  {
28  
29      @Rule
30      public DynamicPort dynamicPort = new DynamicPort("port1");
31  
32      @Override
33      protected String getConfigResources()
34      {
35          return "axis-named-param-mule-config.xml";
36      }
37  
38      @Test
39      public void testNamedParameters() throws Exception
40      {
41          MuleClient client = new MuleClient(muleContext);
42          // The service itself will throw an exception if the parameters in the
43          // request SOAP message are not named
44          MuleMessage result = client.send("vm://mycomponent1", "Hello Named", null);
45          assertEquals("Hello Named", result.getPayload());
46      }
47  
48      @Test
49      public void testNamedParametersViaClient() throws Exception
50      {
51          MuleClient client = new MuleClient(muleContext);
52          Map props = new HashMap();
53          // create the soap method passing in the method name and return type
54          SoapMethod soapMethod = new SoapMethod(new QName("echo"), NamedParameter.XSD_STRING);
55          // add one or more parameters
56          soapMethod.addNamedParameter(new QName("value"), NamedParameter.XSD_STRING, ParameterMode.IN);
57          // set the soap method as a property and pass the properties
58          // when making the call
59          props.put(MuleProperties.MULE_SOAP_METHOD, soapMethod);
60  
61          MuleMessage result = client.send("axis:http://localhost:" + dynamicPort.getNumber() + "/mule/mycomponent2?method=echo",
62              "Hello Named", props);
63          assertEquals("Hello Named", result.getPayload());
64      }
65  
66  }