View Javadoc
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 junit.framework.TestCase;
24  import org.dbunit.dataset.datatype.DataType;
25  import org.dbunit.dataset.datatype.IntegerDataType;
26  
27  import java.sql.Types;
28  
29  /**
30   *
31   * @author Jarvis Cochrane (jarvis@cochrane.com.au)
32   * @author Roberto Lo Giacco (rlogiacco@users.sourceforge.ent)
33   * @author Martin Gollogly (zemertz@gmail.com)
34   * @since 2.4.5 (Apr 27, 2009)
35   */
36  public class PostgresqlDataTypeFactoryTest extends TestCase {
37  
38      public PostgresqlDataTypeFactoryTest(String testName) {
39          super(testName);
40      }
41  
42      /**
43       * Test of createDataType method, of class PostgresqlDataTypeFactory.
44       */
45      public void testCreateUuidType() throws Exception {
46  
47          PostgresqlDataTypeFactory instance = new PostgresqlDataTypeFactory();
48  
49          // Test UUID type created properly
50          int sqlType = Types.OTHER;
51          String sqlTypeName = "uuid";
52  
53          DataType result = instance.createDataType(sqlType, sqlTypeName);
54          assertTrue(result instanceof UuidType);
55      }
56  
57      public void testCreateIntervalType() throws Exception {
58  
59          PostgresqlDataTypeFactory instance = new PostgresqlDataTypeFactory();
60  
61          // Test interval type created properly
62          int sqlType = Types.OTHER;
63          String sqlTypeName = "interval";
64  
65          DataType result = instance.createDataType(sqlType, sqlTypeName);
66          assertTrue(result instanceof IntervalType);
67      }
68  
69      public void testCreateInetType() throws Exception {
70  
71          PostgresqlDataTypeFactory instance = new PostgresqlDataTypeFactory();
72  
73          // Test inet type created properly
74          int sqlType = Types.OTHER;
75          String sqlTypeName = "inet";
76  
77          DataType result = instance.createDataType(sqlType, sqlTypeName);
78          assertTrue(result instanceof InetType);
79      }
80  
81  
82      public void testCreateCitextType() throws Exception {
83  
84          PostgresqlDataTypeFactory instance = new PostgresqlDataTypeFactory();
85  
86          // Test CITEXT type created properly
87          int sqlType = Types.OTHER;
88          String sqlTypeName = "citext";
89  
90          DataType result = instance.createDataType(sqlType, sqlTypeName);
91          assertTrue(result instanceof CitextType);
92      }
93  
94      public void testCreateEnumType() throws Exception {
95  
96          PostgresqlDataTypeFactory instance = new PostgresqlDataTypeFactory(){
97              public boolean isEnumType(String sqlTypeName) {
98                  if(sqlTypeName.equalsIgnoreCase("abc_enum")){
99                      return true;
100                 }
101                 return false;
102             }
103         };
104 
105         // Test Enum type created properly
106         int sqlType = Types.OTHER;
107         String sqlTypeName = "abc_enum";
108 
109         DataType result = instance.createDataType(sqlType, sqlTypeName);
110         assertTrue(result instanceof GenericEnumType);
111         assertEquals("abc_enum", ((GenericEnumType)result).getSqlTypeName());
112     }
113 
114     public void testCreateDefaultType() throws Exception {
115 
116         PostgresqlDataTypeFactory instance = new PostgresqlDataTypeFactory();
117 
118         int sqlType = Types.INTEGER;
119         String sqlTypeName = "int";
120 
121         DataType result = instance.createDataType(sqlType, sqlTypeName);
122         assertTrue(result instanceof IntegerDataType);
123     }
124 
125     public void testPostgreSQLOidType() throws Exception {
126 
127         PostgresqlDataTypeFactory instance = new PostgresqlDataTypeFactory();
128 
129         int sqlType = Types.BIGINT;
130         String sqlTypeName = "oid";
131 
132         DataType result = instance.createDataType(sqlType, sqlTypeName);
133         assertTrue(result instanceof PostgreSQLOidDataType);
134     }
135 }