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.soap12;
018:
019: import java.util.Iterator;
020: import java.util.Locale;
021: import javax.xml.namespace.QName;
022:
023: import org.springframework.ws.soap.AbstractSoapBodyTestCase;
024: import org.springframework.ws.soap.SoapFault;
025: import org.springframework.ws.soap.SoapFaultDetail;
026: import org.springframework.ws.soap.SoapFaultDetailElement;
027: import org.springframework.ws.soap.SoapVersion;
028: import org.springframework.xml.transform.StringResult;
029: import org.springframework.xml.transform.StringSource;
030:
031: public abstract class AbstractSoap12BodyTestCase extends
032: AbstractSoapBodyTestCase {
033:
034: public void testGetType() {
035: assertTrue("Invalid type returned",
036: soapBody instanceof Soap12Body);
037: }
038:
039: public void testGetName() throws Exception {
040: assertEquals("Invalid qualified name", new QName(
041: SoapVersion.SOAP_12.getEnvelopeNamespaceUri(), "Body"),
042: soapBody.getName());
043: }
044:
045: public void testGetSource() throws Exception {
046: StringResult result = new StringResult();
047: transformer.transform(soapBody.getSource(), result);
048: assertXMLEqual(
049: "Invalid contents of body",
050: "<Body xmlns='http://www.w3.org/2003/05/soap-envelope' />",
051: result.toString());
052: }
053:
054: public void testAddMustUnderstandFault() throws Exception {
055: SoapFault fault = soapBody.addMustUnderstandFault(
056: "SOAP Must Understand Error", Locale.ENGLISH);
057: assertEquals("Invalid fault code", new QName(
058: "http://www.w3.org/2003/05/soap-envelope",
059: "MustUnderstand"), fault.getFaultCode());
060: StringResult result = new StringResult();
061: transformer.transform(fault.getSource(), result);
062: assertXMLEqual(
063: "Invalid contents of body",
064: "<soapenv:Fault xmlns:soapenv='http://www.w3.org/2003/05/soap-envelope'>"
065: + "<soapenv:Code><soapenv:Value>"
066: + soapBody.getName().getPrefix()
067: + ":MustUnderstand</soapenv:Value></soapenv:Code>"
068: + "<soapenv:Reason><soapenv:Text xml:lang='en'>SOAP Must Understand Error</soapenv:Text>"
069: + "</soapenv:Reason></soapenv:Fault>", result
070: .toString());
071: }
072:
073: public void testAddSenderFault() throws Exception {
074: SoapFault fault = soapBody.addClientOrSenderFault(
075: "faultString", Locale.ENGLISH);
076: assertEquals("Invalid fault code", new QName(
077: "http://www.w3.org/2003/05/soap-envelope", "Sender"),
078: fault.getFaultCode());
079: StringResult result = new StringResult();
080: transformer.transform(fault.getSource(), result);
081: assertXMLEqual(
082: "Invalid contents of body",
083: "<soapenv:Fault xmlns:soapenv='http://www.w3.org/2003/05/soap-envelope'>"
084: + "<soapenv:Code><soapenv:Value>"
085: + soapBody.getName().getPrefix()
086: + ":Sender</soapenv:Value></soapenv:Code>"
087: + "<soapenv:Reason><soapenv:Text xml:lang='en'>faultString</soapenv:Text></soapenv:Reason>"
088: + "</soapenv:Fault>", result.toString());
089: }
090:
091: public void testAddReceiverFault() throws Exception {
092: SoapFault fault = soapBody.addServerOrReceiverFault(
093: "faultString", Locale.ENGLISH);
094: assertEquals("Invalid fault code", new QName(
095: "http://www.w3.org/2003/05/soap-envelope", "Receiver"),
096: fault.getFaultCode());
097: StringResult result = new StringResult();
098: transformer.transform(fault.getSource(), result);
099: assertXMLEqual(
100: "Invalid contents of body",
101: "<soapenv:Fault xmlns:soapenv='http://www.w3.org/2003/05/soap-envelope'>"
102: + "<soapenv:Code><soapenv:Value>"
103: + soapBody.getName().getPrefix()
104: + ":Receiver</soapenv:Value></soapenv:Code>"
105: + "<soapenv:Reason><soapenv:Text xml:lang='en'>faultString</soapenv:Text></soapenv:Reason>"
106: + "</soapenv:Fault>", result.toString());
107: }
108:
109: public void testAddFaultWithDetail() throws Exception {
110: SoapFault fault = soapBody.addServerOrReceiverFault(
111: "faultString", Locale.ENGLISH);
112: SoapFaultDetail detail = fault.addFaultDetail();
113: SoapFaultDetailElement detailElement = detail
114: .addFaultDetailElement(new QName("namespace",
115: "localPart", "prefix"));
116: StringSource detailContents = new StringSource(
117: "<detailContents xmlns='namespace'/>");
118: transformer
119: .transform(detailContents, detailElement.getResult());
120: StringResult result = new StringResult();
121: transformer.transform(fault.getSource(), result);
122: assertXMLEqual(
123: "Invalid source for body",
124: "<soapenv:Fault xmlns:soapenv='http://www.w3.org/2003/05/soap-envelope'>"
125: + "<soapenv:Code><soapenv:Value>"
126: + soapBody.getName().getPrefix()
127: + ":Receiver</soapenv:Value>"
128: + "</soapenv:Code>"
129: + "<soapenv:Reason><soapenv:Text xml:lang='en'>faultString</soapenv:Text></soapenv:Reason>"
130: + "<soapenv:Detail><prefix:localPart xmlns:prefix='namespace'><detailContents xmlns='namespace'/>"
131: + "</prefix:localPart></soapenv:Detail></soapenv:Fault>",
132: result.toString());
133: }
134:
135: public void testAddFaultWithDetailResult() throws Exception {
136: SoapFault fault = soapBody.addServerOrReceiverFault(
137: "faultString", Locale.ENGLISH);
138: SoapFaultDetail detail = fault.addFaultDetail();
139: transformer.transform(new StringSource(
140: "<detailContents xmlns='namespace'/>"), detail
141: .getResult());
142: transformer.transform(new StringSource(
143: "<detailContents xmlns='namespace'/>"), detail
144: .getResult());
145: StringResult result = new StringResult();
146: transformer.transform(fault.getSource(), result);
147: assertXMLEqual(
148: "Invalid source for body",
149: "<soapenv:Fault xmlns:soapenv='http://www.w3.org/2003/05/soap-envelope'>"
150: + "<soapenv:Code><soapenv:Value>"
151: + soapBody.getName().getPrefix()
152: + ":Receiver</soapenv:Value>"
153: + "</soapenv:Code>"
154: + "<soapenv:Reason><soapenv:Text xml:lang='en'>faultString</soapenv:Text></soapenv:Reason>"
155: + "<soapenv:Detail>"
156: + "<detailContents xmlns='namespace'/>"
157: + "<detailContents xmlns='namespace'/>"
158: + "</soapenv:Detail></soapenv:Fault>", result
159: .toString());
160: }
161:
162: public void testAddFaultWithSubcode() throws Exception {
163: Soap12Fault fault = (Soap12Fault) soapBody
164: .addServerOrReceiverFault("faultString", Locale.ENGLISH);
165: QName subcode1 = new QName("http://www.springframework.org",
166: "Subcode1", "spring-ws");
167: fault.addFaultSubcode(subcode1);
168: QName subcode2 = new QName("http://www.springframework.org",
169: "Subcode2", "spring-ws");
170: fault.addFaultSubcode(subcode2);
171: Iterator iterator = fault.getFaultSubcodes();
172: assertTrue("No subcode found", iterator.hasNext());
173: assertEquals("Invalid subcode", subcode1, iterator.next());
174: assertTrue("No subcode found", iterator.hasNext());
175: assertEquals("Invalid subcode", subcode2, iterator.next());
176: assertFalse("Subcode found", iterator.hasNext());
177: StringResult result = new StringResult();
178: transformer.transform(fault.getSource(), result);
179: assertXMLEqual(
180: "Invalid source for body",
181: "<soapenv:Fault xmlns:soapenv='http://www.w3.org/2003/05/soap-envelope'>"
182: + "<soapenv:Code><soapenv:Value>"
183: + soapBody.getName().getPrefix()
184: + ":Receiver</soapenv:Value>"
185: + "<soapenv:Subcode><soapenv:Value xmlns:spring-ws='http://www.springframework.org'>spring-ws:Subcode1</soapenv:Value>"
186: + "<soapenv:Subcode><soapenv:Value xmlns:spring-ws='http://www.springframework.org'>spring-ws:Subcode2</soapenv:Value>"
187: + "</soapenv:Subcode></soapenv:Subcode></soapenv:Code>"
188: + "<soapenv:Reason><soapenv:Text xml:lang='en'>faultString</soapenv:Text></soapenv:Reason>"
189: + "</soapenv:Fault>", result.toString());
190: }
191:
192: }
|