1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.soap.axiom;
18
19 import java.io.StringReader;
20 import javax.xml.stream.XMLInputFactory;
21 import javax.xml.stream.XMLStreamReader;
22
23 import org.springframework.ws.soap.SoapFault;
24 import org.springframework.ws.soap.SoapFaultDetail;
25
26 import org.apache.axiom.soap.SOAPMessage;
27 import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
28 import org.junit.Assert;
29 import org.junit.Before;
30 import org.junit.Test;
31
32 @SuppressWarnings("Since15")
33 public class AxiomSoapFaultDetailTest {
34
35 private static final String FAILING_FAULT =
36 "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
37 "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
38 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n " + "<soapenv:Body>\n " +
39 "<soapenv:Fault>\n " + "<faultcode>Client</faultcode>\n " +
40 "<faultstring>Client Error</faultstring>\n " + "<detail>\n " +
41 "<ns1:dispositionReport xmlns:ns1=\"urn:uddi-org:api_v3\">\n " +
42 "<ns1:result errno=\"10210\"/>\n " + "</ns1:dispositionReport>" + "</detail>" +
43 "</soapenv:Fault>" + "</soapenv:Body>" + "</soapenv:Envelope>";
44
45 private static final String SUCCEEDING_FAULT =
46 "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
47 "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
48 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n " + "<soapenv:Body>\n " +
49 "<soapenv:Fault>\n " + "<faultcode>Client</faultcode>\n " +
50 "<faultstring>Client Error</faultstring>\n " + "<detail>" +
51 "<ns1:dispositionReport xmlns:ns1=\"urn:uddi-org:api_v3\">\n " +
52 "<ns1:result errno=\"10210\"/>\n " + "</ns1:dispositionReport>" + "</detail>" +
53 "</soapenv:Fault>" + "</soapenv:Body>" + "</soapenv:Envelope>";
54
55 private AxiomSoapMessage failingMessage;
56
57 private AxiomSoapMessage succeedingMessage;
58
59 @Before
60 public void setUp() throws Exception {
61 XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(FAILING_FAULT));
62 StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(parser);
63 SOAPMessage soapMessage = builder.getSoapMessage();
64
65 failingMessage = new AxiomSoapMessage(soapMessage, null, false, true);
66
67 parser = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(SUCCEEDING_FAULT));
68 builder = new StAXSOAPModelBuilder(parser);
69 soapMessage = builder.getSoapMessage();
70
71 succeedingMessage = new AxiomSoapMessage(soapMessage, null, false, true);
72
73 }
74
75 @Test
76 public void testGetDetailEntriesWorksWithWhitespaceNodes() throws Exception {
77 SoapFault fault = failingMessage.getSoapBody().getFault();
78 Assert.assertNotNull("Fault is null", fault);
79 Assert.assertNotNull("Fault detail is null", fault.getFaultDetail());
80 SoapFaultDetail detail = fault.getFaultDetail();
81 Assert.assertTrue("No next detail entry present", detail.getDetailEntries().hasNext());
82 detail.getDetailEntries().next();
83
84 }
85
86 @Test
87 public void testGetDetailEntriesWorksWithoutWhitespaceNodes() throws Exception {
88 SoapFault fault = succeedingMessage.getSoapBody().getFault();
89 Assert.assertNotNull("Fault is null", fault);
90 Assert.assertNotNull("Fault detail is null", fault.getFaultDetail());
91 SoapFaultDetail detail = fault.getFaultDetail();
92 Assert.assertTrue("No next detail entry present", detail.getDetailEntries().hasNext());
93 detail.getDetailEntries().next();
94 }
95
96 }