KickJava   Java API By Example, From Geeks To Geeks.

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


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.9 $
30  * @since Feb 17, 2002
31  */

32 public class DefaultTableMetaDataTest extends TestCase
33 {
34     public DefaultTableMetaDataTest(String JavaDoc s)
35     {
36         super(s);
37     }
38
39     protected ITableMetaData createMetaData(String JavaDoc tableName,
40             Column[] columns, String JavaDoc[] keyNames) throws Exception JavaDoc
41     {
42         return new DefaultTableMetaData(
43                         tableName, columns, keyNames);
44     }
45
46     public void testGetTableName() throws Exception JavaDoc
47     {
48         String JavaDoc expected = "tableName";
49         ITableMetaData metaData = createMetaData(expected, null, null);
50
51         assertEquals("table name", expected, metaData.getTableName());
52     }
53
54     public void testGetColumns() throws Exception JavaDoc
55     {
56         Column[] columns = new Column[]{
57             new Column("numberColumn", DataType.NUMERIC),
58             new Column("stringColumn", DataType.VARCHAR),
59             new Column("booleanColumn", DataType.BOOLEAN),
60         };
61
62         ITableMetaData metaData = createMetaData("toto", columns, null);
63
64         assertEquals("column count", columns.length, metaData.getColumns().length);
65         for (int i = 0; i < columns.length; i++)
66         {
67             Column column = columns[i];
68             assertEquals("columns" + i, column, metaData.getColumns()[i]);
69         }
70         assertEquals("key count", 0, metaData.getPrimaryKeys().length);
71     }
72
73     public void testGetPrimaryKeys() throws Exception JavaDoc
74     {
75         Column[] columns = new Column[]{
76             new Column("numberColumn", DataType.NUMERIC),
77             new Column("stringColumn", DataType.VARCHAR),
78             new Column("booleanColumn", DataType.BOOLEAN),
79         };
80         String JavaDoc[] keyNames = new String JavaDoc[]{"booleanColumn", "numberColumn"};
81
82
83         ITableMetaData metaData = createMetaData("toto", columns, keyNames);
84
85         Column[] keys = metaData.getPrimaryKeys();
86         assertEquals("key count", keyNames.length, keys.length);
87         for (int i = 0; i < keys.length; i++)
88         {
89             assertEquals("key name", keyNames[i], keys[i].getColumnName());
90         }
91     }
92
93     public void testGetPrimaryKeysColumnDontMatch() throws Exception JavaDoc
94     {
95         Column[] columns = new Column[]{
96             new Column("numberColumn", DataType.NUMERIC),
97             new Column("stringColumn", DataType.VARCHAR),
98             new Column("booleanColumn", DataType.BOOLEAN),
99         };
100         String JavaDoc[] keyNames = new String JavaDoc[]{"invalidColumn"};
101
102
103         ITableMetaData metaData = createMetaData("toto", columns, keyNames);
104
105         Column[] keys = metaData.getPrimaryKeys();
106         assertEquals("key count", 0, keys.length);
107     }
108 }
109
110
111
112
113
114
Popular Tags