001: /*
002: * Copyright 2007 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.ws.soap.axiom;
018:
019: import java.io.StringReader;
020: import javax.xml.stream.XMLInputFactory;
021: import javax.xml.stream.XMLStreamReader;
022:
023: import junit.framework.TestCase;
024: import org.apache.axiom.soap.SOAPMessage;
025: import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
026: import org.springframework.ws.soap.SoapFault;
027: import org.springframework.ws.soap.SoapFaultDetail;
028:
029: public class AxiomSoapFaultDetailTest extends TestCase {
030:
031: private static final String FAILING_FAULT = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" "
032: + "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
033: + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n "
034: + "<soapenv:Body>\n "
035: + "<soapenv:Fault>\n "
036: + "<faultcode>Client</faultcode>\n "
037: + "<faultstring>Client Error</faultstring>\n "
038: + "<detail>\n "
039: + "<ns1:dispositionReport xmlns:ns1=\"urn:uddi-org:api_v3\">\n "
040: + "<ns1:result errno=\"10210\"/>\n "
041: + "</ns1:dispositionReport>"
042: + "</detail>"
043: + "</soapenv:Fault>"
044: + "</soapenv:Body>"
045: + "</soapenv:Envelope>";
046:
047: private static final String SUCCEEDING_FAULT = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" "
048: + "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
049: + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n "
050: + "<soapenv:Body>\n "
051: + "<soapenv:Fault>\n "
052: + "<faultcode>Client</faultcode>\n "
053: + "<faultstring>Client Error</faultstring>\n "
054: + "<detail>"
055: + "<ns1:dispositionReport xmlns:ns1=\"urn:uddi-org:api_v3\">\n "
056: + "<ns1:result errno=\"10210\"/>\n "
057: + "</ns1:dispositionReport>"
058: + "</detail>"
059: + "</soapenv:Fault>"
060: + "</soapenv:Body>"
061: + "</soapenv:Envelope>";
062:
063: private AxiomSoapMessage failingMessage;
064:
065: private AxiomSoapMessage succeedingMessage;
066:
067: protected void setUp() throws Exception {
068: XMLStreamReader parser = XMLInputFactory.newInstance()
069: .createXMLStreamReader(new StringReader(FAILING_FAULT));
070: StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(parser);
071: SOAPMessage soapMessage = builder.getSoapMessage();
072:
073: failingMessage = new AxiomSoapMessage(soapMessage, null, false);
074:
075: parser = XMLInputFactory.newInstance().createXMLStreamReader(
076: new StringReader(SUCCEEDING_FAULT));
077: builder = new StAXSOAPModelBuilder(parser);
078: soapMessage = builder.getSoapMessage();
079:
080: succeedingMessage = new AxiomSoapMessage(soapMessage, null,
081: false);
082:
083: }
084:
085: public void testGetDetailEntriesWorksWithWhitespaceNodes()
086: throws Exception {
087: SoapFault fault = failingMessage.getSoapBody().getFault();
088: assertNotNull("Fault is null", fault);
089: assertNotNull("Fault detail is null", fault.getFaultDetail());
090: SoapFaultDetail detail = fault.getFaultDetail();
091: assertTrue("No next detail entry present", detail
092: .getDetailEntries().hasNext());
093: detail.getDetailEntries().next();
094:
095: }
096:
097: public void testGetDetailEntriesWorksWithoutWhitespaceNodes()
098: throws Exception {
099: SoapFault fault = succeedingMessage.getSoapBody().getFault();
100: assertNotNull("Fault is null", fault);
101: assertNotNull("Fault detail is null", fault.getFaultDetail());
102: SoapFaultDetail detail = fault.getFaultDetail();
103: assertTrue("No next detail entry present", detail
104: .getDetailEntries().hasNext());
105: detail.getDetailEntries().next();
106: }
107:
108: }
|