KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbunit > dataset > LowerCaseTableMetaDataTest


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
22 package org.dbunit.dataset;
23
24 import junit.framework.TestCase;
25 import org.dbunit.dataset.datatype.DataType;
26
27 /**
28  * @author Manuel Laflamme
29  * @version $Revision: 1.3 $
30  * @since Feb 17, 2002
31  */

32 public class LowerCaseTableMetaDataTest extends TestCase
33 {
34     public LowerCaseTableMetaDataTest(String JavaDoc s)
35     {
36         super(s);
37     }
38
39     public void testGetTableName() throws Exception JavaDoc
40     {
41         String JavaDoc original = "TABLE_NAME";
42         String JavaDoc expected = original.toLowerCase();
43
44         ITableMetaData metaData = new LowerCaseTableMetaData(
45                 new DefaultTableMetaData(original, new Column[0]));
46
47         assertEquals("table name", expected, metaData.getTableName());
48     }
49
50     public void testGetColumns() throws Exception JavaDoc
51     {
52         Column[] columns = new Column[]{
53             new Column("NUMBER_COLUMN", DataType.NUMERIC, "qwerty", Column.NULLABLE),
54             new Column("STRING_COLUMN", DataType.VARCHAR, "toto", Column.NO_NULLS),
55             new Column("BOOLEAN_COLUMN", DataType.BOOLEAN),
56         };
57
58         ITableMetaData metaData = new LowerCaseTableMetaData(
59                 "TABLE_NAME", columns);
60
61         Column[] lowerColumns = metaData.getColumns();
62         assertEquals("column count", columns.length, lowerColumns.length);
63         for (int i = 0; i < columns.length; i++)
64         {
65             Column column = columns[i];
66             Column lowerColumn = lowerColumns[i];
67
68             assertEquals("name", column.getColumnName().toLowerCase(),
69                     lowerColumn.getColumnName());
70             assertTrue("name not equals",
71                     !column.getColumnName().equals(lowerColumn.getColumnName()));
72             assertEquals("type", column.getDataType(), lowerColumn.getDataType());
73             assertEquals("sql type", column.getSqlTypeName(), lowerColumn.getSqlTypeName());
74             assertEquals("nullable", column.getNullable(), lowerColumn.getNullable());
75         }
76         assertEquals("key count", 0, metaData.getPrimaryKeys().length);
77     }
78
79     public void testGetPrimaryKeys() throws Exception JavaDoc
80     {
81         Column[] columns = new Column[]{
82             new Column("NUMBER_COLUMN", DataType.NUMERIC, "qwerty", Column.NULLABLE),
83             new Column("STRING_COLUMN", DataType.VARCHAR, "toto", Column.NO_NULLS),
84             new Column("BOOLEAN_COLUMN", DataType.BOOLEAN),
85         };
86         String JavaDoc[] keyNames = new String JavaDoc[]{"Boolean_Column", "Number_Column"};
87
88
89         ITableMetaData metaData = new LowerCaseTableMetaData(
90                 "TABLE_NAME", columns, keyNames);
91
92         Column[] keys = metaData.getPrimaryKeys();
93         assertEquals("key count", keyNames.length, keys.length);
94         for (int i = 0; i < keys.length; i++)
95         {
96             assertTrue("name not equals",
97                     !keyNames[i].equals(keys[i].getColumnName()));
98             assertEquals("key name", keyNames[i].toLowerCase(),
99                     keys[i].getColumnName());
100         }
101     }
102
103 }
104
105
106
107
108
109
Popular Tags