1   /*
2    * $Id: AxisExternalServerTest.java 10789 2008-02-12 20:04:43Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.AbstractMuleTestCase;
17  import org.mule.transport.soap.NamedParameter;
18  import org.mule.transport.soap.SoapMethod;
19  import org.mule.transport.soap.axis.AxisConnector;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  import javax.xml.namespace.QName;
25  
26  /**
27   * Requires an external Axis server running in Tomcat with the Calculator.jws service
28   * deployed to it.
29   */
30  public class AxisExternalServerTest extends AbstractMuleTestCase
31  {
32  
33      public void testAxisServiceRPC() throws Exception
34      {
35          String URL = "axis:http://localhost:8080/axis/Calculator.jws?method=add";
36          MuleClient client = new MuleClient();
37          MuleMessage result = client.send(URL, new Object[]{new Integer(4), new Integer(3)}, null);
38          assertNotNull(result);
39  
40          assertEquals(result.getPayload(), new Integer(7));
41      }
42  
43      public void testAxisServiceDocLitWrapped() throws Exception
44      {
45          String URL = "axis:http://localhost:8080/axis/Calculator.jws?method=add";
46          MuleClient client = new MuleClient();
47          Map props = new HashMap();
48          props.put(AxisConnector.STYLE, "wrapped");
49          props.put(AxisConnector.USE, "literal");
50          MuleMessage result = client.send(URL, new Object[]{new Integer(3), new Integer(3)}, props);
51          assertNotNull(result);
52  
53          assertEquals(result.getPayload(), new Integer(6));
54      }
55  
56      public void testAxisServiceDocLitWrappedWithNamedParams() throws Exception
57      {
58          String URL = "axis:http://localhost:8080/axis/Calculator.jws";
59          MuleClient client = new MuleClient();
60  
61          SoapMethod method = new SoapMethod(new QName("http://muleumo.org/Calc", "add"));
62          method.addNamedParameter(new QName("Number1"), NamedParameter.XSD_INT, "in");
63          method.addNamedParameter(new QName("Number2"), NamedParameter.XSD_INT, "in");
64          method.setReturnType(NamedParameter.XSD_INT);
65  
66          Map props = new HashMap();
67          props.put(AxisConnector.STYLE, "wrapped");
68          props.put(AxisConnector.USE, "literal");
69          props.put(MuleProperties.MULE_METHOD_PROPERTY, method);
70          MuleMessage result = client.send(URL, new Object[]{new Integer(3), new Integer(3)}, props);
71          assertNotNull(result);
72  
73          assertEquals(result.getPayload(), new Integer(6));
74      }
75  
76      public void testAxisServiceDocLitWrappedWithNamedParamsinXml() throws Exception
77      {
78  
79          MuleClient client = new MuleClient(
80              "axis-client-endpoint-config.xml");
81  
82          MuleMessage result = client.send("calculatorAddEndpoint",
83              new Object[]{new Integer(3), new Integer(3)}, null);
84          assertNotNull(result);
85  
86          assertEquals(result.getPayload(), new Integer(6));
87      }
88  
89      // The service is not hosted as Doc/Lit, so Axis will not allow us
90      // to send a Doc/Lit request style soap message
91      // public void testAxisServiceDocLit() throws Exception
92      // {
93      // String URL = "axis:http://localhost:8080/axis/Calculator.jws";
94      // MuleClient client = new MuleClient();
95      // Map props = new HashMap();
96      // props.put("style", "document");
97      // props.put("use", "literal");
98      //         
99      // SoapMethod method = new SoapMethod(new
100     // QName("http://localhost:8080/axis/Calculator.jws", "add"));
101     // method.addNamedParameter(new QName("i1"), NamedParameter.XSD_INT, "in");
102     // method.addNamedParameter(new QName("i2"), NamedParameter.XSD_INT, "in");
103     // method.setReturnType(NamedParameter.XSD_INT);
104     // props.put(MuleProperties.MULE_METHOD_PROPERTY, method);
105     //         
106     // MuleMessage result = client.send(URL, new Object[]{new Integer(3), new
107     // Integer(3)}, props);
108     // assertNotNull(result);
109     //        
110     // assertEquals(result.getPayload(), new Integer(6));
111     // }
112 
113     // wsdl-axis is currently disabled due to the problems axis had with this
114     // feature
115     // public void testAxisServiceUsingWSDL() throws Exception
116     // {
117     // String URL =
118     // "wsdl-axis:http://localhost:8080/axis/Calculator.jws?wsdl&method=add";
119     // MuleClient client = new MuleClient();
120     //
121     // MuleMessage result = client.send(URL, new Object[]{new Integer(4), new
122     // Integer(4)}, null);
123     // assertNotNull(result);
124     //
125     // assertEquals(result.getPayload(), new Integer(8));
126     // }
127 
128 }
129