View Javadoc
1   package org.dbunit.database;
2   
3   import java.io.File;
4   import java.sql.Connection;
5   
6   import org.dbunit.AbstractDatabaseIT;
7   import org.dbunit.DdlExecutor;
8   import org.dbunit.HypersonicEnvironment;
9   import org.dbunit.dataset.Column;
10  import org.dbunit.dataset.Columns;
11  import org.dbunit.dataset.IDataSet;
12  import org.dbunit.testutil.TestUtils;
13  
14  /**
15   * @author gommma (gommma AT users.sourceforge.net)
16   * @author Last changed by: $Author$
17   * @version $Revision$ $Date$
18   * @since 2.4.0
19   */
20  public class ResultSetTableMetaDataIT extends AbstractDatabaseIT
21  {
22      
23      public ResultSetTableMetaDataIT(String s)
24      {
25          super(s);
26      }
27  
28      protected IDataSet createDataSet() throws Exception
29      {
30          return _connection.createDataSet();
31      }
32  
33      /**
34       * Tests the pattern-like column retrieval from the database. DbUnit
35       * should not interpret any table names as regex patterns. 
36       * @throws Exception
37       */
38      public void testGetColumnsForTablesMatchingSamePattern() throws Exception
39      {
40          Connection jdbcConnection = HypersonicEnvironment.createJdbcConnection("tempdb");
41          DdlExecutor.executeDdlFile(TestUtils.getFile("sql/hypersonic_dataset_pattern_test.sql"),
42                  jdbcConnection);
43          IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
44  
45          try {
46              String tableName = "PATTERN_LIKE_TABLE_X_";
47              String[] columnNames = {"VARCHAR_COL_XUNDERSCORE"};
48      
49              String sql = "select * from " + tableName;
50              ForwardOnlyResultSetTable resultSetTable = new ForwardOnlyResultSetTable(tableName, sql, connection);
51              ResultSetTableMetaData metaData = (ResultSetTableMetaData) resultSetTable.getTableMetaData();
52              
53              Column[] columns = metaData.getColumns();
54      
55              assertEquals("column count", columnNames.length, columns.length);
56      
57              for (int i = 0; i < columnNames.length; i++)
58              {
59                  Column column = Columns.getColumn(columnNames[i], columns);
60                  assertEquals(columnNames[i], columnNames[i], column.getColumnName());
61              }
62          }
63          finally {
64              HypersonicEnvironment.shutdown(jdbcConnection);
65              jdbcConnection.close();
66              HypersonicEnvironment.deleteFiles("tempdb");
67          }
68      }
69  
70  }