1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.soap.axis.style;
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.FunctionalTestCase;
17 import org.mule.transport.soap.NamedParameter;
18 import org.mule.transport.soap.SoapMethod;
19 import org.mule.util.StringUtils;
20
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import javax.xml.namespace.QName;
25 import javax.xml.rpc.ParameterMode;
26
27 import org.apache.axis.client.Call;
28 import org.apache.axis.client.Service;
29
30 public class AxisMessageStyleServiceTestCase extends FunctionalTestCase
31 {
32 private static String expectedResult = "TEST RESPONSE";
33
34 public String getConfigResources()
35 {
36 return "style/axis-mule-message-config.xml";
37 }
38
39 protected String getServiceEndpoint()
40 {
41 return "http://localhost:63080/ServiceEntryPoint";
42 }
43
44 public void testDocumentWithNamesapce() throws Exception
45 {
46 doSoapRequest(new QName("http://muleumo.org", "document"), "axis:" + getServiceEndpoint(), false,
47 false, false);
48 }
49
50 public void testDocumentWithQName() throws Exception
51 {
52 doSoapRequest(new QName("http://muleumo.org", "document"), "axis:" + getServiceEndpoint(), false,
53 false, true);
54 }
55
56 public void testDocumentWithAxisApi() throws Exception
57 {
58 doSoapRequest(new QName("http://muleumo.org", "document"), getServiceEndpoint(), true, false, false);
59 }
60
61 public void testDocumentWithSoapMethod() throws Exception
62 {
63 doSoapRequest(new QName("http://muleumo.org", "document"), "axis:" + getServiceEndpoint(), false,
64 true, false);
65 }
66
67 public void testElementArrayWithSoapMethod() throws Exception
68 {
69 doSoapRequest(new QName("http://muleumo.org", "elementArray"), "axis:" + getServiceEndpoint(), false,
70 true, false);
71 }
72
73 public void testElementArrayWithNamesapce() throws Exception
74 {
75 doSoapRequest(new QName("http://muleumo.org", "elementArray"), "axis:" + getServiceEndpoint(), false,
76 false, false);
77 }
78
79 public void testElementArrayWithQName() throws Exception
80 {
81 doSoapRequest(new QName("http://muleumo.org", "elementArray"), "axis:" + getServiceEndpoint(), false,
82 false, true);
83 }
84
85 public void testElementArrayWithAxisApi() throws Exception
86 {
87 doSoapRequest(new QName("http://muleumo.org", "elementArray"), getServiceEndpoint(), true, false,
88 false);
89 }
90
91 public void testSoapBodyElementWithSoapMethod() throws Exception
92 {
93 doSoapRequest(new QName("http://muleumo.org", "soapBodyElement"), "axis:" + getServiceEndpoint(),
94 false, true, false);
95 }
96
97 public void testSoapBodyElementWithNamesapce() throws Exception
98 {
99 doSoapRequest(new QName("http://muleumo.org", "soapBodyElement"), "axis:" + getServiceEndpoint(),
100 false, false, false);
101 }
102
103 public void testSoapBodyElementWithQName() throws Exception
104 {
105 doSoapRequest(new QName("http://muleumo.org", "soapBodyElement"), "axis:" + getServiceEndpoint(),
106 false, false, true);
107 }
108
109 public void testSoapBodyElementWithAxisApi() throws Exception
110 {
111 doSoapRequest(new QName("http://muleumo.org", "soapBodyElement"), getServiceEndpoint(), true, false,
112 false);
113 }
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131 public void testSoapRequestResponseWithAxisApi() throws Exception
132 {
133 doSoapRequest(new QName("http://muleumo.org", "soapRequestResponse"), getServiceEndpoint(), true,
134 false, false);
135 }
136
137 protected void doSoapRequest(QName method,
138 String endpoint,
139 boolean useAxisApi,
140 boolean useSoapMethod,
141 boolean useQNameMethod) throws Exception
142 {
143
144 if (useAxisApi)
145 {
146 Service service = new Service();
147 Call call = (Call)service.createCall();
148 call.setTargetEndpointAddress(new java.net.URL(endpoint));
149 call.setOperationName(method);
150 String ret = (String)call.invoke(new Object[]{expectedResult});
151 assertNotNull(ret);
152 assertEquals(ret, expectedResult);
153 }
154 else
155 {
156
157
158 MuleClient client = new MuleClient();
159 Map props = new HashMap();
160 if (useSoapMethod)
161 {
162 SoapMethod soapMethod = new SoapMethod(method);
163 soapMethod.addNamedParameter(new QName(method.getNamespaceURI(), method.getLocalPart()),
164 NamedParameter.XSD_STRING, ParameterMode.IN);
165 props.put(MuleProperties.MULE_METHOD_PROPERTY, soapMethod);
166 }
167 else if (useQNameMethod)
168 {
169 props.put(MuleProperties.MULE_METHOD_PROPERTY, method);
170 }
171 else
172 {
173 endpoint += "?method=" + method.getLocalPart();
174 if (StringUtils.isNotBlank(method.getNamespaceURI()))
175 {
176 props.put("methodNamespace", method.getNamespaceURI());
177 }
178 }
179
180 MuleMessage result = client.send(endpoint, expectedResult, props);
181 assertNotNull(result);
182 assertEquals(expectedResult, result.getPayloadAsString());
183 }
184 }
185
186 }