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