1 9 10 package test.dom4j.datatype; 11 12 import junit.framework.Test; 13 import junit.framework.TestSuite; 14 import junit.textui.TestRunner; 15 import org.dom4j.DocumentFactory; 16 import org.dom4j.datatype.DatatypeDocumentFactory; 17 import org.dom4j.io.SAXReader; 18 19 import java.math.BigInteger ; 20 import java.util.Calendar ; 21 22 23 29 public class TestAutoSchema extends AbstractDataTypeTest { 30 31 public static void main( String [] args ) { 32 TestRunner.run( suite() ); 33 } 34 35 public static Test suite() { 36 return new TestSuite( TestAutoSchema.class ); 37 } 38 39 public TestAutoSchema(String name) { 40 super(name); 41 } 42 43 public void testIntAttribute() throws Exception { 46 testNodes( "//person/@x", Integer .class ); 47 } 48 49 public void testIntElement() throws Exception { 50 testNodes( "//person/salary", Integer .class ); 51 } 52 53 public void testString() throws Exception { 54 testNodes( "//person/note", String .class ); 55 } 56 57 public void testDate() throws Exception { 58 testNodes( "//person/@d", Calendar .class ); 59 } 60 61 public void testDateTime() throws Exception { 62 testNodes( "//person/@dt", Calendar .class ); 63 } 64 65 public void testInteger() throws Exception { 66 testNodes( "//person/@age", BigInteger .class ); 67 } 68 69 70 protected void setUp() throws Exception { 73 DocumentFactory factory = loadDocumentFactory(); 74 75 SAXReader reader = new SAXReader( factory ); 76 String uri = getDocumentURI(); 77 78 log( "Parsing: " + uri ); 79 80 document = reader.read( uri ); 81 } 82 83 protected String getDocumentURI() { 84 return "xml/test/schema/personal-schema.xml"; 85 } 86 87 protected DocumentFactory loadDocumentFactory() throws Exception { 89 return DatatypeDocumentFactory.getInstance(); 90 } 91 92 } 93 94 95 96 97 141 | Popular Tags |