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.pox.dom;
18:
19: import java.io.ByteArrayOutputStream;
20: import javax.xml.parsers.DocumentBuilder;
21: import javax.xml.parsers.DocumentBuilderFactory;
22: import javax.xml.transform.Transformer;
23: import javax.xml.transform.TransformerFactory;
24:
25: import org.custommonkey.xmlunit.XMLTestCase;
26: import org.springframework.xml.transform.StringResult;
27: import org.springframework.xml.transform.StringSource;
28: import org.w3c.dom.Document;
29:
30: public class DomPoxMessageTest extends XMLTestCase {
31:
32: public static final String NAMESPACE = "http://www.springframework.org/spring-ws";
33:
34: private DomPoxMessage message;
35:
36: private Transformer transformer;
37:
38: protected void setUp() throws Exception {
39: DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
40: .newInstance();
41: DocumentBuilder documentBuilder = documentBuilderFactory
42: .newDocumentBuilder();
43: Document document = documentBuilder.newDocument();
44: TransformerFactory transformerFactory = TransformerFactory
45: .newInstance();
46: transformer = transformerFactory.newTransformer();
47: message = new DomPoxMessage(document, transformer,
48: DomPoxMessageFactory.DEFAULT_CONTENT_TYPE);
49: }
50:
51: public void testGetPayload() throws Exception {
52: String content = "<root xmlns='http://www.springframework.org/spring-ws'>"
53: + "<child/></root>";
54: StringSource source = new StringSource(content);
55: transformer.transform(source, message.getPayloadResult());
56: StringResult stringResult = new StringResult();
57: transformer.transform(message.getPayloadSource(), stringResult);
58: assertXMLEqual(content, stringResult.toString());
59: }
60:
61: public void testWriteTo() throws Exception {
62: String content = "<root xmlns='http://www.springframework.org/spring-ws'>"
63: + "<child/></root>";
64: StringSource source = new StringSource(content);
65: transformer.transform(source, message.getPayloadResult());
66: ByteArrayOutputStream os = new ByteArrayOutputStream();
67: message.writeTo(os);
68: assertXMLEqual(content, os.toString("UTF-8"));
69: }
70: }
|