protected static void printResult(ITable resultTable) throws DataSetException { StringBuilder sb = new StringBuilder(); int columnCount = resultTable.getTableMetaData().getColumns().length; String[] columns = new String[columnCount]; for (int i = 0; i < columnCount; i++) { sb.append(resultTable.getTableMetaData().getColumns()[i].getColumnName()); sb.append("-"); sb.append(resultTable.getTableMetaData().getColumns()[i].getDataType()); sb.append("\t"); columns[i] = resultTable.getTableMetaData().getColumns()[i].getColumnName(); } sb.append("\n"); for (int i = 0; i < resultTable.getRowCount(); i++) { for (int j = 0; j < columns.length; j++) { sb.append(resultTable.getValue(i, columns[j])); sb.append("\t"); } sb.append("\n"); } System.out.println(sb.toString()); }
boolean isNumber = currentColumn.getDataType().isNumber(); if(!isNumber){ out.write("\"");
boolean isNumber = currentColumn.getDataType().isNumber(); if (!isNumber) { out.write("\"");
private ITable filterTableByPrimaryKey(ITable expectedDataSet, ITable actualDataSet) throws DataSetException { //PrimaryKeyFilteredTableWrapper uses Set.contains to check PK values, so types should be the same in both datasets DataType dataType = actualDataSet.getTableMetaData().getPrimaryKeys()[0].getDataType(); String pkName = actualDataSet.getTableMetaData().getPrimaryKeys()[0].getColumnName(); Set<Object> pkSet = new HashSet<>(); for (int i = 0; i < expectedDataSet.getRowCount(); i++) { pkSet.add(dataType.typeCast(expectedDataSet.getValue(i, pkName))); } return new PrimaryKeyFilteredTableWrapper(actualDataSet, pkSet); }
/** * Adds the rows of the DbUnit table to the given table. * * @param dbUnitTable The DbUnit table containing the rows, not null * @param table The table to add the rows to, not null * @param primaryKeyColumnNames The names of the pk columns, empty if there are none */ protected void addRows(ITable dbUnitTable, Table table, List<String> primaryKeyColumnNames) throws DataSetException { org.dbunit.dataset.Column[] columns = dbUnitTable.getTableMetaData().getColumns(); int rowCount = dbUnitTable.getRowCount(); for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { Row row = new Row(); table.addRow(row); for (org.dbunit.dataset.Column dbUnitColumn : columns) { String columnName = dbUnitColumn.getColumnName(); DataType columnType = dbUnitColumn.getDataType(); Object value = dbUnitTable.getValue(rowIndex, columnName); Column column = new Column(columnName, columnType, value); if (primaryKeyColumnNames.contains(columnName)) { row.addPrimaryKeyColumn(column); } else { row.addColumn(column); } } } }