package sample; import java.io.File; import java.io.FileReader; import java.io.PrintWriter; import java.io.StringWriter; import junit.framework.TestCase; import org.exolab.castor.mapping.Mapping; import org.exolab.castor.xml.Marshaller; import org.xml.sax.InputSource; public class CastorMappingIdTest extends TestCase { private Department department; public CastorMappingIdTest(String s) { super(s); } protected void setUp() throws Exception { super.setUp(); Person john = new Person("id-1", "John"); Person susan = new Person("id-2", "Susan"); department = new Department(); department.add(john); department.add(susan); } public void testCompatibility_1() throws Exception { Mapping mapping = new Mapping(); File f = new File("map1.xml"); mapping.loadMapping(new InputSource(new FileReader(f))); StringWriter out = new StringWriter(); Marshaller marshaller = new Marshaller(out); marshaller.setValidation(true); marshaller.setLogWriter(new PrintWriter(System.err)); marshaller.setMapping(mapping); marshaller.marshal(department); out.close(); assertTrue(out.toString().length() > 0); System.out.println(out); } public void testCompatibility_2() throws Exception { Mapping mapping = new Mapping(); File f = new File("map2.xml"); mapping.loadMapping(new InputSource(new FileReader(f))); StringWriter out = new StringWriter(); Marshaller marshaller = new Marshaller(out); marshaller.setValidation(true); marshaller.setMapping(mapping); marshaller.marshal(department); out.close(); assertTrue(out.toString().length() > 0); System.out.println(out); } }