01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.fixtures;
04:
05: import java.io.PrintWriter;
06: import java.io.StringWriter;
07:
08: import fit.*;
09:
10: public abstract class RowEntryFixture extends ColumnFixture {
11: public abstract void enterRow() throws Exception;
12:
13: public final static String ERROR_INDICATOR = "Unable to enter last row: ";
14: public static final String RIGHT_STYLE = "pass";
15: public static final String WRONG_STYLE = "fail";
16:
17: public void doRow(Parse row) {
18: if (row.parts.body.indexOf(ERROR_INDICATOR) != -1)
19: return;
20: super .doRow(row);
21: try {
22: enterRow();
23: right(appendCell(row, "entered"));
24: } catch (Exception e) {
25: wrong(appendCell(row, "skipped"));
26: reportError(row, e);
27: }
28: }
29:
30: protected Parse appendCell(Parse row, String text) {
31: Parse lastCell = new Parse("td", text, null, null);
32: row.parts.last().more = lastCell;
33: return lastCell;
34: }
35:
36: public void reportError(Parse row, Exception e) {
37: Parse errorCell = makeMessageCell(e);
38: insertRowAfter(row, new Parse("tr", null, errorCell, null));
39: }
40:
41: public Parse makeMessageCell(Exception e) {
42: Parse errorCell = new Parse("td", "", null, null);
43: final StringWriter buffer = new StringWriter();
44:
45: e.printStackTrace(new PrintWriter(buffer));
46: errorCell.addToTag(" colspan=\"" + (columnBindings.length + 1)
47: + "\"");
48: errorCell.addToBody("<i>" + ERROR_INDICATOR + e.getMessage()
49: + "</i>");
50: errorCell.addToBody("<pre>" + (buffer.toString()) + "</pre>");
51: wrong(errorCell);
52:
53: return errorCell;
54: }
55:
56: public void insertRowAfter(Parse currentRow, Parse rowToAdd) {
57: Parse nextRow = currentRow.more;
58: currentRow.more = rowToAdd;
59: rowToAdd.more = nextRow;
60: }
61:
62: }
|