1   /*
2    * Copyright 2007 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 junit.framework.TestCase;
24  import org.apache.axiom.soap.SOAPMessage;
25  import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
26  
27  import org.springframework.ws.soap.SoapFault;
28  import org.springframework.ws.soap.SoapFaultDetail;
29  
30  public class AxiomSoapFaultDetailTest extends TestCase {
31  
32      private static final String FAILING_FAULT =
33              "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
34                      "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
35                      "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n  " + "<soapenv:Body>\n  " +
36                      "<soapenv:Fault>\n  " + "<faultcode>Client</faultcode>\n  " +
37                      "<faultstring>Client Error</faultstring>\n  " + "<detail>\n " +
38                      "<ns1:dispositionReport xmlns:ns1=\"urn:uddi-org:api_v3\">\n  " +
39                      "<ns1:result errno=\"10210\"/>\n  " + "</ns1:dispositionReport>" + "</detail>" +
40                      "</soapenv:Fault>" + "</soapenv:Body>" + "</soapenv:Envelope>";
41  
42      private static final String SUCCEEDING_FAULT =
43              "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
44                      "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
45                      "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n  " + "<soapenv:Body>\n  " +
46                      "<soapenv:Fault>\n  " + "<faultcode>Client</faultcode>\n  " +
47                      "<faultstring>Client Error</faultstring>\n  " + "<detail>" +
48                      "<ns1:dispositionReport xmlns:ns1=\"urn:uddi-org:api_v3\">\n  " +
49                      "<ns1:result errno=\"10210\"/>\n  " + "</ns1:dispositionReport>" + "</detail>" +
50                      "</soapenv:Fault>" + "</soapenv:Body>" + "</soapenv:Envelope>";
51  
52      private AxiomSoapMessage failingMessage;
53  
54      private AxiomSoapMessage succeedingMessage;
55  
56      protected void setUp() throws Exception {
57          XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(FAILING_FAULT));
58          StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(parser);
59          SOAPMessage soapMessage = builder.getSoapMessage();
60  
61          failingMessage = new AxiomSoapMessage(soapMessage, null, false, true);
62  
63          parser = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(SUCCEEDING_FAULT));
64          builder = new StAXSOAPModelBuilder(parser);
65          soapMessage = builder.getSoapMessage();
66  
67          succeedingMessage = new AxiomSoapMessage(soapMessage, null, false, true);
68  
69      }
70  
71      public void testGetDetailEntriesWorksWithWhitespaceNodes() throws Exception {
72          SoapFault fault = failingMessage.getSoapBody().getFault();
73          assertNotNull("Fault is null", fault);
74          assertNotNull("Fault detail is null", fault.getFaultDetail());
75          SoapFaultDetail detail = fault.getFaultDetail();
76          assertTrue("No next detail entry present", detail.getDetailEntries().hasNext());
77          detail.getDetailEntries().next();
78  
79      }
80  
81      public void testGetDetailEntriesWorksWithoutWhitespaceNodes() throws Exception {
82          SoapFault fault = succeedingMessage.getSoapBody().getFault();
83          assertNotNull("Fault is null", fault);
84          assertNotNull("Fault detail is null", fault.getFaultDetail());
85          SoapFaultDetail detail = fault.getFaultDetail();
86          assertTrue("No next detail entry present", detail.getDetailEntries().hasNext());
87          detail.getDetailEntries().next();
88      }
89  
90  }