KickJava   Java API By Example, From Geeks To Geeks.

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


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.dataset.AbstractTableIteratorTest;
24 import org.dbunit.dataset.ITable;
25 import org.dbunit.dataset.ITableIterator;
26 import org.dbunit.dataset.MockDataSet;
27
28 /**
29  * @author Manuel Laflamme
30  * @since Apr 6, 2003
31  * @version $Revision: 1.4 $
32  */

33 public class DatabaseTableIteratorTest extends AbstractTableIteratorTest
34 {
35     public DatabaseTableIteratorTest(String JavaDoc s)
36     {
37         super(s);
38     }
39
40     private MockDataSet createMockDataSet(String JavaDoc[] expectedNames)
41     {
42         MockDataSet dataSet = new MockDataSet();
43         for (int i = 0; i < expectedNames.length; i++)
44         {
45             String JavaDoc tableName = expectedNames[i];
46             MockResultSetTable table = new MockResultSetTable();
47             table.setupTableMetaData(tableName);
48             table.setExpectedCloseCalls(1);
49             dataSet.addTable(table);
50         }
51         return dataSet;
52     }
53
54     protected ITableIterator getIterator() throws Exception JavaDoc
55     {
56         String JavaDoc[] expectedNames = getExpectedNames();
57         MockDataSet dataSet = createMockDataSet(expectedNames);
58
59         return new DatabaseTableIterator(expectedNames, dataSet);
60     }
61
62     protected ITableIterator getEmptyIterator() throws Exception JavaDoc
63     {
64         return new DatabaseTableIterator(new String JavaDoc[0], new MockDataSet());
65     }
66
67     public void testGetTableClose() throws Exception JavaDoc
68     {
69         int i = 0;
70         String JavaDoc[] expectedNames = getExpectedNames();
71         MockDataSet dataSet = createMockDataSet(expectedNames);
72
73         ITableIterator iterator = new DatabaseTableIterator(expectedNames, dataSet);
74         while(iterator.next())
75         {
76             ITable table = iterator.getTable();
77             assertEquals("name " + i, expectedNames[i],
78                     table.getTableMetaData().getTableName());
79             i++;
80         }
81
82         assertEquals("count", expectedNames.length, i);
83         dataSet.verify();
84     }
85 }
86
Popular Tags