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()); }
@Override public Object getValue(int row, String column) throws DataSetException { return table.getValue(row, column); } }
@Override public Object getValue(int row, String column) throws DataSetException { return table.getValue(row, column); } }
@Override public Object getValue(int row, String column) throws DataSetException { return table.getValue(row, column); } }
public Object getValue(String columnName) throws Exception { return table.getValue(index, columnName); }
public Object getValue(int row, String column) throws DataSetException { Object delta = delegate.getValue(row, column); if (delta instanceof String) { if (StringUtils.isEmpty((String) delta)) { return null; } } return delta; }
public static int getTableIndexFor(ITable table, String columnName, Object value) throws Exception { for (int i = 0; i < table.getRowCount(); i++) { if (value.equals(table.getValue(i, columnName))) { return i; } } return -1; }
public static List<TableRow> getTableRowsFor(ITable table, String columnName, Object value) throws Exception { List<TableRow> rows = new ArrayList<TableRow>(); for (int i = 0; i < table.getRowCount(); i++) { if (value.equals(table.getValue(i, columnName))) { rows.add(new TableRow(table, i)); } } return rows; }
public Object getValue(int row, String column) throws DataSetException { Object value = this.target.getValue(row, column); if (value == null) return value; if (!(value instanceof String)) return value; for (ParamFilter valueReplacer : getValueReplacerList()) { value = valueReplacer.handle(value.toString()); } return value; }
@Override public Object getValue(int row, String column) throws DataSetException { Object value = delegate.getValue(row, column); if (value != null && scriptEnginePattern.matcher(value.toString()).matches()) { ScriptEngine engine = getScriptEngine(value.toString().trim()); if (engine != null) { try { return getScriptResult(value.toString(), engine); } catch (Exception e) { log.log(Level.WARNING,String.format("Could not evaluate script expression for table '%s', column '%s'. The original value will be used.", getTableMetaData().getTableName(), column),e); } } } return value; }
@Test public void testUpdateCompany() { CompanyDao companyDao = new CompanyDao(); IDatabaseConnection dbConn = createConnection(); IDataSet dataSet = createDataSet("CompanyDataSet.xml"); DatabaseOperation.CLEAN_INSERT.execute(dbConn, dataSet); companyDao.updateCompany(100, "NewName"); IDataSet actual = dbConn.createDataSet(new String[]{"company"}); ITable companyTable = actual.getTable("company"); assertEquals("NewName", companyTable.getValue(0, "company_name")); }
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); }
for (int i=0; i<expectedTable.getRowCount(); i++) { for (String orderColumn : orderBy) { if (expectedTable.getValue(i, orderColumn).toString().startsWith("regex:")) { throw new IllegalArgumentException("The orderBy columns cannot use regex matching");
/** * 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); } } } }
Object value = table.getValue(j, column.getColumnName()); if (value != null)