1   /*
2    * Copyright 2006 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
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.InputStream;
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 AbstractStaxXmlReaderTestCase {
31  
32      public static final String CONTENT = "<root xmlns='http://springframework.org/spring-ws'><child/></root>";
33  
34      protected AbstractStaxXmlReader createStaxXmlReader(InputStream inputStream) throws XMLStreamException {
35          return new StaxEventXmlReader(inputFactory.createXMLEventReader(inputStream));
36      }
37  
38      public void testPartial() throws Exception {
39          XMLInputFactory inputFactory = XMLInputFactory.newInstance();
40          XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(CONTENT));
41          eventReader.nextTag(); // skip to root
42          StaxEventXmlReader xmlReader = new StaxEventXmlReader(eventReader);
43  
44          MockControl mockControl = MockControl.createStrictControl(ContentHandler.class);
45          mockControl.setDefaultMatcher(new SaxArgumentMatcher());
46          ContentHandler contentHandlerMock = (ContentHandler) mockControl.getMock();
47  
48          contentHandlerMock.startDocument();
49          contentHandlerMock.startElement("http://springframework.org/spring-ws", "child", "child", new AttributesImpl());
50          contentHandlerMock.endElement("http://springframework.org/spring-ws", "child", "child");
51          contentHandlerMock.endDocument();
52  
53          xmlReader.setContentHandler(contentHandlerMock);
54          mockControl.replay();
55          xmlReader.parse(new InputSource());
56          mockControl.verify();
57      }
58  
59  }
60