View Javadoc
1   /*
2    *
3    * The DbUnit Database Testing Framework
4    * Copyright (C)2002-2004, 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.mysql;
22  
23  import org.dbunit.dataset.datatype.AbstractDataTypeFactoryTest;
24  import org.dbunit.dataset.datatype.DataType;
25  import org.dbunit.dataset.datatype.IDataTypeFactory;
26  
27  import java.sql.Types;
28  
29  /**
30   * @author Manuel Laflamme
31   * @since Sep 3, 2003
32   * @version $Revision$
33   */
34  public class MySqlDataTypeFactoryTest extends AbstractDataTypeFactoryTest
35  {
36      public MySqlDataTypeFactoryTest(String s)
37      {
38          super(s);
39      }
40  
41      public IDataTypeFactory createFactory() throws Exception
42      {
43          return new MySqlDataTypeFactory();
44      }
45  
46      public void testCreateLongtextDataType() throws Exception
47      {
48          DataType actual = createFactory().createDataType(Types.OTHER, "longtext");
49          DataType expected = DataType.CLOB;
50          assertSame("type", expected, actual);
51      }
52  
53      public void testCreateLongtextUpperCaseDataType() throws Exception
54      {
55          // MySql 5 reports the datatypes in uppercase, so this here must also work
56          DataType actual = createFactory().createDataType(Types.OTHER, "LONGTEXT");
57          DataType expected = DataType.CLOB;
58          assertSame("type", expected, actual);
59      }
60  
61      public void testCreateBooleanDataType() throws Exception
62      {
63          DataType actual = createFactory().createDataType(Types.OTHER, "bit");
64          DataType expected = DataType.BOOLEAN;
65          assertSame("type", expected, actual);
66      }
67      
68      public void testCreateBooleanUpperCaseDataType() throws Exception
69      {
70          // MySql 5 reports the datatypes in uppercase, so this here must also work
71          DataType actual = createFactory().createDataType(Types.OTHER, "BIT");
72          DataType expected = DataType.BOOLEAN;
73          assertSame("type", expected, actual);
74      }
75  
76      public void testCreatePointDataType() throws Exception
77      {
78          DataType actual = createFactory().createDataType(Types.OTHER, "point");
79          DataType expected = DataType.BINARY;
80          assertSame("type", expected, actual);
81      }
82  
83      public void testCreatePointUpperCaseDataType() throws Exception
84      {
85          // MySql 5 reports the datatypes in uppercase, so this here must also work
86          DataType actual = createFactory().createDataType(Types.OTHER, "POINT");
87          DataType expected = DataType.BINARY;
88          assertSame("type", expected, actual);
89      }
90  
91      public void testCreateTinyintUnsignedDatatype() throws Exception
92      {
93          int sqlType = Types.BIT; // MySqlConnector/J reports "TINYINT UNSIGNED" columns as SQL type "BIT".
94          String sqlTypeName = MySqlDataTypeFactory.SQL_TYPE_NAME_TINYINT_UNSIGNED;
95  
96          DataType expected = DataType.TINYINT;
97          DataType actual = createFactory().createDataType(sqlType, sqlTypeName);
98          assertSame("type", expected, actual);
99      }
100 
101     public void testCreateIntegerUnsignedDatatype() throws Exception
102     {
103         int sqlType = Types.INTEGER;
104         String sqlTypeName = "INTEGER" + MySqlDataTypeFactory.UNSIGNED_SUFFIX;
105 
106         DataType expected = DataType.BIGINT;
107         DataType actual = createFactory().createDataType(sqlType, sqlTypeName);
108         assertSame("type", expected, actual);
109     }
110 
111 }