1 21 22 package org.dbunit.dataset; 23 24 import junit.framework.TestCase; 25 26 31 public abstract class AbstractTableTest extends TestCase 32 { 33 protected static final int ROW_COUNT = 6; 34 protected static final int COLUMN_COUNT = 4; 35 36 public AbstractTableTest(String s) 37 { 38 super(s); 39 } 40 41 46 protected abstract ITable createTable() throws Exception ; 47 48 51 public void testGetRowCount() throws Exception 52 { 53 assertEquals("row count", ROW_COUNT, createTable().getRowCount()); 54 } 55 56 public void testTableMetaData() throws Exception 57 { 58 Column[] columns = createTable().getTableMetaData().getColumns(); 59 assertEquals("column count", COLUMN_COUNT, columns.length); 60 for (int i = 0; i < columns.length; i++) 61 { 62 String expected = "COLUMN" + i; 63 String actual = columns[i].getColumnName(); 64 assertEquals("column name", expected, actual); 65 } 66 } 67 68 public void testGetValue() throws Exception 69 { 70 ITable table = createTable(); 71 for (int i = 0; i < ROW_COUNT; i++) 72 { 73 for (int j = 0; j < COLUMN_COUNT; j++) 74 { 75 String columnName = "COLUMN" + j; 76 String expected = "row " + i + " col " + j; 77 Object value = table.getValue(i, columnName); 78 assertEquals("value", expected, value); 79 } 80 } 81 } 82 83 public void testGetValueCaseInsensitive() throws Exception 84 { 85 ITable table = createTable(); 86 for (int i = 0; i < ROW_COUNT; i++) 87 { 88 for (int j = 0; j < COLUMN_COUNT; j++) 89 { 90 String columnName = "CoLUmN" + j; 91 String expected = "row " + i + " col " + j; 92 Object value = table.getValue(i, columnName); 93 assertEquals("value", expected, value); 94 } 95 } 96 } 97 98 public abstract void testGetMissingValue() throws Exception ; 99 100 public void testGetValueRowBounds() throws Exception 101 { 102 int[] rows = new int[]{-2, -1, -ROW_COUNT, ROW_COUNT, ROW_COUNT + 1}; 103 ITable table = createTable(); 104 String columnName = table.getTableMetaData().getColumns()[0].getColumnName(); 105 106 for (int i = 0; i < rows.length; i++) 107 { 108 try 109 { 110 table.getValue(rows[i], columnName); 111 fail("Should throw a RowOutOfBoundsException!"); 112 } 113 catch (RowOutOfBoundsException e) 114 { 115 } 116 } 117 } 118 119 public void testGetValueAndNoSuchColumn() throws Exception 120 { 121 ITable table = createTable(); 122 String columnName = "Unknown"; 123 124 try 125 { 126 table.getValue(0, columnName); 127 fail("Should throw a NoSuchColumnException!"); 128 } 129 catch (NoSuchColumnException e) 130 { 131 } 132 } 133 } 134 135 136 137 138 139 140 | Popular Tags |