1 21 22 package org.dbunit.dataset; 23 24 import junit.framework.TestCase; 25 26 import org.dbunit.dataset.datatype.DataType; 27 import org.dbunit.dataset.filter.IColumnFilter; 28 import org.dbunit.dataset.filter.DefaultColumnFilter; 29 30 35 public class FilteredTableMetaDataTest extends TestCase 36 { 37 public FilteredTableMetaDataTest(String s) 38 { 39 super(s); 40 } 41 42 protected IColumnFilter createColumnFilter() throws Exception 43 { 44 DefaultColumnFilter filter = new DefaultColumnFilter(); 45 filter.excludeColumn("excluded*"); 46 return filter; 47 } 48 49 public void testGetTableName() throws Exception 50 { 51 String expected = "tableName"; 52 ITableMetaData metaData = new DefaultTableMetaData(expected, null, (Column[])null); 53 metaData = new FilteredTableMetaData(metaData, createColumnFilter()); 54 55 assertEquals("table name", expected, metaData.getTableName()); 56 } 57 58 public void testGetColumns() throws Exception 59 { 60 Column[] columns = new Column[]{ 61 new Column("numberColumn", DataType.NUMERIC), 62 new Column("stringColumn", DataType.VARCHAR), 63 new Column("booleanColumn", DataType.BOOLEAN), 64 new Column("excludedColumn", DataType.BOOLEAN), 65 }; 66 67 ITableMetaData metaData = new DefaultTableMetaData("toto", columns, (Column[])null); 68 metaData = new FilteredTableMetaData(metaData, createColumnFilter()); 69 70 assertEquals("column count", 3, metaData.getColumns().length); 71 for (int i = 0; i < 3; i++) 72 { 73 Column column = columns[i]; 74 assertEquals("columns" + i, column, metaData.getColumns()[i]); 75 } 76 assertEquals("key count", 0, metaData.getPrimaryKeys().length); 77 } 78 79 public void testGetPrimaryKeys() throws Exception 80 { 81 Column[] columns = new Column[]{ 82 new Column("numberColumn", DataType.NUMERIC), 83 new Column("stringColumn", DataType.VARCHAR), 84 new Column("booleanColumn", DataType.BOOLEAN), 85 new Column("excludedColumn", DataType.BOOLEAN), 86 }; 87 String [] keyNames = new String []{"booleanColumn", "numberColumn", "excludedColumn"}; 88 89 90 ITableMetaData metaData = new DefaultTableMetaData("toto", columns, keyNames); 91 metaData = new FilteredTableMetaData(metaData, createColumnFilter()); 92 93 Column[] keys = metaData.getPrimaryKeys(); 94 assertEquals("key count", 2, keys.length); 95 for (int i = 0; i < 2; i++) 96 { 97 assertEquals("key name", keyNames[i], keys[i].getColumnName()); 98 } 99 } 100 } 101 102 103 104 105 106 | Popular Tags |