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