KickJava   Java API By Example, From Geeks To Geeks.

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


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
26 /**
27  * @author Manuel Laflamme
28  * @version $Revision: 1.10 $
29  * @since Feb 17, 2002
30  */

31 public abstract class AbstractTableTest extends TestCase
32 {
33     protected static final int ROW_COUNT = 6;
34     protected static final int COLUMN_COUNT = 4;
35
36     public AbstractTableTest(String JavaDoc s)
37     {
38         super(s);
39     }
40
41     /**
42      * Creates a table having 6 row and 4 column where columns are named
43      * "COLUMN1, COLUMN2, COLUMN3, COLUMN4" and values are string follwing this
44      * template "row ? col ?"
45      */

46     protected abstract ITable createTable() throws Exception JavaDoc;
47
48     ////////////////////////////////////////////////////////////////////////////
49
// Test methods
50

51     public void testGetRowCount() throws Exception JavaDoc
52     {
53         assertEquals("row count", ROW_COUNT, createTable().getRowCount());
54     }
55
56     public void testTableMetaData() throws Exception JavaDoc
57     {
58         Column[] columns = createTable().getTableMetaData().getColumns();
59         assertEquals("column count", COLUMN_COUNT, columns.length);
60         for (int i = 0; i < columns.length; i++)
61         {
62             String JavaDoc expected = "COLUMN" + i;
63             String JavaDoc actual = columns[i].getColumnName();
64             assertEquals("column name", expected, actual);
65         }
66     }
67
68     public void testGetValue() throws Exception JavaDoc
69     {
70         ITable table = createTable();
71         for (int i = 0; i < ROW_COUNT; i++)
72         {
73             for (int j = 0; j < COLUMN_COUNT; j++)
74             {
75                 String JavaDoc columnName = "COLUMN" + j;
76                 String JavaDoc expected = "row " + i + " col " + j;
77                 Object JavaDoc value = table.getValue(i, columnName);
78                 assertEquals("value", expected, value);
79             }
80         }
81     }
82
83     public void testGetValueCaseInsensitive() throws Exception JavaDoc
84     {
85         ITable table = createTable();
86         for (int i = 0; i < ROW_COUNT; i++)
87         {
88             for (int j = 0; j < COLUMN_COUNT; j++)
89             {
90                 String JavaDoc columnName = "CoLUmN" + j;
91                 String JavaDoc expected = "row " + i + " col " + j;
92                 Object JavaDoc value = table.getValue(i, columnName);
93                 assertEquals("value", expected, value);
94             }
95         }
96     }
97
98     public abstract void testGetMissingValue() throws Exception JavaDoc;
99
100     public void testGetValueRowBounds() throws Exception JavaDoc
101     {
102         int[] rows = new int[]{-2, -1, -ROW_COUNT, ROW_COUNT, ROW_COUNT + 1};
103         ITable table = createTable();
104         String JavaDoc columnName = table.getTableMetaData().getColumns()[0].getColumnName();
105
106         for (int i = 0; i < rows.length; i++)
107         {
108             try
109             {
110                 table.getValue(rows[i], columnName);
111                 fail("Should throw a RowOutOfBoundsException!");
112             }
113             catch (RowOutOfBoundsException e)
114             {
115             }
116         }
117     }
118
119     public void testGetValueAndNoSuchColumn() throws Exception JavaDoc
120     {
121         ITable table = createTable();
122         String JavaDoc columnName = "Unknown";
123
124         try
125         {
126             table.getValue(0, columnName);
127             fail("Should throw a NoSuchColumnException!");
128         }
129         catch (NoSuchColumnException e)
130         {
131         }
132     }
133 }
134
135
136
137
138
139
140
Popular Tags