001: /*
002: * Copyright 2006 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.soap11;
018:
019: import java.util.Locale;
020: import javax.xml.namespace.QName;
021:
022: import org.springframework.ws.soap.AbstractSoapBodyTestCase;
023: import org.springframework.ws.soap.SoapFault;
024: import org.springframework.ws.soap.SoapFaultDetail;
025: import org.springframework.ws.soap.SoapFaultDetailElement;
026: import org.springframework.ws.soap.SoapVersion;
027: import org.springframework.xml.transform.StringResult;
028: import org.springframework.xml.transform.StringSource;
029:
030: public abstract class AbstractSoap11BodyTestCase extends
031: AbstractSoapBodyTestCase {
032:
033: public void testGetType() {
034: assertTrue("Invalid type returned",
035: soapBody instanceof Soap11Body);
036: }
037:
038: public void testGetName() throws Exception {
039: assertEquals("Invalid qualified name", SoapVersion.SOAP_11
040: .getBodyName(), soapBody.getName());
041: }
042:
043: public void testGetSource() throws Exception {
044: StringResult result = new StringResult();
045: transformer.transform(soapBody.getSource(), result);
046: assertXMLEqual(
047: "Invalid contents of body",
048: "<Body xmlns='http://schemas.xmlsoap.org/soap/envelope/' />",
049: result.toString());
050: }
051:
052: public void testAddMustUnderstandFault() throws Exception {
053: SoapFault fault = soapBody.addMustUnderstandFault(
054: "SOAP Must Understand Error", null);
055: assertEquals("Invalid fault code", new QName(
056: "http://schemas.xmlsoap.org/soap/envelope/",
057: "MustUnderstand"), fault.getFaultCode());
058: assertPayloadEqual("<SOAP-ENV:Fault xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>"
059: + "<faultcode>"
060: + soapBody.getName().getPrefix()
061: + ":MustUnderstand</faultcode>"
062: + "<faultstring>SOAP Must Understand Error</faultstring></SOAP-ENV:Fault>");
063: }
064:
065: public void testAddClientFault() throws Exception {
066: SoapFault fault = soapBody.addClientOrSenderFault(
067: "faultString", null);
068: assertEquals("Invalid fault code", new QName(
069: "http://schemas.xmlsoap.org/soap/envelope/", "Client"),
070: fault.getFaultCode());
071: assertPayloadEqual("<SOAP-ENV:Fault xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>"
072: + "<faultcode>"
073: + soapBody.getName().getPrefix()
074: + ":Client</faultcode>"
075: + "<faultstring>faultString</faultstring>"
076: + "</SOAP-ENV:Fault>");
077: }
078:
079: public void testAddServerFault() throws Exception {
080: SoapFault fault = soapBody.addServerOrReceiverFault(
081: "faultString", null);
082: assertEquals("Invalid fault code", new QName(
083: "http://schemas.xmlsoap.org/soap/envelope/", "Server"),
084: fault.getFaultCode());
085: assertPayloadEqual("<SOAP-ENV:Fault xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>"
086: + "<faultcode>"
087: + soapBody.getName().getPrefix()
088: + ":Server</faultcode>"
089: + "<faultstring>faultString</faultstring>"
090: + "</SOAP-ENV:Fault>");
091: }
092:
093: public void testAddFault() throws Exception {
094: QName faultCode = new QName("http://www.springframework.org",
095: "fault", "spring");
096: String faultString = "faultString";
097: Soap11Fault fault = ((Soap11Body) soapBody).addFault(faultCode,
098: faultString, Locale.ENGLISH);
099: assertNotNull("Null returned", fault);
100: assertTrue("SoapBody has no fault", soapBody.hasFault());
101: assertNotNull("SoapBody has no fault", soapBody.getFault());
102: assertEquals("Invalid fault code", faultCode, fault
103: .getFaultCode());
104: assertEquals("Invalid fault string", faultString, fault
105: .getFaultStringOrReason());
106: assertEquals("Invalid fault string locale", Locale.ENGLISH,
107: fault.getFaultStringLocale());
108: String actor = "http://www.springframework.org/actor";
109: fault.setFaultActorOrRole(actor);
110: assertEquals("Invalid fault actor", actor, fault
111: .getFaultActorOrRole());
112: assertPayloadEqual("<SOAP-ENV:Fault xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' "
113: + "xmlns:spring='http://www.springframework.org'>"
114: + "<faultcode>spring:fault</faultcode>"
115: + "<faultstring xml:lang='en'>"
116: + faultString
117: + "</faultstring>"
118: + "<faultactor>"
119: + actor
120: + "</faultactor>" + "</SOAP-ENV:Fault>");
121: }
122:
123: public void testAddFaultWithDetail() throws Exception {
124: QName faultCode = new QName("http://www.springframework.org",
125: "fault", "spring");
126: String faultString = "faultString";
127: SoapFault fault = ((Soap11Body) soapBody).addFault(faultCode,
128: faultString, null);
129: SoapFaultDetail detail = fault.addFaultDetail();
130: QName detailName = new QName("http://www.springframework.org",
131: "detailEntry", "spring");
132: SoapFaultDetailElement detailElement1 = detail
133: .addFaultDetailElement(detailName);
134: StringSource detailContents = new StringSource(
135: "<detailContents xmlns='namespace'/>");
136: transformer.transform(detailContents, detailElement1
137: .getResult());
138: SoapFaultDetailElement detailElement2 = detail
139: .addFaultDetailElement(detailName);
140: detailContents = new StringSource(
141: "<detailContents xmlns='namespace'/>");
142: transformer.transform(detailContents, detailElement2
143: .getResult());
144: assertPayloadEqual("<SOAP-ENV:Fault xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:spring='http://www.springframework.org'>"
145: + "<faultcode>spring:fault</faultcode>"
146: + "<faultstring>"
147: + faultString
148: + "</faultstring>"
149: + "<detail>"
150: + "<spring:detailEntry xmlns:spring='http://www.springframework.org'><detailContents xmlns='namespace'/></spring:detailEntry>"
151: + "<spring:detailEntry xmlns:spring='http://www.springframework.org'><detailContents xmlns='namespace'/></spring:detailEntry>"
152: + "</detail>" + "</SOAP-ENV:Fault>");
153:
154: }
155:
156: public void testAddFaultWithDetailResult() throws Exception {
157: SoapFault fault = ((Soap11Body) soapBody).addFault(new QName(
158: "namespace", "localPart", "prefix"), "Fault", null);
159: SoapFaultDetail detail = fault.addFaultDetail();
160: transformer.transform(new StringSource(
161: "<detailContents xmlns='namespace'/>"), detail
162: .getResult());
163: transformer.transform(new StringSource(
164: "<detailContents xmlns='namespace'/>"), detail
165: .getResult());
166: assertPayloadEqual("<SOAP-ENV:Fault xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>"
167: + "<faultcode xmlns:prefix='namespace'>prefix:localPart</faultcode>"
168: + "<faultstring>Fault</faultstring>"
169: + "<detail>"
170: + "<detailContents xmlns='namespace'/>"
171: + "<detailContents xmlns='namespace'/>"
172: + "</detail></SOAP-ENV:Fault>");
173: }
174:
175: }
|