01: /*
02: * Copyright 2005 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 javax.xml.transform.Source;
20:
21: import org.springframework.xml.transform.StringSource;
22: import org.xml.sax.Attributes;
23: import org.xml.sax.ContentHandler;
24: import org.xml.sax.SAXException;
25: import org.xml.sax.helpers.DefaultHandler;
26:
27: public class SaxPayloadEndpointTest extends
28: AbstractPayloadEndpointTestCase {
29:
30: protected PayloadEndpoint createNoResponseEndpoint()
31: throws Exception {
32: return new AbstractSaxPayloadEndpoint() {
33:
34: protected Source getResponse(ContentHandler contentHandler) {
35: return null;
36: }
37:
38: protected ContentHandler createContentHandler() {
39: return new DefaultHandler();
40: }
41: };
42: }
43:
44: protected PayloadEndpoint createResponseEndpoint() throws Exception {
45: return new AbstractSaxPayloadEndpoint() {
46:
47: protected ContentHandler createContentHandler() {
48: return new TestContentHandler();
49: }
50:
51: protected Source getResponse(ContentHandler contentHandler) {
52: return new StringSource(RESPONSE);
53: }
54: };
55: }
56:
57: protected PayloadEndpoint createNoRequestEndpoint()
58: throws Exception {
59: return new AbstractSaxPayloadEndpoint() {
60:
61: protected ContentHandler createContentHandler()
62: throws Exception {
63: fail("Not expected");
64: return null;
65: }
66:
67: protected Source getResponse(ContentHandler contentHandler)
68: throws Exception {
69: return null;
70: }
71: };
72: }
73:
74: private static class TestContentHandler extends DefaultHandler {
75:
76: public void endElement(String uri, String localName,
77: String qName) throws SAXException {
78: assertEquals("Invalid local name", REQUEST_ELEMENT,
79: localName);
80: assertEquals("Invalid qName", REQUEST_ELEMENT, localName);
81: assertEquals("Invalid namespace", NAMESPACE_URI, uri);
82: }
83:
84: public void startElement(String uri, String localName,
85: String qName, Attributes attributes)
86: throws SAXException {
87: assertEquals("Invalid local name", REQUEST_ELEMENT,
88: localName);
89: assertEquals("Invalid qName", REQUEST_ELEMENT, localName);
90: assertEquals("Invalid namespace", NAMESPACE_URI, uri);
91: }
92: }
93: }
|