KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.dbunit.dataset.datatype.DataType;
25
26 /**
27  * @author Manuel Laflamme
28  * @version $Revision: 1.7 $
29  * @since Feb 17, 2002
30  */

31 public class DefaultTableTest extends AbstractTableTest
32 {
33     public DefaultTableTest(String JavaDoc s)
34     {
35         super(s);
36     }
37
38     protected ITable createTable() throws Exception JavaDoc
39     {
40         return createTable(COLUMN_COUNT, ROW_COUNT, 0);
41     }
42
43     protected ITable createTable(int columnCount, int rowCount, int startRow)
44             throws Exception JavaDoc
45     {
46         DefaultTable table = new DefaultTable(createTableMetaData(columnCount));
47         for (int i = 0; i < rowCount; i++)
48         {
49             Object JavaDoc[] rowValues = new Object JavaDoc[columnCount];
50             for (int j = 0; j < rowValues.length; j++)
51             {
52                 rowValues[j] = "row " + (i + startRow) + " col " + j;
53             }
54             table.addRow(rowValues);
55         }
56         return table;
57     }
58
59     protected ITableMetaData createTableMetaData(int columnCount) throws Exception JavaDoc
60     {
61         Column[] columns = new Column[columnCount];
62         for (int i = 0; i < columns.length; i++)
63         {
64             columns[i] = new Column("COLUMN" + i, DataType.UNKNOWN);
65         }
66
67         return new DefaultTableMetaData("myTable", columns);
68     }
69
70     public void testGetMissingValue() throws Exception JavaDoc
71     {
72         String JavaDoc columnName = "COLUMN0";
73         Object JavaDoc expected = ITable.NO_VALUE;
74
75         DefaultTable table = new DefaultTable(createTableMetaData(COLUMN_COUNT));
76         table.addRow(new Object JavaDoc[]{ITable.NO_VALUE, ITable.NO_VALUE, ITable.NO_VALUE,
77                                   ITable.NO_VALUE, ITable.NO_VALUE, ITable.NO_VALUE});
78         Column[] columns = table.getTableMetaData().getColumns();
79         assertNotNull(DataSetUtils.getColumn(columnName, columns));
80         assertEquals("no value", expected, table.getValue(0, columnName));
81     }
82
83 }
84
85
86
87
88
Popular Tags