Debian Codegraph @

test/saaj/TestSOAPFaultDetail.java

raw
1
2 package test.saaj;
3
4 import org.apache.axis.Message;
5 import org.apache.axis.MessageContext;
6 import org.apache.axis.server.AxisServer;
7 import org.apache.axis.message.SOAPBodyElement;
8 import org.apache.axis.message.SOAPFault;
9 import org.apache.axis.message.SOAPEnvelope;
10 import org.apache.axis.encoding.DeserializationContext;
11 import org.xml.sax.InputSource;
12
13 import javax.xml.soap.DetailEntry;
14 import java.io.Reader;
15 import java.io.StringReader;
16 import java.util.Iterator;
17
18 public class TestSOAPFaultDetail extends junit.framework.TestCase
19 {
20 private MessageContext _msgContext;
21
22 public TestSOAPFaultDetail(String name)
23 {
24 super(name);
25 _msgContext = new MessageContext(new AxisServer());
26 }
27
28 String xmlString =
29 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
30 "<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\">" +
31 " <soapenv:Body>" +
32 " <soapenv:Fault>" +
33 " <faultcode>soapenv:Server.generalException</faultcode>" +
34 " <faultstring></faultstring>" +
35 " <detail>" +
36 " <tickerSymbol xsi:type=\"xsd:string\">MACR</tickerSymbol>" +
37 " <ns1:exceptionName xmlns:ns1=\"http://xml.apache.org/axis/\">test.wsdl.faults.InvalidTickerFaultMessage</ns1:exceptionName>" +
38 " </detail>" +
39 " </soapenv:Fault>" +
40 " </soapenv:Body>" +
41 "</soapenv:Envelope>";
42
43
44 public void testDetails() throws Exception
45 {
46 Reader reader = new StringReader(xmlString);
47 InputSource src = new InputSource(reader);
48 SOAPBodyElement bodyItem = getFirstBody(src);
49 assertTrue("The SOAPBodyElement I got was not a SOAPFault, it was a " +
50 bodyItem.getClass().getName(), bodyItem instanceof SOAPFault);
51 SOAPFault flt = (SOAPFault)bodyItem;
52 flt.addDetail();
53 javax.xml.soap.Detail d = flt.getDetail();
54 Iterator i = d.getDetailEntries();
55 while (i.hasNext())
56 {
57 DetailEntry entry = (DetailEntry) i.next();
58 String name = entry.getElementName().getLocalName();
59 if ("tickerSymbol".equals(name)) {
60 assertEquals("the value of the tickerSymbol element didn't match",
61 "MACR", entry.getValue());
62 } else if ("exceptionName".equals(name)) {
63 assertEquals("the value of the exceptionName element didn't match",
64 "test.wsdl.faults.InvalidTickerFaultMessage", entry.getValue());
65 } else {
66 assertTrue("Expecting details element name of 'tickerSymbol' or 'expceptionName' - I found :" + name, false);
67 }
68 }
69 assertTrue(d != null);
70 }
71
72 private SOAPBodyElement getFirstBody(InputSource msgSource)
73 throws Exception
74 {
75 DeserializationContext dser = new DeserializationContext(
76 msgSource, _msgContext, Message.RESPONSE);
77 dser.parse();
78 SOAPEnvelope env = dser.getEnvelope();
79
80 return env.getFirstBody();
81 }
82
83 /**
84 * Main
85 */
86 public static void main(String[] args)
87 throws Exception
88 {
89 TestSOAPFaultDetail detailTest = new TestSOAPFaultDetail("faultdetails");
90 detailTest.testDetails();
91 }
92
93 }