fitnesse.fixtures.RowEntryFixture Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fitnesse Show documentation
Show all versions of fitnesse Show documentation
The fully integrated standalone wiki, and acceptance testing framework.
// Copyright (C) 2003-2009 by Object Mentor, Inc. All rights reserved.
// Released under the terms of the CPL Common Public License version 1.0.
package fitnesse.fixtures;
import java.io.PrintWriter;
import java.io.StringWriter;
import fit.ColumnFixture;
import fit.Parse;
public abstract class RowEntryFixture extends ColumnFixture {
public abstract void enterRow() throws Exception;
public static final String ERROR_INDICATOR = "Unable to enter last row: ";
public static final String RIGHT_STYLE = "pass";
public static final String WRONG_STYLE = "fail";
@Override
public void doRow(Parse row) {
if (row.parts.body.contains(ERROR_INDICATOR))
return;
super.doRow(row);
try {
enterRow();
right(appendCell(row, "entered"));
}
catch (Exception e) {
wrong(appendCell(row, "skipped"));
reportError(row, e);
}
}
protected Parse appendCell(Parse row, String text) {
Parse lastCell = new Parse("td", text, null, null);
row.parts.last().more = lastCell;
return lastCell;
}
public void reportError(Parse row, Exception e) {
Parse errorCell = makeMessageCell(e);
insertRowAfter(row, new Parse("tr", null, errorCell, null));
}
public Parse makeMessageCell(Exception e) {
Parse errorCell = new Parse("td", "", null, null);
final StringWriter buffer = new StringWriter();
e.printStackTrace(new PrintWriter(buffer));
errorCell.addToTag(" colspan=\"" + (columnBindings.length + 1) + "\"");
errorCell.addToBody("" + ERROR_INDICATOR + e.getMessage() + "");
errorCell.addToBody("" + (buffer.toString()) + "
");
wrong(errorCell);
return errorCell;
}
public void insertRowAfter(Parse currentRow, Parse rowToAdd) {
Parse nextRow = currentRow.more;
currentRow.more = rowToAdd;
rowToAdd.more = nextRow;
}
}