01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19:
20: package org.apache.axis2.saaj;
21:
22: import junit.framework.TestCase;
23:
24: import javax.xml.soap.DetailEntry;
25: import javax.xml.soap.MessageFactory;
26: import javax.xml.soap.MimeHeaders;
27: import javax.xml.soap.SOAPBody;
28: import javax.xml.soap.SOAPFault;
29: import javax.xml.soap.SOAPMessage;
30: import java.io.ByteArrayInputStream;
31: import java.util.Iterator;
32:
33: public class SOAPFaultDetailTest extends TestCase {
34:
35: public SOAPFaultDetailTest(String name) {
36: super (name);
37: }
38:
39: private String xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
40: + "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
41: + " <soapenv:Body>"
42: + " <soapenv:Fault>"
43: + " <faultcode>soapenv:Server.generalException</faultcode>"
44: + " <faultstring></faultstring>"
45: + " <detail>"
46: + " <tickerSymbol xsi:type=\"xsd:string\">MACR</tickerSymbol>"
47: + " <ns1:exceptionName xmlns:ns1=\"http://xml.apache.org/axis2/\">test.wsdl.faults.InvalidTickerFaultMessage</ns1:exceptionName>"
48: + " </detail>"
49: + " </soapenv:Fault>"
50: + " </soapenv:Body>" + "</soapenv:Envelope>";
51:
52: public void testDetails() throws Exception {
53: MessageFactory mf = MessageFactory.newInstance();
54: SOAPMessage smsg = mf.createMessage(new MimeHeaders(),
55: new ByteArrayInputStream(xmlString.getBytes()));
56: SOAPBody body = smsg.getSOAPBody();
57: //smsg.writeTo(System.out);
58: SOAPFault fault = body.getFault();
59: fault.addDetail();
60: javax.xml.soap.Detail d = fault.getDetail();
61: Iterator i = d.getDetailEntries();
62: while (i.hasNext()) {
63: DetailEntry entry = (DetailEntry) i.next();
64: String name = entry.getElementName().getLocalName();
65: if ("tickerSymbol".equals(name)) {
66: assertEquals(
67: "the value of the tickerSymbol element didn't match",
68: "MACR", entry.getValue());
69: } else if ("exceptionName".equals(name)) {
70: assertEquals(
71: "the value of the exceptionName element didn't match",
72: "test.wsdl.faults.InvalidTickerFaultMessage",
73: entry.getValue());
74: } else {
75: assertTrue(
76: "Expecting details element name of 'tickerSymbol' or "
77: + "'expceptionName' - I found :" + name,
78: false);
79: }
80: }
81: }
82: }
|