01: /*
02: * Copyright 2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
18:
19: import java.util.Locale;
20:
21: import org.springframework.xml.transform.StringResult;
22: import org.springframework.xml.transform.StringSource;
23:
24: public abstract class AbstractSoapBodyTestCase extends
25: AbstractSoapElementTestCase {
26:
27: protected SoapBody soapBody;
28:
29: protected final SoapElement createSoapElement() throws Exception {
30: soapBody = createSoapBody();
31: return soapBody;
32: }
33:
34: protected abstract SoapBody createSoapBody() throws Exception;
35:
36: public void testPayload() throws Exception {
37: String payload = "<payload xmlns='http://www.springframework.org' />";
38: StringSource contents = new StringSource(payload);
39: transformer.transform(contents, soapBody.getPayloadResult());
40: assertPayloadEqual(payload);
41: }
42:
43: public void testNoFault() throws Exception {
44: assertFalse("body has fault", soapBody.hasFault());
45: }
46:
47: public void testAddFaultWithExistingPayload() throws Exception {
48: StringSource contents = new StringSource(
49: "<payload xmlns='http://www.springframework.org' />");
50: transformer.transform(contents, soapBody.getPayloadResult());
51: soapBody.addMustUnderstandFault("faultString", Locale.ENGLISH);
52: assertTrue("Body has no fault", soapBody.hasFault());
53: }
54:
55: protected void assertPayloadEqual(String expectedPayload)
56: throws Exception {
57: StringResult result = new StringResult();
58: transformer.transform(soapBody.getPayloadSource(), result);
59: assertXMLEqual("Invalid payload contents", expectedPayload,
60: result.toString());
61: }
62:
63: }
|