KickJava   Java API By Example, From Geeks To Geeks.

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


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.HypersonicEnvironment;
24 import org.dbunit.dataset.FilteredDataSet;
25 import org.dbunit.dataset.IDataSet;
26 import org.dbunit.dataset.filter.ITableFilter;
27
28 import junit.framework.TestCase;
29
30 import java.io.File JavaDoc;
31 import java.io.FilenameFilter JavaDoc;
32 import java.sql.Connection JavaDoc;
33 import java.util.Arrays JavaDoc;
34
35 /**
36  * @author Manuel Laflamme
37  * @since May 8, 2004
38  * @version $Revision: 1.3 $
39  */

40 public class DatabaseSequenceFilterTest extends TestCase
41 {
42     Connection JavaDoc _jdbcConnection;
43
44     public DatabaseSequenceFilterTest(String JavaDoc s)
45     {
46         super(s);
47     }
48
49     protected void setUp() throws Exception JavaDoc
50     {
51         super.setUp();
52
53         _jdbcConnection = HypersonicEnvironment.createJdbcConnection("tempdb");
54     }
55
56     protected void tearDown() throws Exception JavaDoc
57     {
58         super.tearDown();
59
60 // HypersonicEnvironment.execute(_jdbcConnection, "SHUTDOWN");
61
_jdbcConnection.close();
62
63         File JavaDoc[] files = new File JavaDoc(".").listFiles(new FilenameFilter JavaDoc()
64                 {
65                     public boolean accept(File JavaDoc dir, String JavaDoc name)
66                     {
67                         if (name.indexOf("tempdb") != -1)
68                         {
69                             return true;
70                         }
71                         return false;
72                     }
73                 });
74
75         for (int i = 0; i < files.length; i++)
76         {
77             File JavaDoc file = files[i];
78             file.delete();
79         }
80     }
81
82     public void testGetTableNames() throws Exception JavaDoc
83     {
84         String JavaDoc[] expectedNoFilter = {"A","B","C","D","E","F","G","H",};
85         String JavaDoc[] expectedFiltered = {"D","A","F","C","G","E","H","B",};
86
87         HypersonicEnvironment.executeDdlFile(new File JavaDoc("src/sql/hypersonic_fk.sql"),
88                 _jdbcConnection);
89         IDatabaseConnection connection = new DatabaseConnection(_jdbcConnection);
90
91         IDataSet databaseDataset = connection.createDataSet();
92         String JavaDoc[] actualNoFilter = databaseDataset.getTableNames();
93         assertEquals("no filter", Arrays.asList(expectedNoFilter), Arrays.asList(actualNoFilter));
94
95         ITableFilter filter = new DatabaseSequenceFilter(connection);
96         IDataSet filteredDataSet = new FilteredDataSet(filter, databaseDataset);
97         String JavaDoc[] actualFiltered = filteredDataSet.getTableNames();
98         assertEquals("filtered", Arrays.asList(expectedFiltered), Arrays.asList(actualFiltered));
99     }
100 /*
101
102     public void testGetTableNamesCyclic() throws Exception
103     {
104         String[] expectedNoFilter = {"A","B","C","D","E",};
105
106         HypersonicEnvironment.executeDdlFile(new File("src/sql/hypersonic_cyclic.sql"),
107                 _jdbcConnection);
108         IDatabaseConnection connection = new DatabaseConnection(_jdbcConnection);
109
110         IDataSet databaseDataset = connection.createDataSet();
111         String[] actualNoFilter = databaseDataset.getTableNames();
112         assertEquals("no filter", Arrays.asList(expectedNoFilter), Arrays.asList(actualNoFilter));
113
114         try
115         {
116             ITableFilter filter = new DatabaseSequenceFilter(connection);
117             IDataSet filteredDataSet = new FilteredDataSet(filter, databaseDataset);
118             filteredDataSet.getTableNames();
119             fail("Should not be here!");
120         }
121         catch (CyclicTablesDependencyException e)
122         {
123         }
124     }
125 */

126
127 }
128
Popular Tags