本文整理汇总了Java中org.dbunit.dataset.ITableIterator类的典型用法代码示例。如果您正苦于以下问题:Java ITableIterator类的具体用法?Java ITableIterator怎么用?Java ITableIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ITableIterator类属于org.dbunit.dataset包,在下文中一共展示了ITableIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testLoadDataSet_lessColumnsLast
import org.dbunit.dataset.ITableIterator; //导入依赖的package包/类
/**
* Test the loading of a data set with 2 rows for a table, but the second
* row has less columns than the first one.
*/
@Test
public void testLoadDataSet_lessColumnsLast() throws Exception {
MultiSchemaDataSet result = multiSchemaXmlDataSetReader.readDataSetXml(toFile(getClass().getResource("LessColumnsLastDataSet.xml")));
// there should be 1 dataset for the default schema A
assertLenientEquals(new String[]{"SCHEMA_A"}, result.getSchemaNames());
// the dataset should contain 2 tables with the same name
IDataSet dataSet = result.getDataSetForSchema("SCHEMA_A");
assertLenientEquals(new String[]{"TABLE_A"}, dataSet.getTableNames());
assertEquals(2, dataSet.getTable("TABLE_A").getRowCount());
ITableIterator tableIterator = dataSet.iterator();
// first table TABLE_A row should contain 3 columns
assertTrue(tableIterator.next());
ITable table = tableIterator.getTable();
assertEquals(2, table.getRowCount());
assertPropertyLenientEquals("columnName", asList("COLUMN_1", "COLUMN_2", "COLUMN_3"), asList(table.getTableMetaData().getColumns()));
assertEquals("1", table.getValue(0, "COLUMN_1"));
assertEquals("2", table.getValue(0, "COLUMN_2"));
assertEquals("3", table.getValue(0, "COLUMN_3"));
}
示例2: testLoadDataSet_lessColumnsFirst
import org.dbunit.dataset.ITableIterator; //导入依赖的package包/类
/**
* Test the loading of a data set with 2 rows for a table, but the first
* row has less columns than the second one.
*/
@Test
public void testLoadDataSet_lessColumnsFirst() throws Exception {
MultiSchemaDataSet result = multiSchemaXmlDataSetReader.readDataSetXml(toFile(getClass().getResource("LessColumnsFirstDataSet.xml")));
// there should be 1 dataset for the default schema A
assertLenientEquals(new String[]{"SCHEMA_A"}, result.getSchemaNames());
// the dataset should contain 2 tables with the same name
IDataSet dataSet = result.getDataSetForSchema("SCHEMA_A");
assertLenientEquals(new String[]{"TABLE_A"}, dataSet.getTableNames());
assertEquals(2, dataSet.getTable("TABLE_A").getRowCount());
ITableIterator tableIterator = dataSet.iterator();
// first table TABLE_A row should contain 1 column
assertTrue(tableIterator.next());
ITable table = tableIterator.getTable();
assertPropertyLenientEquals("columnName", asList("COLUMN_1", "COLUMN_2", "COLUMN_3"), asList(table.getTableMetaData().getColumns()));
assertEquals(2, table.getRowCount());
assertEquals("4", table.getValue(0, "COLUMN_2"));
}
示例3: compareDbToDataSet
import org.dbunit.dataset.ITableIterator; //导入依赖的package包/类
private void compareDbToDataSet(String filename) throws Exception
{
IDataSet afterActualDataSet = getDbUnitconnection().createDataSet();
IDataSet afterExpectedDataSet = loadDataSet(filename);
ITableIterator iter = afterActualDataSet.iterator();
while (iter.next()) {
ITable actualTable = iter.getTable();
ITable expectedTable = afterExpectedDataSet.getTable(actualTable.getTableMetaData().getTableName());
Column[] expectedColumns = expectedTable.getTableMetaData().getColumns();
//Expected table will be sorted by the columns present on expected file
ITable sortedExpectedTable = new SortedTable(expectedTable, expectedColumns);
//Actual table will be sorted by the columns present on *expected* file.
//It will be also filtered to only include tables present on expected file
ITable filteredActualTable = DefaultColumnFilter.includedColumnsTable(actualTable, expectedColumns);
ITable sortedFilteredActualTable = new SortedTable(filteredActualTable, expectedColumns);
Assertion.assertEquals(sortedExpectedTable, sortedFilteredActualTable);
}
}
示例4: createIterator
import org.dbunit.dataset.ITableIterator; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected ITableIterator createIterator(boolean reversed)
throws DataSetException {
if (logger.isDebugEnabled())
logger.debug("createIterator(reversed={}) - start", String.valueOf(reversed));
ITable[] tables = (ITable[]) _tables.orderedValues().toArray(new ITable[0]);
return new DefaultTableIterator(tables, reversed);
}
示例5: execute
import org.dbunit.dataset.ITableIterator; //导入依赖的package包/类
@Override
public void execute(IDatabaseConnection connection, IDataSet dataSet) throws DatabaseUnitException, SQLException {
DatabaseConfig databaseConfig = connection.getConfig();
IStatementFactory statementFactory = (IStatementFactory) databaseConfig.getProperty(DatabaseConfig.PROPERTY_STATEMENT_FACTORY);
IBatchStatement statement = statementFactory.createBatchStatement(connection);
try {
int count = 0;
ITableIterator iterator = dataSet.iterator();
while (iterator.next()) {
String tableName = iterator.getTableMetaData().getTableName();
StringBuilder sql = new StringBuilder();
sql.append("delete from ");
sql.append(this.getQualifiedName(this.schema, tableName, connection));
statement.addBatch(sql.toString());
count++;
}
if (count > 0) {
statement.executeBatch();
statement.clearBatch();
}
} finally {
statement.close();
}
}
示例6: verify
import org.dbunit.dataset.ITableIterator; //导入依赖的package包/类
static void verify(ITableIterator actual, List<ITable> expected) throws Exception {
List<ITable> actualTables = new LinkedList<>();
while (actual.next()) {
actualTables.add(actual.getTable());
}
new IterableVerifier<ITable>().verify(actualTables, expected);
}
示例7: checkResult
import org.dbunit.dataset.ITableIterator; //导入依赖的package包/类
/**
* Check if the content of the database as expected.
*
* @param expected the expected dataset.
*/
public void checkResult(final IDataSet expected) {
try {
final IDataSet actual =
databaseTester.getConnection().createDataSet();
final ITableIterator expectdTables = expected.iterator();
while (expectdTables.next()) {
final String tableName =
expectdTables.getTable().getTableMetaData()
.getTableName();
final String[] uk = tableToUniqueKey.get(tableName);
if (uk == null) {
throw new IllegalStateException(
"You must define a unique-key for each table.");
}
final ITable expectedTable =
new SortedTable(expected.getTable(tableName), uk);
final ITable actualTable =
new SortedTable(actual.getTable(tableName), uk);
Assertion.assertEquals(expectedTable, actualTable,
new ValidatorFailureHandler());
}
} catch (Exception e) {
throw new IllegalStateException("Error during checkResult", e);
}
}
示例8: printTableNames
import org.dbunit.dataset.ITableIterator; //导入依赖的package包/类
/**
* Print the tables in the order of the dependencies.
*
* @param conn the database-connection.
* @throws DataSetException error in the dataset.
* @throws SQLException error communicate with db.
*/
// //CSOFF: RegexpSinglelineJava It's only helper to dump something to
// console.
public static void printTableNames(IDatabaseConnection conn)
throws DataSetException, SQLException {
final ITableFilter filter = new DatabaseSequenceFilter(conn);
final ITableIterator tables =
filter.iterator(conn.createDataSet(), false);
System.out.println("########### Database tables");
while (tables.next()) {
System.out.print("\"" + tables.getTableMetaData().getTableName()
+ "\", ");
}
System.out.println();
}
示例9: createIterator
import org.dbunit.dataset.ITableIterator; //导入依赖的package包/类
@Override
protected ITableIterator createIterator(boolean reversed) throws DataSetException {
return new ScriptableDataSetIterator(reversed ? delegate.reverseIterator() : delegate.iterator());
}
示例10: ScriptableDataSetIterator
import org.dbunit.dataset.ITableIterator; //导入依赖的package包/类
public ScriptableDataSetIterator(ITableIterator delegate) {
this.delegate = delegate;
}
示例11: iterator
import org.dbunit.dataset.ITableIterator; //导入依赖的package包/类
@Override
public ITableIterator iterator() throws DataSetException {
return new DefaultTableIterator(getTables());
}
示例12: reverseIterator
import org.dbunit.dataset.ITableIterator; //导入依赖的package包/类
@Override
public ITableIterator reverseIterator() throws DataSetException {
return new DefaultTableIterator(getTables(), true);
}
示例13: createIterator
import org.dbunit.dataset.ITableIterator; //导入依赖的package包/类
@Override
protected ITableIterator createIterator(boolean reversed) throws DataSetException {
ITable[] t = new ITable[0];
return new DefaultTableIterator(t, reversed);
}
示例14: createIterator
import org.dbunit.dataset.ITableIterator; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected ITableIterator createIterator(boolean reversed) throws DataSetException {
ITable[] t = (ITable[]) this.tables.orderedValues().toArray(new ITable[0]);
return new DefaultTableIterator(t, reversed);
}
示例15: createIterator
import org.dbunit.dataset.ITableIterator; //导入依赖的package包/类
@Override
protected ITableIterator createIterator(boolean reverse) throws DataSetException {
return new DefaultTableIterator(tables.toArray(new ITable[tables.size()]));
}