1 16 17 18 package org.apache.commons.betwixt.schema; 19 20 import java.math.BigDecimal ; 21 import java.math.BigInteger ; 22 23 import junit.framework.TestCase; 24 25 31 public class TestDataTypeMapper extends TestCase { 32 33 public TestDataTypeMapper(String testName) { 34 super(testName); 35 } 36 37 public void testDefaultDataTypeMapping() throws Exception { 38 DefaultDataTypeMapper mapper = new DefaultDataTypeMapper(); 39 assertEquals("java.lang.String", "xsd:string", mapper.toXMLSchemaDataType(String .class)); 40 assertEquals("java.math.BigInteger", "xsd:integer", mapper.toXMLSchemaDataType(BigInteger .class)); 41 assertEquals("java.math.BigDecimal", "xsd:decimal", mapper.toXMLSchemaDataType(BigDecimal .class)); 42 assertEquals("Integer", "xsd:int", mapper.toXMLSchemaDataType(Integer.TYPE)); 43 assertEquals("int", "xsd:int", mapper.toXMLSchemaDataType(Integer .class)); 44 assertEquals("Long", "xsd:long", mapper.toXMLSchemaDataType(Long.TYPE)); 45 assertEquals("long", "xsd:long", mapper.toXMLSchemaDataType(Long .class)); 46 assertEquals("Short", "xsd:short", mapper.toXMLSchemaDataType(Short.TYPE)); 47 assertEquals("short", "xsd:short", mapper.toXMLSchemaDataType(Short .class)); 48 assertEquals("Float", "xsd:float", mapper.toXMLSchemaDataType(Float.TYPE)); 49 assertEquals("float", "xsd:float", mapper.toXMLSchemaDataType(Float .class)); 50 assertEquals("Double", "xsd:double", mapper.toXMLSchemaDataType(Double.TYPE)); 51 assertEquals("double", "xsd:double", mapper.toXMLSchemaDataType(Double .class)); 52 assertEquals("Boolean", "xsd:boolean", mapper.toXMLSchemaDataType(Boolean.TYPE)); 53 assertEquals("boolean", "xsd:boolean", mapper.toXMLSchemaDataType(Boolean .class)); 54 assertEquals("Byte", "xsd:byte", mapper.toXMLSchemaDataType(Byte.TYPE)); 55 assertEquals("byte", "xsd:byte", mapper.toXMLSchemaDataType(byte.class)); 56 assertEquals("java.util.Date", "xsd:dateTime", mapper.toXMLSchemaDataType(java.util.Date .class)); 57 assertEquals("java.sql.Date", "xsd:date", mapper.toXMLSchemaDataType(java.sql.Date .class)); 58 assertEquals("java.sql.Time", "xsd:time", mapper.toXMLSchemaDataType(java.sql.Time .class)); 59 } 60 61 public void testDefaultDataTypeTransciption() throws Exception { 62 Schema expected = new Schema(); 63 64 GlobalComplexType allSimplesBeanType = new GlobalComplexType(); 65 allSimplesBeanType.setName("org.apache.commons.betwixt.schema.AllSimplesBean"); 66 allSimplesBeanType.addElement(new SimpleLocalElement("string", "xsd:string")); 67 allSimplesBeanType.addElement(new SimpleLocalElement("bigInteger", "xsd:integer")); 68 allSimplesBeanType.addElement(new SimpleLocalElement("primitiveInt", "xsd:int")); 69 allSimplesBeanType.addElement(new SimpleLocalElement("objectInt", "xsd:int")); 70 allSimplesBeanType.addElement(new SimpleLocalElement("primitiveLong", "xsd:long")); 71 allSimplesBeanType.addElement(new SimpleLocalElement("objectLong", "xsd:long")); 72 allSimplesBeanType.addElement(new SimpleLocalElement("primitiveShort", "xsd:short")); 73 allSimplesBeanType.addElement(new SimpleLocalElement("objectShort", "xsd:short")); 74 allSimplesBeanType.addElement(new SimpleLocalElement("bigDecimal", "xsd:decimal")); 75 allSimplesBeanType.addElement(new SimpleLocalElement("primitiveFloat", "xsd:float")); 76 allSimplesBeanType.addElement(new SimpleLocalElement("objectFloat", "xsd:float")); 77 allSimplesBeanType.addElement(new SimpleLocalElement("primitiveDouble", "xsd:double")); 78 allSimplesBeanType.addElement(new SimpleLocalElement("objectDouble", "xsd:double")); 79 allSimplesBeanType.addElement(new SimpleLocalElement("primitiveBoolean", "xsd:boolean")); 80 allSimplesBeanType.addElement(new SimpleLocalElement("objectBoolean", "xsd:boolean")); 81 allSimplesBeanType.addElement(new SimpleLocalElement("primitiveByte", "xsd:byte")); 82 allSimplesBeanType.addElement(new SimpleLocalElement("objectByte", "xsd:byte")); 83 allSimplesBeanType.addElement(new SimpleLocalElement("utilDate", "xsd:dateTime")); 84 allSimplesBeanType.addElement(new SimpleLocalElement("sqlDate", "xsd:date")); 85 allSimplesBeanType.addElement(new SimpleLocalElement("sqlTime", "xsd:time")); 86 87 GlobalElement root = new GlobalElement("AllSimplesBean", "org.apache.commons.betwixt.schema.AllSimplesBean"); 88 expected.addComplexType(allSimplesBeanType); 89 expected.addElement(root); 90 91 SchemaTranscriber transcriber = new SchemaTranscriber(); 92 transcriber.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(false); 93 Schema out = transcriber.generate(AllSimplesBean.class); 94 95 assertEquals("AllSimplesBean schema", expected, out); 96 } 97 } 98 | Popular Tags |