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.xml.stream;
18:
19: import java.io.Reader;
20: import java.io.StringReader;
21: import javax.xml.namespace.QName;
22: import javax.xml.stream.XMLInputFactory;
23: import javax.xml.stream.XMLStreamException;
24: import javax.xml.stream.XMLStreamReader;
25:
26: import org.easymock.MockControl;
27: import org.xml.sax.ContentHandler;
28: import org.xml.sax.InputSource;
29: import org.xml.sax.helpers.AttributesImpl;
30:
31: public class StaxStreamXmlReaderTest extends
32: AbstractStaxXmlReaderTestCase {
33:
34: public static final String CONTENT = "<root xmlns='http://springframework.org/spring-ws'><child/></root>";
35:
36: protected AbstractStaxXmlReader createStaxXmlReader(Reader reader)
37: throws XMLStreamException {
38: return new StaxStreamXmlReader(inputFactory
39: .createXMLStreamReader(reader));
40: }
41:
42: public void testPartial() throws Exception {
43: XMLInputFactory inputFactory = XMLInputFactory.newInstance();
44: XMLStreamReader streamReader = inputFactory
45: .createXMLStreamReader(new StringReader(CONTENT));
46: streamReader.nextTag(); // skip to root
47: assertEquals("Invalid element", new QName(
48: "http://springframework.org/spring-ws", "root"),
49: streamReader.getName());
50: streamReader.nextTag(); // skip to child
51: assertEquals("Invalid element", new QName(
52: "http://springframework.org/spring-ws", "child"),
53: streamReader.getName());
54: StaxStreamXmlReader xmlReader = new StaxStreamXmlReader(
55: streamReader);
56:
57: MockControl mockControl = MockControl
58: .createStrictControl(ContentHandler.class);
59: mockControl.setDefaultMatcher(new SaxArgumentMatcher());
60: ContentHandler contentHandlerMock = (ContentHandler) mockControl
61: .getMock();
62:
63: contentHandlerMock.startDocument();
64: contentHandlerMock.startElement(
65: "http://springframework.org/spring-ws", "child",
66: "child", new AttributesImpl());
67: contentHandlerMock.endElement(
68: "http://springframework.org/spring-ws", "child",
69: "child");
70: contentHandlerMock.endDocument();
71:
72: xmlReader.setContentHandler(contentHandlerMock);
73: mockControl.replay();
74: xmlReader.parse(new InputSource());
75: mockControl.verify();
76: }
77:
78: }
|