KickJava   Java API By Example, From Geeks To Geeks.

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


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.database.AmbiguousTableNameException;
25 import org.dbunit.dataset.xml.XmlDataSet;
26
27 import java.io.FileReader JavaDoc;
28
29 /**
30  * @author Manuel Laflamme
31  * @version $Revision: 1.12 $
32  * @since Feb 22, 2002
33  */

34 public class FilteredDataSetTest extends AbstractDataSetTest
35 {
36     public FilteredDataSetTest(String JavaDoc s)
37     {
38         super(s);
39     }
40
41     protected IDataSet createDataSet() throws Exception JavaDoc
42     {
43         IDataSet dataSet1 = new XmlDataSet(
44                 new FileReader JavaDoc("src/xml/dataSetTest.xml"));
45         IDataSet dataSet2 = new XmlDataSet(
46                 new FileReader JavaDoc("src/xml/filteredDataSetTest.xml"));
47
48         IDataSet dataSet = new CompositeDataSet(dataSet1, dataSet2);
49         assertEquals("count before filter", getExpectedNames().length + 1,
50                 dataSet.getTableNames().length);
51         return new FilteredDataSet(getExpectedNames(), dataSet);
52     }
53
54     protected IDataSet createDuplicateDataSet() throws Exception JavaDoc
55     {
56         IDataSet dataSet1 = new XmlDataSet(
57                 new FileReader JavaDoc("src/xml/xmlDataSetDuplicateTest.xml"));
58         IDataSet dataSet2 = new XmlDataSet(
59                 new FileReader JavaDoc("src/xml/filteredDataSetTest.xml"));
60
61         IDataSet dataSet = new CompositeDataSet(dataSet1, dataSet2, false);
62         assertEquals("count before filter", getExpectedDuplicateNames().length + 1,
63                 dataSet.getTableNames().length);
64         return new FilteredDataSet(getExpectedDuplicateNames(), dataSet);
65     }
66
67     protected IDataSet createMultipleCaseDuplicateDataSet() throws Exception JavaDoc
68     {
69         String JavaDoc[] names = getExpectedDuplicateNames();
70         names[0] = names[0].toLowerCase();
71
72         return new FilteredDataSet(names, createDuplicateDataSet());
73     }
74
75     public void testGetFilteredTableNames() throws Exception JavaDoc
76     {
77         String JavaDoc[] originalNames = getExpectedNames();
78         String JavaDoc expectedName = originalNames[0];
79         IDataSet dataSet = createDataSet();
80         assertTrue("original count", dataSet.getTableNames().length > 1);
81
82         IDataSet filteredDataSet = new FilteredDataSet(new String JavaDoc[]{expectedName}, dataSet);
83         assertEquals("filtered count", 1, filteredDataSet.getTableNames().length);
84         assertEquals("filtered names", expectedName, filteredDataSet.getTableNames()[0]);
85     }
86
87     public void testGetFilteredTable() throws Exception JavaDoc
88     {
89         String JavaDoc[] originalNames = getExpectedNames();
90         IDataSet filteredDataSet = new FilteredDataSet(
91                 new String JavaDoc[]{originalNames[0]}, createDataSet());
92
93
94         for (int i = 0; i < originalNames.length; i++)
95         {
96             String JavaDoc name = originalNames[i];
97             if (i == 0)
98             {
99                 assertEquals("table " + i, name,
100                         filteredDataSet.getTable(name).getTableMetaData().getTableName());
101             }
102             else
103             {
104                 try
105                 {
106                     filteredDataSet.getTable(name);
107                     fail("Should throw a NoSuchTableException");
108                 }
109                 catch (NoSuchTableException e)
110                 {
111                 }
112             }
113         }
114     }
115
116     public void testGetFilteredTableMetaData() throws Exception JavaDoc
117     {
118         String JavaDoc[] originalNames = getExpectedNames();
119         IDataSet filteredDataSet = new FilteredDataSet(
120                 new String JavaDoc[]{originalNames[0]}, createDataSet());
121
122
123         for (int i = 0; i < originalNames.length; i++)
124         {
125             String JavaDoc name = originalNames[i];
126             if (i == 0)
127             {
128                 assertEquals("table " + i, name,
129                         filteredDataSet.getTableMetaData(name).getTableName());
130             }
131             else
132             {
133                 try
134                 {
135                     filteredDataSet.getTableMetaData(name);
136                     fail("Should throw a NoSuchTableException");
137                 }
138                 catch (NoSuchTableException e)
139                 {
140                 }
141             }
142         }
143     }
144
145     public void testGetDuplicateTableNames() throws Exception JavaDoc
146     {
147         IDataSet dataSet = createDuplicateDataSet();
148         try
149         {
150             dataSet.getTableNames();
151             fail("Should throw AmbiguousTableNameException");
152         }
153         catch (AmbiguousTableNameException e)
154         {
155         }
156     }
157
158     public void testGetDuplicateTables() throws Exception JavaDoc
159     {
160         IDataSet dataSet = createDuplicateDataSet();
161         try
162         {
163             dataSet.getTables();
164             fail("Should throw AmbiguousTableNameException");
165         }
166         catch (AmbiguousTableNameException e)
167         {
168         }
169     }
170
171     public void testReverseIteratorAndDuplicateTable() throws Exception JavaDoc
172     {
173         IDataSet dataSet = createDuplicateDataSet();
174         try
175         {
176             dataSet.iterator();
177             fail("Should throw AmbiguousTableNameException");
178         }
179         catch (AmbiguousTableNameException e)
180         {
181         }
182     }
183
184     public void testIteratorAndDuplicateTable() throws Exception JavaDoc
185     {
186         IDataSet dataSet = createDuplicateDataSet();
187         try
188         {
189             dataSet.reverseIterator();
190             fail("Should throw AmbiguousTableNameException");
191         }
192         catch (AmbiguousTableNameException e)
193         {
194         }
195     }
196 }
197
198
199
200
201
202
Popular Tags