01: package net.sourceforge.jaxor.generator.tests;
02:
03: import junit.framework.TestCase;
04: import net.sourceforge.jaxor.generator.Sql2JavaMapping;
05:
06: import java.sql.Types;
07:
08: /**
09: * Created By: fede
10: * Date: 2-feb-2004
11: * Time: 9.59.16
12: *
13: * Last Checkin: $Author: mrettig $
14: * Date: $Date: 2004/02/13 05:23:06 $
15: * Revision: $Revision: 1.7 $
16: */
17: public class Sql2JavaMappingTest extends TestCase {
18: private Sql2JavaMapping mapping;
19:
20: protected void setUp() throws Exception {
21: mapping = new Sql2JavaMapping();
22: }
23:
24: public void testTheDefaultMappingsFollowsTheJdbcStandard() {
25: assertEquals(java.math.BigDecimal.class.getName(), mapping
26: .getByTypeCode(Types.NUMERIC));
27: assertEquals("Boolean", mapping.getByTypeCode(Types.BIT));
28: assertEquals("Byte", mapping.getByTypeCode(Types.TINYINT));
29: assertEquals("java.sql.Date", mapping.getByTypeCode(Types.DATE));
30: assertEquals("Double", mapping.getByTypeCode(Types.DOUBLE));
31: assertEquals("Float", mapping.getByTypeCode(Types.REAL));
32: assertEquals("Integer", mapping.getByTypeCode(Types.INTEGER));
33: assertEquals("Long", mapping.getByTypeCode(Types.BIGINT));
34: assertEquals("Short", mapping.getByTypeCode(Types.SMALLINT));
35: assertEquals("String", mapping.getByTypeCode(Types.VARCHAR));
36: assertEquals("java.sql.Timestamp", mapping
37: .getByTypeCode(Types.TIMESTAMP));
38: assertEquals("Double", mapping.getByTypeCode(Types.DECIMAL));
39: }
40:
41: public void testNewMappingsCanBeAddedByTypeName() {
42: mapping = new Sql2JavaMapping();
43: mapping.register("DB2XML.XMLCLOB", "String");
44: assertEquals("String", mapping.getByTypeName("DB2XML.XMLCLOB"));
45: }
46:
47: public void testReturnUnknownDataTypeWhenSearchedForNonExistentMapping() {
48: final int typeCode = 0;
49: assertEquals(Sql2JavaMapping.UNKNOW_DATA_TYPE, mapping
50: .getByTypeName("FOO"));
51: assertEquals(Sql2JavaMapping.UNKNOW_DATA_TYPE, mapping
52: .getByTypeCode(typeCode));
53: assertEquals(Sql2JavaMapping.UNKNOW_DATA_TYPE, mapping
54: .getByTypeNameOrCode("FOO", typeCode));
55: }
56:
57: public void testMappingCanBeSearchedByTypeCodeOrTypeName() {
58: assertEquals("java.sql.Timestamp", mapping.getByTypeNameOrCode(
59: "FOO", Types.TIMESTAMP));
60: }
61: }
|