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.util.Collections;
20: import javax.xml.namespace.QName;
21: import javax.xml.stream.XMLEventFactory;
22: import javax.xml.stream.XMLEventReader;
23: import javax.xml.stream.XMLStreamException;
24: import javax.xml.stream.events.Namespace;
25: import javax.xml.stream.events.XMLEvent;
26: import javax.xml.stream.util.XMLEventConsumer;
27:
28: /**
29: * Test case for AbstractStaxEventPayloadEndpoint.
30: *
31: * @see AbstractStaxEventPayloadEndpoint
32: */
33: public class StaxEventPayloadEndpointTest extends
34: AbstractMessageEndpointTestCase {
35:
36: protected MessageEndpoint createNoResponseEndpoint() {
37: return new AbstractStaxEventPayloadEndpoint() {
38: protected void invokeInternal(XMLEventReader eventReader,
39: XMLEventConsumer eventWriter,
40: XMLEventFactory eventFactory) throws Exception {
41: }
42: };
43: }
44:
45: protected MessageEndpoint createResponseEndpoint() {
46: return new AbstractStaxEventPayloadEndpoint() {
47:
48: protected void invokeInternal(XMLEventReader eventReader,
49: XMLEventConsumer eventWriter,
50: XMLEventFactory eventFactory)
51: throws XMLStreamException {
52: assertNotNull("eventReader not given", eventReader);
53: assertNotNull("eventWriter not given", eventWriter);
54: assertNotNull("eventFactory not given", eventFactory);
55: assertTrue("eventReader has not next element",
56: eventReader.hasNext());
57: XMLEvent event = eventReader.nextEvent();
58: assertTrue("Not a start document", event
59: .isStartDocument());
60: event = eventReader.nextEvent();
61: assertTrue("Not a start element", event
62: .isStartElement());
63: assertEquals("Invalid start event local name",
64: REQUEST_ELEMENT, event.asStartElement()
65: .getName().getLocalPart());
66: assertEquals("Invalid start event namespace",
67: NAMESPACE_URI, event.asStartElement().getName()
68: .getNamespaceURI());
69: assertTrue("eventReader has not next element",
70: eventReader.hasNext());
71: event = eventReader.nextEvent();
72: assertTrue("Not a end element", event.isEndElement());
73: assertEquals("Invalid end event local name",
74: REQUEST_ELEMENT, event.asEndElement().getName()
75: .getLocalPart());
76: assertEquals("Invalid end event namespace",
77: NAMESPACE_URI, event.asEndElement().getName()
78: .getNamespaceURI());
79: Namespace namespace = eventFactory
80: .createNamespace(NAMESPACE_URI);
81: QName name = new QName(NAMESPACE_URI, RESPONSE_ELEMENT);
82: eventWriter.add(eventFactory.createStartElement(name,
83: null, Collections.singleton(namespace)
84: .iterator()));
85: eventWriter.add(eventFactory.createEndElement(name,
86: Collections.singleton(namespace).iterator()));
87: eventWriter.add(eventFactory.createEndDocument());
88: }
89: };
90: }
91:
92: }
|