1   /*
2    * Copyright 2005-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }