1 21 package org.dbunit.database; 22 23 import org.dbunit.dataset.AbstractTableIteratorTest; 24 import org.dbunit.dataset.ITable; 25 import org.dbunit.dataset.ITableIterator; 26 import org.dbunit.dataset.MockDataSet; 27 28 33 public class DatabaseTableIteratorTest extends AbstractTableIteratorTest 34 { 35 public DatabaseTableIteratorTest(String s) 36 { 37 super(s); 38 } 39 40 private MockDataSet createMockDataSet(String [] expectedNames) 41 { 42 MockDataSet dataSet = new MockDataSet(); 43 for (int i = 0; i < expectedNames.length; i++) 44 { 45 String tableName = expectedNames[i]; 46 MockResultSetTable table = new MockResultSetTable(); 47 table.setupTableMetaData(tableName); 48 table.setExpectedCloseCalls(1); 49 dataSet.addTable(table); 50 } 51 return dataSet; 52 } 53 54 protected ITableIterator getIterator() throws Exception 55 { 56 String [] expectedNames = getExpectedNames(); 57 MockDataSet dataSet = createMockDataSet(expectedNames); 58 59 return new DatabaseTableIterator(expectedNames, dataSet); 60 } 61 62 protected ITableIterator getEmptyIterator() throws Exception 63 { 64 return new DatabaseTableIterator(new String [0], new MockDataSet()); 65 } 66 67 public void testGetTableClose() throws Exception 68 { 69 int i = 0; 70 String [] expectedNames = getExpectedNames(); 71 MockDataSet dataSet = createMockDataSet(expectedNames); 72 73 ITableIterator iterator = new DatabaseTableIterator(expectedNames, dataSet); 74 while(iterator.next()) 75 { 76 ITable table = iterator.getTable(); 77 assertEquals("name " + i, expectedNames[i], 78 table.getTableMetaData().getTableName()); 79 i++; 80 } 81 82 assertEquals("count", expectedNames.length, i); 83 dataSet.verify(); 84 } 85 } 86 | Popular Tags |