package sample; import java.io.File; import java.io.FileReader; import java.io.PrintWriter; import java.io.StringReader; import java.io.StringWriter; import junit.framework.TestCase; import org.exolab.castor.mapping.Mapping; import org.exolab.castor.xml.Marshaller; import org.exolab.castor.xml.Unmarshaller; import org.xml.sax.InputSource; public class CastorConstructorWithArgumentsTest extends TestCase { private SimpleMessage msg1; private SimpleMessage msg2; private SimpleMessage msg3; private Unmarshaller unmarshaller; private File f; public CastorConstructorWithArgumentsTest(String s) { super(s); } protected void setUp() throws Exception { super.setUp(); msg1 = new SimpleMessage("cannot delete temporary file", Severity.WARNING); msg2 = new SimpleMessage("marked object as obsolete", Severity.WARNING); msg3 = new SimpleMessage("must shut down system", Severity.ERROR); Mapping mapping = new Mapping(); f = new File("map3.xml"); mapping.loadMapping(new InputSource(new FileReader(f))); unmarshaller = new Unmarshaller(); unmarshaller.setValidation(true); unmarshaller.setLogWriter(new PrintWriter(System.err)); unmarshaller.setMapping(mapping); } public void testWrite() throws Exception { Mapping mapping = new Mapping(); 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(msg1); marshaller.marshal(msg2); marshaller.marshal(msg3); out.close(); assertTrue(out.toString().length() > 0); System.out.println(out); } public void testReadWarning() throws Exception { String s = ""; SimpleMessage simple = (SimpleMessage) unmarshaller .unmarshal(new StringReader(s)); assertNotNull(simple); assertEquals(msg1.severity(), simple.severity()); assertEquals(msg1.formattedText(), simple.formattedText()); } public void testReadError() throws Exception { String s = ""; SimpleMessage simple = (SimpleMessage) unmarshaller .unmarshal(new StringReader(s)); assertNotNull(simple); assertEquals(msg3.severity(), simple.severity()); assertEquals(msg3.formattedText(), simple.formattedText()); } }