package com.thoughtworks.xstream.io;

import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import com.thoughtworks.acceptance.objects.Software;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
import com.thoughtworks.xstream.io.xml.Dom4JDriver;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.thoughtworks.xstream.io.xml.JDomDriver;
import com.thoughtworks.xstream.io.xml.StaxDriver;
import com.thoughtworks.xstream.io.xml.XomDriver;
import com.thoughtworks.xstream.io.xml.XppDomDriver;
import com.thoughtworks.xstream.io.xml.XppDriver;

public class DriverEndToEndTestSuite extends TestSuite {

    public static Test suite() {
        return new DriverEndToEndTestSuite();
    }

    public DriverEndToEndTestSuite() {
        super(DriverEndToEndTestSuite.class.getName());
        addDriverTest(new Dom4JDriver());
        addDriverTest(new DomDriver());
        addDriverTest(new JDomDriver());
        addDriverTest(new StaxDriver());
        addDriverTest(new XppDomDriver());
        addDriverTest(new XppDriver());
        addDriverTest(new XomDriver());
        addDriverTest(new JettisonMappedXmlDriver());
    }

    private void test(HierarchicalStreamDriver driver) {
        XStream xstream = new XStream(driver);

        Object in = new Software("some vendor", "some name");
        String xml = xstream.toXML(in);
        Object out = xstream.fromXML(xml);

        Assert.assertEquals(in, out);
    }

    private void addDriverTest(final HierarchicalStreamDriver driver) {
        String testName = getShortName(driver);
        addTest(new TestCase(testName) {
            protected void runTest() throws Throwable {
                test(driver);
            }
        });
    }

    private String getShortName(HierarchicalStreamDriver driver) {
        String result = driver.getClass().getName();
        result = result.substring(result.lastIndexOf('.') + 1);
        return result;
    }

}

@@ -62,16 +62,61 @@
 Assert;%0A
+import junit.framework.AssertionFailedError;%0A
 import j
@@ -334,39 +334,16 @@
 eam.
-io.json.JettisonMappedXmlDriver
+core.JVM
 ;%0Aim
@@ -1236,53 +1236,593 @@
     
-addDriverTest(new JettisonMappedXmlDriver());
+if (JVM.is14()) %7B%0A            JVM jvm = new JVM();%0A            Class driverType = jvm.loadClass(%22com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver%22);%0A            try %7B%0A                addDriverTest((HierarchicalStreamDriver)driverType.newInstance());%0A            %7D catch (InstantiationException e) %7B%0A                throw new AssertionFailedError(%22Cannot instantiate %22 + driverType.getName());%0A            %7D catch (IllegalAccessException e) %7B%0A                throw new AssertionFailedError(%22Cannot access default constructor of %22 + driverType.getName());%0A            %7D%0A        %7D
 %0A   

Fix JDK 1.3 compatibility.