1 21 package org.dbunit.database; 22 23 import org.dbunit.DatabaseEnvironment; 24 import org.dbunit.dataset.Column; 25 import org.dbunit.dataset.ForwardOnlyTableTest; 26 import org.dbunit.dataset.ITable; 27 import org.dbunit.dataset.MockTableMetaData; 28 import org.dbunit.dataset.RowOutOfBoundsException; 29 import org.dbunit.operation.DatabaseOperation; 30 31 36 public class ForwardOnlyResultSetTableTest extends ForwardOnlyTableTest 37 { 38 public ForwardOnlyResultSetTableTest(String s) 39 { 40 super(s); 41 } 42 43 protected ITable createTable() throws Exception 44 { 45 DatabaseEnvironment env = DatabaseEnvironment.getInstance(); 46 IDatabaseConnection connection = env.getConnection(); 47 48 DatabaseOperation.CLEAN_INSERT.execute(connection, env.getInitDataSet()); 49 50 String selectStatement = "select * from test_table order by COLUMN0"; 51 return new ForwardOnlyResultSetTable("TEST_TABLE", selectStatement, connection); 52 } 53 54 public void testGetMissingValue() throws Exception 55 { 56 } 58 59 public void testGetValueOnLastRowIsClosingResultSet() throws Exception 60 { 61 String tableName = "TABLE"; 62 String [] columnNames = {"C0"}; 63 Object [][] expectedValues = new Object [][]{ 65 new Object []{"1", "2", "3"}, 66 new Object []{"4", "5", "6"}, 67 new Object []{"7", "8", "9"}, 68 }; 69 70 ExtendedMockMultiRowResultSet resultSet = new ExtendedMockMultiRowResultSet(); 72 resultSet.setExpectedCloseCalls(1); 73 resultSet.setupColumnNames(columnNames); 74 resultSet.setupRows(expectedValues); 75 76 MockTableMetaData metaData = new MockTableMetaData(tableName, columnNames); 78 ForwardOnlyResultSetTable table = 79 new ForwardOnlyResultSetTable(metaData, resultSet); 80 81 try 83 { 84 Column[] columns = table.getTableMetaData().getColumns(); 85 86 for (int i = 0; ; i++) 87 { 88 for (int j = 0; j < columns.length; j++) 89 { 90 String columnName = columns[j].getColumnName(); 91 Object actualValue = table.getValue(i, columnName); 92 Object expectedValue = expectedValues[i][j]; 93 assertEquals("row=" + i + ", col=" + columnName, 94 expectedValue, actualValue); 95 96 } 97 } 98 } 99 catch(RowOutOfBoundsException e) 100 { 101 } 103 104 resultSet.verify(); 106 } 107 108 } 109 | Popular Tags |