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 com.ctc.wstx.stax.WstxOutputFactory;
14:
15: import junit.framework.Test;
16:
17: import javax.xml.stream.XMLOutputFactory;
18:
19: public final class WoodstoxStaxWriterTest extends
20: AbstractStaxWriterTest {
21: public WoodstoxStaxWriterTest() {
22: System.setProperty(XMLOutputFactory.class.getName(),
23: WstxOutputFactory.class.getName());
24: }
25:
26: public static Test suite() {
27: return createSuite(WoodstoxStaxWriterTest.class,
28: WstxOutputFactory.class.getName());
29: }
30:
31: protected void assertXmlProducedIs(String expected) {
32: if (outputFactory.getProperty(
33: XMLOutputFactory.IS_REPAIRING_NAMESPACES).equals(
34: Boolean.FALSE)) {
35: expected = perlUtil
36: .substitute(
37: "s#<(\\w+|\\w+:\\w+) (xmlns[^\"]*\"[^\"]*\")>#<$1>#g",
38: expected);
39: } else if (perlUtil.match("#<\\w+:\\w+(>| xmlns:\\w+=)#",
40: expected)) {
41: expected = perlUtil
42: .substitute("s# xmlns=\"\"##g", expected);
43: }
44: expected = perlUtil.substitute("s#<(\\w+)([^>]*)/>#<$1$2 />#g",
45: expected);
46: expected = replaceAll(expected, "
", "
");
47: expected = replaceAll(expected, ">", ">"); // Woodstox bug !!
48: expected = getXMLHeader() + expected;
49: assertEquals(expected, buffer.toString());
50: }
51:
52: protected String getXMLHeader() {
53: return "<?xml version='1.0' encoding='UTF-8'?>";
54: }
55:
56: protected XMLOutputFactory getOutputFactory() {
57: return new WstxOutputFactory();
58: }
59: }
|