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.saaj;
18:
19: import java.util.Iterator;
20: import javax.xml.soap.MessageFactory;
21: import javax.xml.soap.SOAPBody;
22: import javax.xml.soap.SOAPBodyElement;
23: import javax.xml.soap.SOAPConstants;
24: import javax.xml.soap.SOAPMessage;
25: import javax.xml.transform.Result;
26: import javax.xml.transform.Source;
27:
28: import org.springframework.ws.soap.SoapMessage;
29: import org.springframework.ws.soap.soap11.AbstractSoap11MessageTestCase;
30: import org.springframework.xml.transform.StringResult;
31: import org.springframework.xml.transform.StringSource;
32:
33: public class SaajSoap11MessageTest extends
34: AbstractSoap11MessageTestCase {
35:
36: private SOAPMessage saajMessage;
37:
38: protected final SoapMessage createSoapMessage() throws Exception {
39: MessageFactory messageFactory = MessageFactory
40: .newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
41: saajMessage = messageFactory.createMessage();
42: saajMessage.getSOAPHeader().detachNode();
43: return new SaajSoapMessage(saajMessage);
44: }
45:
46: public void testGetPayloadSource() throws Exception {
47: saajMessage.getSOAPPart().getEnvelope().getBody()
48: .addChildElement("child");
49: Source source = soapMessage.getPayloadSource();
50: StringResult result = new StringResult();
51: transformer.transform(source, result);
52: assertXMLEqual("Invalid source", "<child/>", result.toString());
53: }
54:
55: public void testGetPayloadSourceText() throws Exception {
56: SOAPBody body = saajMessage.getSOAPPart().getEnvelope()
57: .getBody();
58: body.addTextNode(" ");
59: body.addChildElement("child");
60: Source source = soapMessage.getPayloadSource();
61: StringResult result = new StringResult();
62: transformer.transform(source, result);
63: assertXMLEqual("Invalid source", "<child/>", result.toString());
64: }
65:
66: public void testGetPayloadResult() throws Exception {
67: StringSource source = new StringSource("<child/>");
68: Result result = soapMessage.getPayloadResult();
69: transformer.transform(source, result);
70: SOAPBody body = saajMessage.getSOAPPart().getEnvelope()
71: .getBody();
72: Iterator iterator = body.getChildElements();
73: assertTrue("No child nodes created", iterator.hasNext());
74: SOAPBodyElement bodyElement = (SOAPBodyElement) iterator.next();
75: assertEquals("Invalid child node created", "child", bodyElement
76: .getElementName().getLocalName());
77: }
78:
79: }
|