1 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 ; 31 import java.io.FilenameFilter ; 32 import java.sql.Connection ; 33 import java.util.Arrays ; 34 35 40 public class DatabaseSequenceFilterTest extends TestCase 41 { 42 Connection _jdbcConnection; 43 44 public DatabaseSequenceFilterTest(String s) 45 { 46 super(s); 47 } 48 49 protected void setUp() throws Exception 50 { 51 super.setUp(); 52 53 _jdbcConnection = HypersonicEnvironment.createJdbcConnection("tempdb"); 54 } 55 56 protected void tearDown() throws Exception 57 { 58 super.tearDown(); 59 60 _jdbcConnection.close(); 62 63 File [] files = new File (".").listFiles(new FilenameFilter () 64 { 65 public boolean accept(File dir, String 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 file = files[i]; 78 file.delete(); 79 } 80 } 81 82 public void testGetTableNames() throws Exception 83 { 84 String [] expectedNoFilter = {"A","B","C","D","E","F","G","H",}; 85 String [] expectedFiltered = {"D","A","F","C","G","E","H","B",}; 86 87 HypersonicEnvironment.executeDdlFile(new File ("src/sql/hypersonic_fk.sql"), 88 _jdbcConnection); 89 IDatabaseConnection connection = new DatabaseConnection(_jdbcConnection); 90 91 IDataSet databaseDataset = connection.createDataSet(); 92 String [] 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 [] actualFiltered = filteredDataSet.getTableNames(); 98 assertEquals("filtered", Arrays.asList(expectedFiltered), Arrays.asList(actualFiltered)); 99 } 100 126 127 } 128 | Popular Tags |