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 static org.assertj.core.api.Assertions.assertThat;
25  
26  import org.dbunit.dataset.datatype.DataType;
27  import org.junit.jupiter.api.Test;
28  
29  /**
30   * @author Manuel Laflamme
31   * @version $Revision$
32   * @since Feb 17, 2002
33   */
34  public class DefaultTableTest extends AbstractTableTest
35  {
36  
37      @Override
38      protected ITable createTable() throws Exception
39      {
40          return createTable(COLUMN_COUNT, ROW_COUNT, 0);
41      }
42  
43      protected ITable createTable(final int columnCount, final int rowCount,
44              final int startRow) throws Exception
45      {
46          final DefaultTable table =
47                  new DefaultTable(createTableMetaData(columnCount));
48          for (int i = 0; i < rowCount; i++)
49          {
50              final Object[] rowValues = new Object[columnCount];
51              for (int j = 0; j < rowValues.length; j++)
52              {
53                  rowValues[j] = "row " + (i + startRow) + " col " + j;
54              }
55              table.addRow(rowValues);
56          }
57          return table;
58      }
59  
60      protected ITableMetaData createTableMetaData(final int columnCount)
61              throws Exception
62      {
63          final Column[] columns = new Column[columnCount];
64          for (int i = 0; i < columns.length; i++)
65          {
66              columns[i] = new Column("COLUMN" + i, DataType.UNKNOWN);
67          }
68  
69          return new DefaultTableMetaData("myTable", columns);
70      }
71  
72      @Override
73      @Test
74      public void testGetMissingValue_withMissingCells_returnsExpectedValues() throws Exception
75      {
76          final String columnName = "COLUMN0";
77          final Object expected = ITable.NO_VALUE;
78  
79          final DefaultTable table =
80                  new DefaultTable(createTableMetaData(COLUMN_COUNT));
81          table.addRow(
82                  new Object[] {ITable.NO_VALUE, ITable.NO_VALUE, ITable.NO_VALUE,
83                          ITable.NO_VALUE, ITable.NO_VALUE, ITable.NO_VALUE});
84          final Column[] columns = table.getTableMetaData().getColumns();
85          assertThat(Columns.getColumn(columnName, columns)).isNotNull();
86          assertThat(table.getValue(0, columnName)).as("no value")
87                  .isEqualTo(expected);
88      }
89  
90  }