View Javadoc

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