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