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.server.endpoint;
18:
19: import java.io.ByteArrayInputStream;
20: import java.io.InputStream;
21: import java.io.Reader;
22: import java.io.StringReader;
23: import javax.xml.parsers.DocumentBuilder;
24: import javax.xml.parsers.DocumentBuilderFactory;
25: import javax.xml.stream.XMLEventReader;
26: import javax.xml.stream.XMLInputFactory;
27: import javax.xml.stream.XMLStreamReader;
28: import javax.xml.transform.Source;
29: import javax.xml.transform.dom.DOMSource;
30: import javax.xml.transform.sax.SAXSource;
31: import javax.xml.transform.stream.StreamSource;
32:
33: import org.custommonkey.xmlunit.XMLTestCase;
34: import org.springframework.xml.transform.StaxSource;
35: import org.w3c.dom.Document;
36: import org.xml.sax.InputSource;
37: import org.xml.sax.XMLReader;
38: import org.xml.sax.helpers.XMLReaderFactory;
39:
40: public abstract class AbstractEndpointTestCase extends XMLTestCase {
41:
42: protected static final String NAMESPACE_URI = "http://springframework.org/ws";
43:
44: protected static final String REQUEST_ELEMENT = "request";
45:
46: protected static final String RESPONSE_ELEMENT = "response";
47:
48: protected static final String REQUEST = "<" + REQUEST_ELEMENT
49: + " xmlns=\"" + NAMESPACE_URI + "\"/>";
50:
51: protected static final String RESPONSE = "<" + RESPONSE_ELEMENT
52: + " xmlns=\"" + NAMESPACE_URI + "\"/>";
53:
54: public void testDomSource() throws Exception {
55: DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
56: .newInstance();
57: documentBuilderFactory.setNamespaceAware(true);
58: DocumentBuilder documentBuilder = documentBuilderFactory
59: .newDocumentBuilder();
60: Document requestDocument = documentBuilder
61: .parse(new InputSource(new StringReader(REQUEST)));
62: testSource(new DOMSource(requestDocument.getDocumentElement()));
63: }
64:
65: public void testSaxSource() throws Exception {
66: XMLReader reader = XMLReaderFactory.createXMLReader();
67: InputSource inputSource = new InputSource(new StringReader(
68: REQUEST));
69: testSource(new SAXSource(reader, inputSource));
70: }
71:
72: public void testStaxSourceEventReader() throws Exception {
73: XMLInputFactory inputFactory = XMLInputFactory.newInstance();
74: XMLEventReader eventReader = inputFactory
75: .createXMLEventReader(new StringReader(REQUEST));
76: testSource(new StaxSource(eventReader));
77: }
78:
79: public void testStaxSourceStreamReader() throws Exception {
80: XMLInputFactory inputFactory = XMLInputFactory.newInstance();
81: XMLStreamReader streamReader = inputFactory
82: .createXMLStreamReader(new StringReader(REQUEST));
83: testSource(new StaxSource(streamReader));
84: }
85:
86: public void testStreamSourceInputStream() throws Exception {
87: InputStream is = new ByteArrayInputStream(REQUEST
88: .getBytes("UTF-8"));
89: testSource(new StreamSource(is));
90: }
91:
92: public void testStreamSourceReader() throws Exception {
93: Reader reader = new StringReader(REQUEST);
94: testSource(new StreamSource(reader));
95: }
96:
97: protected abstract void testSource(Source requestSource)
98: throws Exception;
99: }
|