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.DynamicPortTestCase;
17 import org.mule.transport.soap.axis.NamedParameter;
18 import org.mule.transport.soap.axis.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 DynamicPortTestCase
31 {
32 private static String expectedResult = "TEST RESPONSE";
33
34 @Override
35 public String getConfigResources()
36 {
37 return "style/axis-mule-message-config.xml";
38 }
39
40 protected String getServiceEndpoint()
41 {
42 return "http://localhost:" + getPorts().get(0) + "/ServiceEntryPoint";
43 }
44
45 public void testDocumentWithNamespace() throws Exception
46 {
47 doSoapRequest(new QName("http://muleumo.org", "document"), "axis:" + getServiceEndpoint(), false,
48 false, false);
49 }
50
51 public void testDocumentWithQName() throws Exception
52 {
53 doSoapRequest(new QName("http://muleumo.org", "document"), "axis:" + getServiceEndpoint(), false,
54 false, true);
55 }
56
57 public void testDocumentWithAxisApi() throws Exception
58 {
59 doSoapRequest(new QName("http://muleumo.org", "document"), getServiceEndpoint(), true, false, false);
60 }
61
62 public void testDocumentWithSoapMethod() throws Exception
63 {
64 doSoapRequest(new QName("http://muleumo.org", "document"), "axis:" + getServiceEndpoint(), false,
65 true, false);
66 }
67
68 public void testElementArrayWithSoapMethod() throws Exception
69 {
70 doSoapRequest(new QName("http://muleumo.org", "elementArray"), "axis:" + getServiceEndpoint(), false,
71 true, false);
72 }
73
74 public void testElementArrayWithNamesapce() throws Exception
75 {
76 doSoapRequest(new QName("http://muleumo.org", "elementArray"), "axis:" + getServiceEndpoint(), false,
77 false, false);
78 }
79
80 public void testElementArrayWithQName() throws Exception
81 {
82 doSoapRequest(new QName("http://muleumo.org", "elementArray"), "axis:" + getServiceEndpoint(), false,
83 false, true);
84 }
85
86 public void testElementArrayWithAxisApi() throws Exception
87 {
88 doSoapRequest(new QName("http://muleumo.org", "elementArray"), getServiceEndpoint(), true, false,
89 false);
90 }
91
92 public void testSoapBodyElementWithSoapMethod() throws Exception
93 {
94 doSoapRequest(new QName("http://muleumo.org", "soapBodyElement"), "axis:" + getServiceEndpoint(),
95 false, true, false);
96 }
97
98 public void testSoapBodyElementWithNamesapce() throws Exception
99 {
100 doSoapRequest(new QName("http://muleumo.org", "soapBodyElement"), "axis:" + getServiceEndpoint(),
101 false, false, false);
102 }
103
104 public void testSoapBodyElementWithQName() throws Exception
105 {
106 doSoapRequest(new QName("http://muleumo.org", "soapBodyElement"), "axis:" + getServiceEndpoint(),
107 false, false, true);
108 }
109
110 public void testSoapBodyElementWithAxisApi() throws Exception
111 {
112 doSoapRequest(new QName("http://muleumo.org", "soapBodyElement"), getServiceEndpoint(), true, false,
113 false);
114 }
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132 public void testSoapRequestResponseWithAxisApi() throws Exception
133 {
134 doSoapRequest(new QName("http://muleumo.org", "soapRequestResponse"), getServiceEndpoint(), true,
135 false, false);
136 }
137
138 protected void doSoapRequest(QName method,
139 String endpoint,
140 boolean useAxisApi,
141 boolean useSoapMethod,
142 boolean useQNameMethod) throws Exception
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(muleContext);
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 @Override
187 protected int getNumPortsToFind()
188 {
189 return 1;
190 }
191
192 }