01: /*
02: * Copyright (C) 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 03. November 2007 by Joerg Schaible
10: */
11: package com.thoughtworks.xstream.io.xml;
12:
13: import junit.framework.AssertionFailedError;
14: import junit.framework.Test;
15:
16: import javax.xml.stream.XMLOutputFactory;
17:
18: public final class JDK6StaxWriterTest extends AbstractStaxWriterTest {
19: final static String className = "com.sun.xml.internal.stream.XMLOutputFactoryImpl";
20: private final Class factoryClass;
21:
22: public static Test suite() {
23: return createSuite(JDK6StaxWriterTest.class, className);
24: }
25:
26: protected void assertXmlProducedIs(String expected) {
27: if (outputFactory.getProperty(
28: XMLOutputFactory.IS_REPAIRING_NAMESPACES).equals(
29: Boolean.FALSE)) {
30: expected = perlUtil
31: .substitute(
32: "s#<(\\w+|\\w+:\\w+) (xmlns[^\"]*\"[^\"]*\")>#<$1>#g",
33: expected);
34: }
35: expected = perlUtil.substitute(
36: "s#<(\\w+)([^>]*)/>#<$1$2></$1>#g", expected);
37: expected = replaceAll(expected, "
", "\r");
38: expected = getXMLHeader() + expected;
39: assertEquals(expected, buffer.toString());
40: }
41:
42: public JDK6StaxWriterTest() {
43: try {
44: this .factoryClass = Class.forName(className);
45: } catch (ClassNotFoundException e) {
46: throw new AssertionFailedError("Cannot load JDK 6 class "
47: + className);
48: }
49: System.setProperty(XMLOutputFactory.class.getName(), className);
50: }
51:
52: protected String getXMLHeader() {
53: return "<?xml version=\"1.0\" ?>";
54: }
55:
56: protected XMLOutputFactory getOutputFactory() {
57: try {
58: return (XMLOutputFactory) this .factoryClass.newInstance();
59: } catch (InstantiationException e) {
60: throw new AssertionFailedError("Cannot instantiate "
61: + className);
62: } catch (IllegalAccessException e) {
63: throw new AssertionFailedError(
64: "Cannot access default ctor of " + className);
65: }
66: }
67: }
|