KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > schema > TestDataTypeMapper


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17
18 package org.apache.commons.betwixt.schema;
19
20 import java.math.BigDecimal JavaDoc;
21 import java.math.BigInteger JavaDoc;
22
23 import junit.framework.TestCase;
24
25 /**
26  * Tests for <code>DataTypeMapper</code>
27  * both usages and implementations.
28  * @author <a HREF='http://jakarta.apache.org/'>Jakarta Commons Team</a>
29  * @version $Revision: 1.2 $
30  */

31 public class TestDataTypeMapper extends TestCase {
32
33     public TestDataTypeMapper(String JavaDoc testName) {
34         super(testName);
35     }
36
37     public void testDefaultDataTypeMapping() throws Exception JavaDoc {
38         DefaultDataTypeMapper mapper = new DefaultDataTypeMapper();
39         assertEquals("java.lang.String", "xsd:string", mapper.toXMLSchemaDataType(String JavaDoc.class));
40         assertEquals("java.math.BigInteger", "xsd:integer", mapper.toXMLSchemaDataType(BigInteger JavaDoc.class));
41         assertEquals("java.math.BigDecimal", "xsd:decimal", mapper.toXMLSchemaDataType(BigDecimal JavaDoc.class));
42         assertEquals("Integer", "xsd:int", mapper.toXMLSchemaDataType(Integer.TYPE));
43         assertEquals("int", "xsd:int", mapper.toXMLSchemaDataType(Integer JavaDoc.class));
44         assertEquals("Long", "xsd:long", mapper.toXMLSchemaDataType(Long.TYPE));
45         assertEquals("long", "xsd:long", mapper.toXMLSchemaDataType(Long JavaDoc.class));
46         assertEquals("Short", "xsd:short", mapper.toXMLSchemaDataType(Short.TYPE));
47         assertEquals("short", "xsd:short", mapper.toXMLSchemaDataType(Short JavaDoc.class));
48         assertEquals("Float", "xsd:float", mapper.toXMLSchemaDataType(Float.TYPE));
49         assertEquals("float", "xsd:float", mapper.toXMLSchemaDataType(Float JavaDoc.class));
50         assertEquals("Double", "xsd:double", mapper.toXMLSchemaDataType(Double.TYPE));
51         assertEquals("double", "xsd:double", mapper.toXMLSchemaDataType(Double JavaDoc.class));
52         assertEquals("Boolean", "xsd:boolean", mapper.toXMLSchemaDataType(Boolean.TYPE));
53         assertEquals("boolean", "xsd:boolean", mapper.toXMLSchemaDataType(Boolean JavaDoc.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 JavaDoc.class));
57         assertEquals("java.sql.Date", "xsd:date", mapper.toXMLSchemaDataType(java.sql.Date JavaDoc.class));
58         assertEquals("java.sql.Time", "xsd:time", mapper.toXMLSchemaDataType(java.sql.Time JavaDoc.class));
59     }
60     
61     public void testDefaultDataTypeTransciption() throws Exception JavaDoc {
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