KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbunit > database > ForwardOnlyResultSetTableTest


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.database;
22
23 import org.dbunit.DatabaseEnvironment;
24 import org.dbunit.dataset.Column;
25 import org.dbunit.dataset.ForwardOnlyTableTest;
26 import org.dbunit.dataset.ITable;
27 import org.dbunit.dataset.MockTableMetaData;
28 import org.dbunit.dataset.RowOutOfBoundsException;
29 import org.dbunit.operation.DatabaseOperation;
30
31 /**
32  * @author Manuel Laflamme
33  * @since Apr 11, 2003
34  * @version $Revision: 1.5 $
35  */

36 public class ForwardOnlyResultSetTableTest extends ForwardOnlyTableTest
37 {
38     public ForwardOnlyResultSetTableTest(String JavaDoc s)
39     {
40         super(s);
41     }
42
43     protected ITable createTable() throws Exception JavaDoc
44     {
45         DatabaseEnvironment env = DatabaseEnvironment.getInstance();
46         IDatabaseConnection connection = env.getConnection();
47
48         DatabaseOperation.CLEAN_INSERT.execute(connection, env.getInitDataSet());
49
50         String JavaDoc selectStatement = "select * from test_table order by COLUMN0";
51         return new ForwardOnlyResultSetTable("TEST_TABLE", selectStatement, connection);
52     }
53
54     public void testGetMissingValue() throws Exception JavaDoc
55     {
56         // Do not test this!
57
}
58
59     public void testGetValueOnLastRowIsClosingResultSet() throws Exception JavaDoc
60     {
61         String JavaDoc tableName = "TABLE";
62         String JavaDoc[] columnNames = {"C0"};
63 // String[] columnNames = {"C0", "C1", "C2"};
64
Object JavaDoc[][] expectedValues = new Object JavaDoc[][]{
65             new Object JavaDoc[]{"1", "2", "3"},
66             new Object JavaDoc[]{"4", "5", "6"},
67             new Object JavaDoc[]{"7", "8", "9"},
68         };
69
70         // Setup resultset
71
ExtendedMockMultiRowResultSet resultSet = new ExtendedMockMultiRowResultSet();
72         resultSet.setExpectedCloseCalls(1);
73         resultSet.setupColumnNames(columnNames);
74         resultSet.setupRows(expectedValues);
75
76         // Create table
77
MockTableMetaData metaData = new MockTableMetaData(tableName, columnNames);
78         ForwardOnlyResultSetTable table =
79                 new ForwardOnlyResultSetTable(metaData, resultSet);
80
81         // Excercise getValue()
82
try
83         {
84             Column[] columns = table.getTableMetaData().getColumns();
85
86             for (int i = 0; ; i++)
87             {
88                 for (int j = 0; j < columns.length; j++)
89                 {
90                     String JavaDoc columnName = columns[j].getColumnName();
91                     Object JavaDoc actualValue = table.getValue(i, columnName);
92                     Object JavaDoc expectedValue = expectedValues[i][j];
93                     assertEquals("row=" + i + ", col=" + columnName,
94                             expectedValue, actualValue);
95
96                 }
97             }
98         }
99         catch(RowOutOfBoundsException e)
100         {
101             // end of table
102
}
103
104         // Verify that ResultSet have been closed
105
resultSet.verify();
106     }
107
108 }
109
Popular Tags