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