KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > soap > impl > llom > builder > StAXSOAPModelBuilderTest


1 package org.apache.axis2.soap.impl.llom.builder;
2
3 import junit.framework.TestCase;
4 import org.apache.axis2.om.OMAttribute;
5 import org.apache.axis2.om.OMElement;
6 import org.apache.axis2.om.OMXMLParserWrapper;
7 import org.apache.axis2.soap.*;
8 import org.apache.axis2.soap.impl.llom.SOAPConstants;
9 import org.apache.axis2.soap.impl.llom.soap11.SOAP11Constants;
10 import org.apache.axis2.soap.impl.llom.soap12.SOAP12Constants;
11
12 import javax.xml.stream.XMLInputFactory;
13 import javax.xml.stream.XMLStreamException;
14 import javax.xml.stream.XMLStreamReader;
15 import java.io.StringReader JavaDoc;
16 import java.util.Iterator JavaDoc;
17
18 /**
19  * Created by IntelliJ IDEA.
20  * User: Anushka
21  * Date: Jun 3, 2005
22  * Time: 10:22:26 AM
23  * To change this template use File | Settings | File Templates.
24  */

25 public class StAXSOAPModelBuilderTest extends TestCase {
26
27     public void setUp() {
28
29     }
30
31     public void testStAXSOAPModelBuilder() {
32         String JavaDoc soap12Message =
33                 "<env:Envelope xmlns:env=\"http://www.w3.org/2003/05/soap-envelope\">\n" +
34                 " <env:Header>\n" +
35                 " <test:echoOk xmlns:test=\"http://example.org/ts-tests\"\n" +
36                 " env:role=\"http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver\"\n" +
37                 " env:mustUnderstand=\"true\">\n" +
38                 " foo\n" +
39                 " </test:echoOk>\n" +
40                 " </env:Header>\n" +
41                 " <env:Body>\n" +
42                 " <env:Fault>\n" +
43                 " <env:Code>\n" +
44                 " <env:Value>env:Sender</env:Value>\n" +
45                 " <env:SubCode>\n" +
46                 " <env:Value>m:MessageTimeout</env:Value>\n" +
47                 " <env:SubCode>\n" +
48                 " <env:Value>m:MessageTimeout</env:Value>\n" +
49                 " </env:SubCode>\n" +
50                 " </env:SubCode>\n" +
51                 " </env:Code>\n" +
52                 " <env:Reason>\n" +
53                 " <env:Text>Sender Timeout</env:Text>\n" +
54                 " </env:Reason>\n" +
55                 " <env:Node>\n" +
56                 " http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver\n" +
57                 " </env:Node>\n" +
58                 " <env:Role>\n" +
59                 " ultimateReceiver\n" +
60                 " </env:Role>\n" +
61                 " <env:Detail xmlns:m=\"http:www.sample.org\">\n" +
62                 " Details of error\n" +
63                 " <m:MaxTime m:detail=\"This is only a test\">\n" +
64                 " P5M\n" +
65                 " </m:MaxTime>\n" +
66                 " <m:AveTime>\n" +
67                 " <m:Time>\n" +
68                 " P3M\n" +
69                 " </m:Time>\n" +
70                 " </m:AveTime>\n" +
71                 " </env:Detail>\n" +
72                 " </env:Fault>\n" +
73                 " </env:Body>\n" +
74                 "</env:Envelope>";
75
76         String JavaDoc soap11Message =
77                 "<?xml version='1.0' ?>" +
78                 "<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
79                 " <env:Header>\n" +
80                 " <test:echoOk xmlns:test=\"http://example.org/ts-tests\"\n" +
81                 " env:actor=\"http://schemas.xmlsoap.org/soap/actor/next\"\n" +
82                 " env:mustUnderstand=\"1\"" +
83                 " >\n" +
84                 " foo\n" +
85                 " </test:echoOk>\n" +
86                 " </env:Header>\n" +
87                 " <env:Body>\n" +
88                 " <env:Fault>\n" +
89                 " <env:faultcode>\n" +
90                 " env:Sender\n" +
91                 " </env:faultcode>\n" +
92                 " <env:faultstring>\n" +
93                 " Sender Timeout\n" +
94                 " </env:faultstring>\n" +
95                 " <env:faultactor>\n" +
96                 " http://schemas.xmlsoap.org/soap/envelope/actor/ultimateReceiver\n" +
97                 " </env:faultactor>\n" +
98                 " <env:detail xmlns:m=\"http:www.sample.org\">\n" +
99                 " Details of error\n" +
100                 " <m:MaxTime m:detail=\"This is only a test\">\n" +
101                 " P5M\n" +
102                 " </m:MaxTime>\n" +
103                 " <m:AveTime>\n" +
104                 " <m:Time>\n" +
105                 " P3M\n" +
106                 " </m:Time>\n" +
107                 " </m:AveTime>\n" +
108                 " </env:detail>\n" +
109                 " <n:Test xmlns:n=\"http:www.Test.org\">\n" +
110                 " <n:TestElement>\n" +
111                 " This is only a test\n" +
112                 " </n:TestElement>\n" +
113                 " </n:Test>\n" +
114                 " </env:Fault>\n" +
115                 " </env:Body>\n" +
116                 "</env:Envelope>";
117
118
119         try {
120             XMLStreamReader sopa12Parser = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader JavaDoc(soap12Message));
121             OMXMLParserWrapper soap12Builder = new StAXSOAPModelBuilder(sopa12Parser);
122             SOAPEnvelope soap12Envelope = (SOAPEnvelope) soap12Builder.getDocumentElement();
123 // soap12Envelope.build();
124
// XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(System.out);
125
// soap12Envelope.serialize(writer);
126
// writer.flush();
127

128             assertTrue("SOAP 1.2 :- envelope local name mismatch", soap12Envelope.getLocalName().equals(SOAPConstants.SOAPENVELOPE_LOCAL_NAME));
129             assertTrue("SOAP 1.2 :- envelope namespace uri mismatch", soap12Envelope.getNamespace().getName().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
130
131             SOAPHeader header = soap12Envelope.getHeader();
132             assertTrue("SOAP 1.2 :- Header local name mismatch", header.getLocalName().equals(SOAPConstants.HEADER_LOCAL_NAME));
133             assertTrue("SOAP 1.2 :- Header namespace uri mismatch", header.getNamespace().getName().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
134
135             SOAPHeaderBlock headerBlock = (SOAPHeaderBlock) header.getFirstElement();
136             assertTrue("SOAP 1.2 :- Header block name mismatch", headerBlock.getLocalName().equals("echoOk"));
137             assertTrue("SOAP 1.2 :- Header block name space uri mismatch", headerBlock.getNamespace().getName().equals("http://example.org/ts-tests"));
138             assertTrue("SOAP 1.2 :- Headaer block text mismatch", headerBlock.getText().equals("foo"));
139
140             Iterator JavaDoc headerBlockAttributes = headerBlock.getAttributes();
141             OMAttribute roleAttribute = (OMAttribute) headerBlockAttributes.next();
142             assertTrue("SOAP 1.2 :- Role attribute name mismatch", roleAttribute.getLocalName().equals(SOAP12Constants.SOAP_ROLE));
143             assertTrue("SOAP 1.2 :- Role value mismatch", roleAttribute.getValue().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI + "/" + SOAP12Constants.SOAP_ROLE + "/" + "ultimateReceiver"));
144             assertTrue("SOAP 1.2 :- Role attribute namespace uri mismatch", roleAttribute.getNamespace().getName().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
145
146             OMAttribute mustUnderstandAttribute = (OMAttribute) headerBlockAttributes.next();
147             assertTrue("SOAP 1.2 :- Mustunderstand attribute name mismatch", mustUnderstandAttribute.getLocalName().equals(SOAPConstants.ATTR_MUSTUNDERSTAND));
148             assertTrue("SOAP 1.2 :- Mustunderstand value mismatch", mustUnderstandAttribute.getValue().equals(SOAPConstants.ATTR_MUSTUNDERSTAND_TRUE));
149             assertTrue("SOAP 1.2 :- Mustunderstand attribute namespace uri mismatch", mustUnderstandAttribute.getNamespace().getName().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
150
151             SOAPBody body = soap12Envelope.getBody();
152             assertTrue("SOAP 1.2 :- Body local name mismatch", body.getLocalName().equals(SOAPConstants.BODY_LOCAL_NAME));
153             assertTrue("SOAP 1.2 :- Body namespace uri mismatch", body.getNamespace().getName().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
154
155             SOAPFault fault = body.getFault();
156             assertTrue("SOAP 1.2 :- Fault local name mismatch", fault.getLocalName().equals(SOAPConstants.SOAPFAULT_LOCAL_NAME));
157             assertTrue("SOAP 1.2 :- Fault namespace uri mismatch", fault.getNamespace().getName().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
158
159             Iterator JavaDoc iteratorInFault = fault.getChildren();
160
161             iteratorInFault.next();
162             SOAPFaultCode code = (SOAPFaultCode) iteratorInFault.next();
163             assertTrue("SOAP 1.2 :- Fault code local name mismatch", code.getLocalName().equals(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME));
164             assertTrue("SOAP 1.2 :- Fault code namespace uri mismatch", code.getNamespace().getName().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
165
166             Iterator JavaDoc iteratorInCode = code.getChildren();
167
168             iteratorInCode.next();
169             SOAPFaultValue value1 = (SOAPFaultValue) iteratorInCode.next();
170             assertTrue("SOAP 1.2 :- Fault code value local name mismatch", value1.getLocalName().equals(SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME));
171             assertTrue("SOAP 1.2 :- Fault code namespace uri mismatch", value1.getNamespace().getName().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
172             assertTrue("SOAP 1.2 :- Value1 text mismatch", value1.getText().equals("env:Sender"));
173
174             iteratorInCode.next();
175             SOAPFaultSubCode subCode1 = (SOAPFaultSubCode) iteratorInCode.next();
176             assertTrue("SOAP 1.2 :- Fault sub code local name mismatch", subCode1.getLocalName().equals(SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME));
177             assertTrue("SOAP 1.2 :- Fault subcode namespace uri mismatch", subCode1.getNamespace().getName().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
178
179             Iterator JavaDoc iteratorInSubCode1 = subCode1.getChildren();
180
181             iteratorInSubCode1.next();
182             SOAPFaultValue value2 = (SOAPFaultValue) iteratorInSubCode1.next();
183             assertTrue("SOAP 1.2 :- Fault code value local name mismatch", value2.getLocalName().equals(SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME));
184             assertTrue("SOAP 1.2 :- Fault code namespace uri mismatch", value2.getNamespace().getName().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
185             assertTrue("SOAP 1.2 :- Value2 text mismatch", value2.getText().equals("m:MessageTimeout"));
186
187             iteratorInSubCode1.next();
188             SOAPFaultSubCode subCode2 = (SOAPFaultSubCode) iteratorInSubCode1.next();
189             assertTrue("SOAP 1.2 :- Fault sub code local name mismatch", subCode2.getLocalName().equals(SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME));
190             assertTrue("SOAP 1.2 :- Fault subcode namespace uri mismatch", subCode2.getNamespace().getName().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
191
192             Iterator JavaDoc iteratorInSubCode2 = subCode2.getChildren();
193
194             iteratorInSubCode2.next();
195             SOAPFaultValue value3 = (SOAPFaultValue) iteratorInSubCode2.next();
196             assertTrue("SOAP 1.2 :- Fault code value local name mismatch", value3.getLocalName().equals(SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME));
197             assertTrue("SOAP 1.2 :- Fault code namespace uri mismatch", value3.getNamespace().getName().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
198             assertTrue("SOAP 1.2 :- Value2 text mismatch", value3.getText().equals("m:MessageTimeout"));
199
200             iteratorInFault.next();
201             SOAPFaultReason reason = (SOAPFaultReason) iteratorInFault.next();
202             assertTrue("SOAP 1.2 :- Fault reason local name mismatch", reason.getLocalName().equals(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME));
203             assertTrue("SOAP 1.2 :- Fault reason namespace uri mismatch", reason.getNamespace().getName().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
204
205             Iterator JavaDoc iteratorInReason = reason.getChildren();
206
207             iteratorInReason.next();
208             SOAPFaultText text = (SOAPFaultText) iteratorInReason.next();
209             assertTrue("SOAP 1.2 :- Fault text local name mismatch", text.getLocalName().equals(SOAP12Constants.SOAP_FAULT_TEXT_LOCAL_NAME));
210             assertTrue("SOAP 1.2 :- Text namespace uri mismatch", text.getNamespace().getName().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
211             assertTrue("SOAP 1.2 :- Text value mismatch", text.getText().equals("Sender Timeout"));
212
213             iteratorInFault.next();
214             SOAPFaultNode node = (SOAPFaultNode) iteratorInFault.next();
215             assertTrue("SOAP 1.2 :- Fault node local name mismatch", node.getLocalName().equals(SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME));
216             assertTrue("SOAP 1.2 :- Fault node namespace uri mismatch", node.getNamespace().getName().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
217             assertTrue("SOAP 1.2 :- Node value mismatch", node.getText().equals("http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver"));
218
219             iteratorInFault.next();
220             SOAPFaultRole role = (SOAPFaultRole) iteratorInFault.next();
221             assertTrue("SOAP 1.2 :- Fault role local name mismatch", role.getLocalName().equals(SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME));
222             assertTrue("SOAP 1.2 :- Fault role namespace uri mismatch", role.getNamespace().getName().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
223             assertTrue("SOAP 1.2 :- Role value mismatch", role.getText().equals("ultimateReceiver"));
224
225             iteratorInFault.next();
226             SOAPFaultDetail detail = (SOAPFaultDetail) iteratorInFault.next();
227             assertTrue("SOAP 1.2 :- Fault detail local name mismatch", detail.getLocalName().equals(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME));
228             assertTrue("SOAP 1.2 :- Fault detail namespace uri mismatch", detail.getNamespace().getName().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
229
230             assertTrue("SOAP 1.2 :- Text in detail mismatch",detail.getText().equals("Details of error"));
231
232             Iterator JavaDoc iteratorInDetail = detail.getChildren();
233
234             iteratorInDetail.next();
235             OMElement element1 = (OMElement)iteratorInDetail.next();
236             assertTrue("SOAP 1.2 :- MaxTime element mismatch",element1.getLocalName().equals("MaxTime"));
237             assertTrue("SOAP 1.2 :- MaxTime element namespace mismatch",element1.getNamespace().getName().equals("http:www.sample.org"));
238             assertTrue("SOAP 1.2 :- Text value in MaxTime element mismatch",element1.getText().equals("P5M"));
239
240             Iterator JavaDoc attributeIterator = element1.getAttributes();
241             OMAttribute attributeInMaxTime = (OMAttribute)attributeIterator.next();
242             assertTrue("SOAP 1.2 :- Attribute local name mismatch",attributeInMaxTime.getLocalName().equals("detail"));
243             assertTrue("SOAP 1.2 :- Attribute namespace mismatch",attributeInMaxTime.getNamespace().getName().equals("http:www.sample.org"));
244             assertTrue("SOAP 1.2 :- Attribute value mismatch",attributeInMaxTime.getValue().equals("This is only a test"));
245
246             iteratorInDetail.next();
247             OMElement element2 = (OMElement)iteratorInDetail.next();
248             assertTrue("SOAP 1.2 :- AveTime element mismatch",element2.getLocalName().equals("AveTime"));
249             assertTrue("SOAP 1.2 :- AveTime element namespace mismatch",element2.getNamespace().getName().equals("http:www.sample.org"));
250
251             Iterator JavaDoc iteratorInAveTimeElement = element2.getChildren();
252
253             iteratorInAveTimeElement.next();
254             OMElement element21 = (OMElement)iteratorInAveTimeElement.next();
255             assertTrue("SOAP 1.2 :- Time element mismatch",element21.getLocalName().equals("Time"));
256             assertTrue("SOAP 1.2 :- Time element namespace mismatch",element21.getNamespace().getName().equals("http:www.sample.org"));
257             assertTrue("SOAP 1.2 :- Text value in Time element mismatch",element21.getText().equals("P3M"));
258
259             XMLStreamReader sopa11Parser = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader JavaDoc(soap11Message));
260             OMXMLParserWrapper soap11Builder = new StAXSOAPModelBuilder(sopa11Parser);
261             SOAPEnvelope soap11Envelope = (SOAPEnvelope) soap11Builder.getDocumentElement();
262 // soap11Envelope.build();
263
// writer = XMLOutputFactory.newInstance().createXMLStreamWriter(System.out);
264
// soap11Envelope.serialize(writer);
265
// writer.flush();
266

267             assertTrue("SOAP 1.1 :- envelope local name mismatch", soap11Envelope.getLocalName().equals(SOAPConstants.SOAPENVELOPE_LOCAL_NAME));
268             assertTrue("SOAP 1.1 :- envelope namespace uri mismatch", soap11Envelope.getNamespace().getName().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));
269
270             header = soap11Envelope.getHeader();
271             assertTrue("SOAP 1.1 :- Header local name mismatch", header.getLocalName().equals(SOAPConstants.HEADER_LOCAL_NAME));
272             assertTrue("SOAP 1.1 :- Header namespace uri mismatch", header.getNamespace().getName().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));
273
274             headerBlock = (SOAPHeaderBlock) header.getFirstElement();
275             assertTrue("SOAP 1.1 :- Header block name mismatch", headerBlock.getLocalName().equals("echoOk"));
276             assertTrue("SOAP 1.1 :- Header block name space uri mismatch", headerBlock.getNamespace().getName().equals("http://example.org/ts-tests"));
277             assertTrue("SOAP 1.1 :- Headaer block text mismatch", headerBlock.getText().equals("foo"));
278
279             headerBlockAttributes = headerBlock.getAttributes();
280
281             mustUnderstandAttribute = (OMAttribute) headerBlockAttributes.next();
282             assertTrue("SOAP 1.1 :- Mustunderstand attribute name mismatch", mustUnderstandAttribute.getLocalName().equals(SOAPConstants.ATTR_MUSTUNDERSTAND));
283             assertTrue("SOAP 1.1 :- Mustunderstand value mismatch", mustUnderstandAttribute.getValue().equals(SOAPConstants.ATTR_MUSTUNDERSTAND_1));
284             assertTrue("SOAP 1.1 :- Mustunderstand attribute namespace uri mismatch", mustUnderstandAttribute.getNamespace().getName().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));
285
286             OMAttribute actorAttribute = (OMAttribute) headerBlockAttributes.next();
287             assertTrue("SOAP 1.1 :- Actor attribute name mismatch", actorAttribute.getLocalName().equals(SOAP11Constants.ATTR_ACTOR));
288             assertTrue("SOAP 1.1 :- Actor value mismatch", actorAttribute.getValue().equals("http://schemas.xmlsoap.org/soap/" + SOAP11Constants.ATTR_ACTOR + "/" + "next"));
289             assertTrue("SOAP 1.1 :- Actor attribute namespace uri mismatch", actorAttribute.getNamespace().getName().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));
290
291             body = soap11Envelope.getBody();
292             assertTrue("SOAP 1.1 :- Body local name mismatch", body.getLocalName().equals(SOAPConstants.BODY_LOCAL_NAME));
293             assertTrue("SOAP 1.1 :- Body namespace uri mismatch", body.getNamespace().getName().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));
294
295             fault = body.getFault();
296             assertTrue("SOAP 1.1 :- Fault namespace uri mismatch", fault.getNamespace().getName().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));
297
298             iteratorInFault = fault.getChildren();
299
300             iteratorInFault.next();
301             code = (SOAPFaultCode) iteratorInFault.next();
302             assertEquals("SOAP Fault code local name mismatch", code.getLocalName(), (SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME));
303             assertTrue("SOAP 1.1 :- Fault code namespace uri mismatch", code.getNamespace().getName().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));
304             assertEquals("SOAP 1.1 :- Fault code value mismatch",code.getValue().getText().trim(), "env:Sender");
305
306             iteratorInFault.next();
307             reason = (SOAPFaultReason) iteratorInFault.next();
308             assertTrue("SOAP 1.1 :- Fault string local name mismatch", reason.getLocalName().equals(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME));
309             assertTrue("SOAP 1.2 :- Fault string namespace uri mismatch", reason.getNamespace().getName().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));
310             assertTrue("SOAP 1.1 :- Fault string value mismatch",reason.getSOAPText().getText().equals("Sender Timeout"));
311
312             iteratorInFault.next();
313             role = (SOAPFaultRole) iteratorInFault.next();
314             assertTrue("SOAP 1.1 :- Fault actor local name mismatch", role.getLocalName().equals(SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME));
315             assertTrue("SOAP 1.1 :- Fault actor namespace uri mismatch", role.getNamespace().getName().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));
316             assertTrue("SOAP 1.1 :- Actor value mismatch", role.getText().equals("http://schemas.xmlsoap.org/soap/envelope/actor/ultimateReceiver"));
317
318             iteratorInFault.next();
319             detail = (SOAPFaultDetail) iteratorInFault.next();
320             assertTrue("SOAP 1.1 :- Fault detail local name mismatch", detail.getLocalName().equals(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME));
321             assertTrue("SOAP 1.1 :- Fault detail namespace uri mismatch", detail.getNamespace().getName().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));
322             assertTrue("SOAP 1.2 :- Text in detail mismatch",detail.getText().equals("Details of error"));
323
324             iteratorInDetail = detail.getChildren();
325
326             iteratorInDetail.next();
327             element1 = (OMElement)iteratorInDetail.next();
328             assertTrue("SOAP 1.1 :- MaxTime element mismatch",element1.getLocalName().equals("MaxTime"));
329             assertTrue("SOAP 1.1 :- MaxTime element namespace mismatch",element1.getNamespace().getName().equals("http:www.sample.org"));
330             assertTrue("SOAP 1.1 :- Text value in MaxTime element mismatch",element1.getText().equals("P5M"));
331
332             attributeIterator = element1.getAttributes();
333             attributeInMaxTime = (OMAttribute)attributeIterator.next();
334             assertTrue("SOAP 1.1 :- Attribute local name mismatch",attributeInMaxTime.getLocalName().equals("detail"));
335             assertTrue("SOAP 1.1 :- Attribute namespace mismatch",attributeInMaxTime.getNamespace().getName().equals("http:www.sample.org"));
336             assertTrue("SOAP 1.1 :- Attribute value mismatch",attributeInMaxTime.getValue().equals("This is only a test"));
337
338             iteratorInDetail.next();
339             element2 = (OMElement)iteratorInDetail.next();
340             assertTrue("SOAP 1.1 :- AveTime element mismatch",element2.getLocalName().equals("AveTime"));
341             assertTrue("SOAP 1.1 :- AveTime element namespace mismatch",element2.getNamespace().getName().equals("http:www.sample.org"));
342
343             iteratorInAveTimeElement = element2.getChildren();
344
345             iteratorInAveTimeElement.next();
346             element21 = (OMElement)iteratorInAveTimeElement.next();
347             assertTrue("SOAP 1.1 :- Time element mismatch",element21.getLocalName().equals("Time"));
348             assertTrue("SOAP 1.1 :- Time element namespace mismatch",element21.getNamespace().getName().equals("http:www.sample.org"));
349             assertTrue("SOAP 1.1 :- Text value in Time element mismatch",element21.getText().equals("P3M"));
350
351            iteratorInFault.next();
352             OMElement testElement = (OMElement)iteratorInFault.next();
353             assertTrue("SOAP 1.1 :- Test element mismatch",testElement.getLocalName().equals("Test"));
354             assertTrue("SOAP 1.1 :- Test element namespace mismatch",testElement.getNamespace().getName().equals("http:www.Test.org"));
355
356             OMElement childOfTestElement = testElement.getFirstElement();
357             assertTrue("SOAP 1.1 :- Test element child local name mismatch",childOfTestElement.getLocalName().equals("TestElement"));
358             assertTrue("SOAP 1.1 :- Test element child namespace mismatch",childOfTestElement.getNamespace().getName().equals("http:www.Test.org"));
359             assertTrue("SOAP 1.1 :- Test element child value mismatch",childOfTestElement.getText().equals("This is only a test"));
360
361         } catch (XMLStreamException e) {
362             e.printStackTrace();
363             fail("Test failed. Reason -> "+e.getMessage());
364         } catch (Exception JavaDoc e) {
365             e.printStackTrace();
366             fail("Test failed. Reason -> "+e.getMessage());
367
368         }
369     }
370 }
371
Popular Tags