01: /*
02: * Copyright (C) 2006, 2007 XStream Committers.
03: * All rights reserved.
04: *
05: * The software in this package is published under the terms of the BSD
06: * style license a copy of which has been included with this distribution in
07: * the LICENSE.txt file.
08: *
09: * Created on 07. July 2006 by Joerg Schaible
10: */
11: package com.thoughtworks.xstream.io.xml;
12:
13: import com.bea.xml.stream.MXParserFactory;
14: import com.bea.xml.stream.XMLOutputFactoryBase;
15: import com.thoughtworks.acceptance.AbstractAcceptanceTest;
16: import com.thoughtworks.xstream.XStream;
17: import com.thoughtworks.xstream.io.StreamException;
18:
19: import javax.xml.stream.XMLInputFactory;
20: import javax.xml.stream.XMLOutputFactory;
21: import javax.xml.stream.XMLStreamException;
22: import javax.xml.stream.XMLStreamReader;
23: import javax.xml.stream.XMLStreamWriter;
24:
25: /**
26: * @author Jörg Schaible
27: */
28: public class StaxDriverTest extends AbstractAcceptanceTest {
29: private static class MyStaxDriver extends StaxDriver {
30: public boolean createStaxWriterCalled = false;
31: public boolean createStaxReaderCalled = false;
32:
33: public StaxWriter createStaxWriter(XMLStreamWriter out)
34: throws StreamException {
35: createStaxWriterCalled = true;
36: try {
37: return super .createStaxWriter(out);
38: } catch (XMLStreamException e) {
39: throw new StreamException(e);
40: }
41: }
42:
43: public AbstractPullReader createStaxReader(XMLStreamReader in) {
44: createStaxReaderCalled = true;
45: return super .createStaxReader(in);
46: }
47: }
48:
49: public void testCanOverloadStaxReaderAndWriterInstantiation() {
50: System.setProperty(XMLInputFactory.class.getName(),
51: MXParserFactory.class.getName());
52: System.setProperty(XMLOutputFactory.class.getName(),
53: XMLOutputFactoryBase.class.getName());
54: final MyStaxDriver driver = new MyStaxDriver();
55: xstream = new XStream(driver);
56: assertBothWays("Hi",
57: "<?xml version='1.0' encoding='utf-8'?><string>Hi</string>");
58: assertTrue(driver.createStaxReaderCalled);
59: assertTrue(driver.createStaxWriterCalled);
60: }
61: }
|