01: /*
02: * Copyright (C) 2005 Joe Walnes.
03: * Copyright (C) 2006, 2007 XStream Committers.
04: * All rights reserved.
05: *
06: * The software in this package is published under the terms of the BSD
07: * style license a copy of which has been included with this distribution in
08: * the LICENSE.txt file.
09: *
10: * Created on 30. April 2005 by Joe Walnes
11: */
12: package com.thoughtworks.xstream.io;
13:
14: import junit.framework.Assert;
15: import junit.framework.AssertionFailedError;
16: import junit.framework.Test;
17: import junit.framework.TestCase;
18: import junit.framework.TestSuite;
19:
20: import com.thoughtworks.acceptance.objects.Software;
21: import com.thoughtworks.xstream.XStream;
22: import com.thoughtworks.xstream.core.JVM;
23: import com.thoughtworks.xstream.io.xml.Dom4JDriver;
24: import com.thoughtworks.xstream.io.xml.DomDriver;
25: import com.thoughtworks.xstream.io.xml.JDomDriver;
26: import com.thoughtworks.xstream.io.xml.StaxDriver;
27: import com.thoughtworks.xstream.io.xml.XomDriver;
28: import com.thoughtworks.xstream.io.xml.XppDomDriver;
29: import com.thoughtworks.xstream.io.xml.XppDriver;
30:
31: public class DriverEndToEndTestSuite extends TestSuite {
32:
33: public static Test suite() {
34: return new DriverEndToEndTestSuite();
35: }
36:
37: public DriverEndToEndTestSuite() {
38: super (DriverEndToEndTestSuite.class.getName());
39: addDriverTest(new Dom4JDriver());
40: addDriverTest(new DomDriver());
41: addDriverTest(new JDomDriver());
42: addDriverTest(new StaxDriver());
43: addDriverTest(new XppDomDriver());
44: addDriverTest(new XppDriver());
45: addDriverTest(new XomDriver());
46: if (JVM.is14()) {
47: JVM jvm = new JVM();
48: Class driverType = jvm
49: .loadClass("com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver");
50: try {
51: addDriverTest((HierarchicalStreamDriver) driverType
52: .newInstance());
53: } catch (InstantiationException e) {
54: throw new AssertionFailedError("Cannot instantiate "
55: + driverType.getName());
56: } catch (IllegalAccessException e) {
57: throw new AssertionFailedError(
58: "Cannot access default constructor of "
59: + driverType.getName());
60: }
61: }
62: }
63:
64: private void test(HierarchicalStreamDriver driver) {
65: XStream xstream = new XStream(driver);
66:
67: Object in = new Software("some vendor", "some name");
68: String xml = xstream.toXML(in);
69: Object out = xstream.fromXML(xml);
70:
71: Assert.assertEquals(in, out);
72: }
73:
74: private void addDriverTest(final HierarchicalStreamDriver driver) {
75: String testName = getShortName(driver);
76: addTest(new TestCase(testName) {
77: protected void runTest() throws Throwable {
78: test(driver);
79: }
80: });
81: }
82:
83: private String getShortName(HierarchicalStreamDriver driver) {
84: String result = driver.getClass().getName();
85: result = result.substring(result.lastIndexOf('.') + 1);
86: return result;
87: }
88:
89: }
|