1 package com.thoughtworks.xstream.io.xml; 2 3 import junit.framework.Test; 4 import junit.framework.TestSuite; 5 import junit.framework.TestCase; 6 import junit.framework.Assert; 7 import com.thoughtworks.xstream.io.HierarchicalStreamDriver; 8 import com.thoughtworks.xstream.XStream; 9 import com.thoughtworks.acceptance.objects.Software; 10 11 public class DriverEndToEndTestSuite extends TestSuite { 12 13 public static Test suite() { 14 return new DriverEndToEndTestSuite(); 15 } 16 17 public DriverEndToEndTestSuite() { 18 super(DriverEndToEndTestSuite.class.getName()); 19 addDriverTest(new Dom4JDriver()); 20 addDriverTest(new DomDriver()); 21 addDriverTest(new JDomDriver()); 22 addDriverTest(new StaxDriver()); 23 addDriverTest(new XppDomDriver()); 24 addDriverTest(new XppDriver()); 25 } 26 27 private void test(HierarchicalStreamDriver driver) { 28 XStream xstream = new XStream(driver); 29 30 Object in = new Software("some vendor", "some name"); 31 String xml = xstream.toXML(in); 32 Object out = xstream.fromXML(xml); 33 34 Assert.assertEquals(in, out); 35 } 36 37 private void addDriverTest(final HierarchicalStreamDriver driver) { 38 String testName = getShortName(driver); 39 addTest(new TestCase(testName) { 40 protected void runTest() throws Throwable { 41 test(driver); 42 } 43 }); 44 } 45 46 private String getShortName(HierarchicalStreamDriver driver) { 47 String result = driver.getClass().getName(); 48 result = result.substring(result.lastIndexOf('.') + 1); 49 return result; 50 } 51 52 } 53 | Popular Tags |