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  package org.dbunit.dataset;
22  
23  import static org.assertj.core.api.Assertions.assertThat;
24  import static org.junit.jupiter.api.Assertions.assertThrows;
25  
26  import org.junit.jupiter.api.Test;
27  
28  /**
29   * @author Manuel Laflamme
30   * @since Apr 11, 2003
31   * @version $Revision$
32   */
33  public class ForwardOnlyTableTest extends DefaultTableTest
34  {
35  
36      @Override
37      protected ITable createTable() throws Exception
38      {
39          return new ForwardOnlyTable(super.createTable());
40      }
41  
42      @Override
43      @Test
44      void testGetRowCount_withSixRowTable_returnsRowCount() throws Exception
45      {
46          final ITable table = createTable();
47          assertThrows(UnsupportedOperationException.class,
48                  () -> table.getRowCount(),
49                  "Should have throw UnsupportedOperationException");
50      }
51  
52      @Override
53      @Test
54      void testGetValueRowBounds_withOutOfBoundsRow_throwsRowOutOfBoundsException() throws Exception
55      {
56          final int[] rows = new int[] {ROW_COUNT, ROW_COUNT + 1};
57          final ITable table = createTable();
58          final String columnName =
59                  table.getTableMetaData().getColumns()[0].getColumnName();
60  
61          for (int i = 0; i < rows.length; i++)
62          {
63              final int row = i;
64              assertThrows(RowOutOfBoundsException.class,
65                      () -> table.getValue(rows[row], columnName),
66                      "Should throw a RowOutOfBoundsException!");
67          }
68      }
69  
70      @Test
71      void testGetValueIterateBackward_whenAccessingPreviousRow_throwsUnsupportedOperation() throws Exception
72      {
73          final ITable table = createTable();
74          for (int i = 0; i < ROW_COUNT; i++)
75          {
76              final int row = i;
77              for (int j = 0; j < COLUMN_COUNT; j++)
78              {
79                  final String columnName = "COLUMN" + j;
80                  final String expected = "row " + i + " col " + j;
81                  final Object value = table.getValue(i, columnName);
82                  assertThat(value).as("value").isEqualTo(expected);
83              }
84  
85              // Try access values from previous row
86              for (int j = 0; j < COLUMN_COUNT; j++)
87              {
88                  final String columnName = "COLUMN" + j;
89                  assertThrows(UnsupportedOperationException.class,
90                          () -> table.getValue(row - 1, columnName));
91              }
92          }
93      }
94  
95      @Test
96      void testGetValueOnEmptyTable_withEmptyTable_throwsRowOutOfBoundsException() throws Exception
97      {
98          final MockTableMetaData metaData =
99                  new MockTableMetaData("TABLE", new String[] {"C1"});
100         final ITable table = new ForwardOnlyTable(new DefaultTable(metaData));
101         assertThrows(RowOutOfBoundsException.class,
102                 () -> table.getValue(0, "C1"),
103                 "Should have throw RowOutOfBoundsException");
104 
105     }
106 
107     /**
108      * @throws Exception
109      */
110     @Override
111     @Test
112     public void testGetMissingValue_withMissingCells_returnsExpectedValues() throws Exception
113     {
114         super.testGetMissingValue_withMissingCells_returnsExpectedValues();
115     }
116 
117 }