package org.exolab.castor.xml.schema.util; import java.io.IOException; import java.io.StringReader; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; /** * Test for XMLInstance2Schema. Intended to test error with * DatatypeHandler converting an invalid time value. * @author Doug Daniels * */ public class TestXMLInstance2Schema extends TestCase { private static final String TEST_DATE_XML = "" + "\n" + " \n" + " 4295 Mbs\n" + " \n" + ""; public TestXMLInstance2Schema(String name) { super(name); } /** * Tests the Date Time data type guessing conversion failure, which * should result in a datatype of String, and not an exception being * thrown. * */ public void testDateTimeConversion() { StringReader reader = new StringReader(TEST_DATE_XML); XMLInstance2Schema xml2schema = new XMLInstance2Schema(); try { //Any exception is considered a failure. //Date Time conversion should fail and then String should be //the data typer used. xml2schema.createSchema(reader); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } } /** * Default suite method */ public static Test suite() { return new TestSuite(TestXMLInstance2Schema.class); } /** * Quick test harness. * @param args */ public static void main(String[] args) { try { TestSuite suite = new TestSuite(); if (args.length != 0) { // Run specific tests as indicated from the // command line for (int i = 0; i < args.length; i++) { suite.addTest(new TestXMLInstance2Schema(args[i])); } } else { // Dynamically discover all of them, or use // user-defined suite suite.addTest(TestXMLInstance2Schema.suite()); } junit.textui.TestRunner.run(suite); } catch (Exception e) { e.printStackTrace(); } } }