1   package org.apache.torque.engine.database.model;
2   
3   /*
4    * Copyright 2001-2005 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License")
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.sql.Types;
20  
21  import junit.framework.TestCase;
22  
23  /***
24   * Tests for TypeMap.
25   *
26   * @author <a href="mailto:mpoeschl@marmot.at>Martin Poeschl</a>
27   */
28  public class TypeMapTest extends TestCase {
29  
30      public void testGetJavaObject() {
31          assertEquals(TypeMap.getJavaObject(SchemaType.INTEGER), "new Integer(0)");
32      }
33  
34      public void testGetJavaNative() {
35          assertEquals(TypeMap.getJavaNative(SchemaType.INTEGER), "int");
36      }
37  
38      public void testGetJavaNativeObject() {
39          assertEquals(TypeMap.getJavaNativeObject(SchemaType.INTEGER), "Integer");
40      }
41  
42      public void testGetVillageMethod() {
43          assertEquals(TypeMap.getVillageMethod(SchemaType.INTEGER), "asInt()");
44      }
45  
46      public void testGetVillageObjectMethod() {
47          assertEquals(TypeMap.getVillageObjectMethod(SchemaType.INTEGER), "asIntegerObj()");
48      }
49  
50      public void testGetPPMethod() {
51          assertEquals(TypeMap.getPPMethod(SchemaType.INTEGER), "getInt(ppKey)");
52      }
53  
54      public void testGetJdbcType() {
55          assertEquals(TypeMap.getJdbcType(SchemaType.INTEGER), SchemaType.INTEGER);
56          assertEquals(TypeMap.getJdbcType(SchemaType.BOOLEANINT), SchemaType.INTEGER);
57      }
58  
59      public void testGetTorqueType() {
60          assertEquals(TypeMap.getTorqueType(new Integer(Types.FLOAT)),
61                  SchemaType.FLOAT);
62          assertEquals(TypeMap.getTorqueType(new Integer(Types.CHAR)),
63                  SchemaType.CHAR);
64      }
65  
66      public void testIsBooleanInt() {
67          assertFalse(TypeMap.isBooleanInt(SchemaType.FLOAT));
68          assertTrue(TypeMap.isBooleanInt(SchemaType.BOOLEANINT));
69      }
70  
71      public void testIsBooleanChar() {
72          assertFalse(TypeMap.isBooleanChar(SchemaType.FLOAT));
73          assertTrue(TypeMap.isBooleanChar(SchemaType.BOOLEANCHAR));
74      }
75  
76      public void testIsTextType() {
77          assertFalse(TypeMap.isTextType(SchemaType.FLOAT));
78          assertTrue(TypeMap.isTextType(SchemaType.CHAR));
79      }
80  
81  }