KickJava   Java API By Example, From Geeks To Geeks.

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


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.dataset;
22
23 /**
24  * @author Manuel Laflamme
25  * @since Apr 6, 2003
26  * @version $Revision: 1.3 $
27  */

28 public abstract class AbstractTableIteratorTest extends AbstractTest
29 {
30     public AbstractTableIteratorTest(String JavaDoc s)
31     {
32         super(s);
33     }
34
35     protected abstract ITableIterator getIterator() throws Exception JavaDoc;
36
37     protected abstract ITableIterator getEmptyIterator() throws Exception JavaDoc;
38
39     public void testNext() throws Exception JavaDoc
40     {
41         int count = 0;
42         String JavaDoc[] names = getExpectedNames();
43         ITableIterator iterator = getIterator();
44         while(iterator.next())
45         {
46             count++;
47         }
48
49         assertEquals("count", names.length, count);
50     }
51
52     public void testNextAndEmpty() throws Exception JavaDoc
53     {
54         int count = 0;
55         ITableIterator iterator = getEmptyIterator();
56         while(iterator.next())
57         {
58             count++;
59         }
60
61         assertEquals("count", 0, count);
62     }
63
64     public void testGetTableMetaData() throws Exception JavaDoc
65     {
66         int i = 0;
67         String JavaDoc[] names = getExpectedNames();
68         ITableIterator iterator = getIterator();
69         while(iterator.next())
70         {
71             assertEquals("name " + i, names[i],
72                     iterator.getTableMetaData().getTableName());
73             i++;
74         }
75
76         assertEquals("count", names.length, i);
77     }
78
79     public void testGetTableMetaDataBeforeNext() throws Exception JavaDoc
80     {
81         ITableIterator iterator = getIterator();
82         try
83         {
84             iterator.getTableMetaData();
85             fail("Should have throw a ???Exception");
86         }
87         catch (IndexOutOfBoundsException JavaDoc e)
88         {
89
90         }
91
92         int i = 0;
93         String JavaDoc[] names = getExpectedNames();
94         while(iterator.next())
95         {
96             assertEquals("name " + i, names[i],
97                     iterator.getTableMetaData().getTableName());
98             i++;
99         }
100
101         assertEquals("count", names.length, i);
102     }
103
104     public void testGetTableMetaDataAfterLastNext() throws Exception JavaDoc
105     {
106         int count = 0;
107         String JavaDoc[] names = getExpectedNames();
108         ITableIterator iterator = getIterator();
109         while(iterator.next())
110         {
111             count++;
112         }
113
114         assertEquals("count", names.length, count);
115
116         try
117         {
118             iterator.getTableMetaData();
119             fail("Should have throw a ???Exception");
120         }
121         catch (IndexOutOfBoundsException JavaDoc e)
122         {
123         }
124     }
125
126     public void testGetTable() throws Exception JavaDoc
127     {
128         int i = 0;
129         String JavaDoc[] names = getExpectedNames();
130         ITableIterator iterator = getIterator();
131         while(iterator.next())
132         {
133             assertEquals("name " + i, names[i],
134                     iterator.getTable().getTableMetaData().getTableName());
135             i++;
136         }
137
138         assertEquals("count", names.length, i);
139     }
140 }
141
Popular Tags