1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 AbstractPayloadEndpointTestCase {
28
29 protected PayloadEndpoint createNoResponseEndpoint() throws Exception {
30 return new AbstractSaxPayloadEndpoint() {
31
32 protected Source getResponse(ContentHandler contentHandler) {
33 return null;
34 }
35
36 protected ContentHandler createContentHandler() {
37 return new DefaultHandler();
38 }
39 };
40 }
41
42 protected PayloadEndpoint createResponseEndpoint() throws Exception {
43 return new AbstractSaxPayloadEndpoint() {
44
45 protected ContentHandler createContentHandler() {
46 return new TestContentHandler();
47 }
48
49 protected Source getResponse(ContentHandler contentHandler) {
50 return new StringSource(RESPONSE);
51 }
52 };
53 }
54
55 protected PayloadEndpoint createNoRequestEndpoint() throws Exception {
56 return new AbstractSaxPayloadEndpoint() {
57
58 protected ContentHandler createContentHandler() throws Exception {
59 fail("Not expected");
60 return null;
61 }
62
63 protected Source getResponse(ContentHandler contentHandler) throws Exception {
64 return null;
65 }
66 };
67 }
68
69 private static class TestContentHandler extends DefaultHandler {
70
71 public void endElement(String uri, String localName, String qName) throws SAXException {
72 assertEquals("Invalid local name", REQUEST_ELEMENT, localName);
73 assertEquals("Invalid qName", REQUEST_ELEMENT, localName);
74 assertEquals("Invalid namespace", NAMESPACE_URI, uri);
75 }
76
77 public void startElement(String uri, String localName, String qName, Attributes attributes)
78 throws SAXException {
79 assertEquals("Invalid local name", REQUEST_ELEMENT, localName);
80 assertEquals("Invalid qName", REQUEST_ELEMENT, localName);
81 assertEquals("Invalid namespace", NAMESPACE_URI, uri);
82 }
83 }
84 }