1   /*
2    * $Id: AxisExternalServerTest.java 7963 2007-08-21 08:53:15Z dirk.olmes $
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.providers.soap.axis;
12  
13  import org.mule.MuleManager;
14  import org.mule.config.MuleProperties;
15  import org.mule.extras.client.MuleClient;
16  import org.mule.providers.soap.NamedParameter;
17  import org.mule.providers.soap.SoapMethod;
18  import org.mule.tck.AbstractMuleTestCase;
19  import org.mule.umo.UMOMessage;
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      public static final String TEST_URL = "http://localhost:8080/mule-tests-external-axis/axis/Calculator.jws";
33      public static final String TEST_AXIS_URL = "axis:" + TEST_URL;
34      public static final String TEST_WSDL_URL = "wsdl-exis:" + TEST_URL + "?wsdl";
35  
36      public void testAxisServiceRPC() throws Exception
37      {
38          String URL = TEST_AXIS_URL + "?method=add";
39          MuleClient client = new MuleClient();
40          UMOMessage result = client.send(URL, new Object[]{new Integer(4), new Integer(3)}, null);
41          assertNotNull(result);
42  
43          assertEquals(result.getPayload(), new Integer(7));
44      }
45  
46      public void testAxisServiceDocLitWrapped() throws Exception
47      {
48          String URL = TEST_AXIS_URL + "?method=add";
49          MuleClient client = new MuleClient();
50          Map props = new HashMap();
51          props.put("style", "wrapped");
52          props.put("use", "literal");
53          UMOMessage result = client.send(URL, new Object[]{new Integer(3), new Integer(3)}, props);
54          assertNotNull(result);
55  
56          assertEquals(result.getPayload(), new Integer(6));
57      }
58  
59      public void testAxisServiceDocLitWrappedWithNamedParams() throws Exception
60      {
61          String URL = TEST_AXIS_URL;
62          MuleClient client = new MuleClient();
63  
64          SoapMethod method = new SoapMethod(new QName("http://muleumo.org/Calc", "add"));
65          method.addNamedParameter(new QName("Number1"), NamedParameter.XSD_INT, "in");
66          method.addNamedParameter(new QName("Number2"), NamedParameter.XSD_INT, "in");
67          method.setReturnType(NamedParameter.XSD_INT);
68  
69          Map props = new HashMap();
70          props.put("style", "wrapped");
71          props.put("use", "literal");
72          props.put(MuleProperties.MULE_METHOD_PROPERTY, method);
73          UMOMessage result = client.send(URL, new Object[]{new Integer(3), new Integer(3)}, props);
74          assertNotNull(result);
75  
76          assertEquals(result.getPayload(), new Integer(6));
77      }
78  
79      public void testAxisServiceDocLitWrappedWithNamedParamsinXml() throws Exception
80      {
81  
82          MuleManager.getInstance().dispose();
83          MuleClient client = new MuleClient(
84              "axis-client-endpoint-config.xml");
85  
86          UMOMessage result = client.send("calculatorAddEndpoint",
87              new Object[]{new Integer(3), new Integer(3)}, null);
88          assertNotNull(result);
89  
90          assertEquals(result.getPayload(), new Integer(6));
91      }
92  
93      // The service is not hosted as Doc/Lit, so Axis will not allow us
94      // to send a Doc/Lit request style soap message
95      // public void testAxisServiceDocLit() throws Exception
96      // {
97      // String URL = TEST_AXIS_URL;
98      // MuleClient client = new MuleClient();
99      // Map props = new HashMap();
100     // props.put("style", "document");
101     // props.put("use", "literal");
102     //         
103     // SoapMethod method = new SoapMethod(new
104     // QName(TEST_URL, "add"));
105     // method.addNamedParameter(new QName("i1"), NamedParameter.XSD_INT, "in");
106     // method.addNamedParameter(new QName("i2"), NamedParameter.XSD_INT, "in");
107     // method.setReturnType(NamedParameter.XSD_INT);
108     // props.put(MuleProperties.MULE_METHOD_PROPERTY, method);
109     //         
110     // UMOMessage result = client.send(URL, new Object[]{new Integer(3), new
111     // Integer(3)}, props);
112     // assertNotNull(result);
113     //        
114     // assertEquals(result.getPayload(), new Integer(6));
115     // }
116 
117     // wsdl-axis is currently disabled due to the problems axis had with this
118     // feature
119     // public void testAxisServiceUsingWSDL() throws Exception
120     // {
121     // String URL = TEST_WSDL_URL + "&method=add";
122     // MuleClient client = new MuleClient();
123     
124     // UMOMessage result = client.send(URL, new Object[]{new Integer(4), new
125     // Integer(4)}, null);
126     // assertNotNull(result);
127    
128     // assertEquals(result.getPayload(), new Integer(8));
129     // }
130 
131 }