1 21 package org.dbunit.dataset; 22 23 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 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 } 118 | Popular Tags |