1   /*
2    *
3    * The DbUnit Database Testing Framework
4    * Copyright (C)2002-2009, DbUnit.org
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 2.1 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   *
20   */
21  package org.dbunit.ext.postgresql;
22  
23  import java.sql.Types;
24  import junit.framework.TestCase;
25  import org.dbunit.dataset.datatype.DataType;
26  import org.dbunit.dataset.datatype.IntegerDataType;
27  
28  /**
29   *
30   * @author Jarvis Cochrane (jarvis@cochrane.com.au)
31   * @author Roberto Lo Giacco (rlogiacco@users.sourceforge.ent)
32   * @since 2.4.5 (Apr 27, 2009)
33   */
34  public class PostgresqlDataTypeFactoryTest extends TestCase {
35  
36      public PostgresqlDataTypeFactoryTest(String testName) {
37          super(testName);
38      }
39  
40      /**
41       * Test of createDataType method, of class PostgresqlDataTypeFactory.
42       */
43      public void testCreateUuidType() throws Exception {
44  
45          PostgresqlDataTypeFactory instance = new PostgresqlDataTypeFactory();
46  
47          // Test UUID type created properly
48          int sqlType = Types.OTHER;
49          String sqlTypeName = "uuid";
50  
51          DataType result = instance.createDataType(sqlType, sqlTypeName);
52          assertTrue(result instanceof UuidType);
53      }
54      
55      public void testCreateIntervalType() throws Exception {
56  
57          PostgresqlDataTypeFactory instance = new PostgresqlDataTypeFactory();
58  
59          // Test interval type created properly
60          int sqlType = Types.OTHER;
61          String sqlTypeName = "interval";
62  
63          DataType result = instance.createDataType(sqlType, sqlTypeName);
64          assertTrue(result instanceof IntervalType);
65      }
66  
67      public void testCreateInetType() throws Exception {
68  
69          PostgresqlDataTypeFactory instance = new PostgresqlDataTypeFactory();
70  
71          // Test inet type created properly
72          int sqlType = Types.OTHER;
73          String sqlTypeName = "inet";
74  
75          DataType result = instance.createDataType(sqlType, sqlTypeName);
76          assertTrue(result instanceof InetType);
77      }
78  
79      public void testCreateEnumType() throws Exception {
80  
81          PostgresqlDataTypeFactory instance = new PostgresqlDataTypeFactory(){
82              public boolean isEnumType(String sqlTypeName) {
83                  if(sqlTypeName.equalsIgnoreCase("abc_enum")){
84                      return true;
85                  }
86                  return false;
87              }
88          };
89  
90          // Test Enum type created properly
91          int sqlType = Types.OTHER;
92          String sqlTypeName = "abc_enum";
93  
94          DataType result = instance.createDataType(sqlType, sqlTypeName);
95          assertTrue(result instanceof GenericEnumType);
96          assertEquals("abc_enum", ((GenericEnumType)result).getSqlTypeName());
97      }
98  
99      public void testCreateDefaultType() throws Exception {
100 
101         PostgresqlDataTypeFactory instance = new PostgresqlDataTypeFactory();
102 
103         int sqlType = Types.INTEGER;
104         String sqlTypeName = "int";
105 
106         DataType result = instance.createDataType(sqlType, sqlTypeName);
107         assertTrue(result instanceof IntegerDataType);
108     }
109 
110 }