View Javadoc
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 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  /**
31   * @author Manuel Laflamme
32   * @version $Revision$
33   * @since May 11, 2004
34   */
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