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:
15: public static final String RIGHT_STYLE = "pass";
16:
17: public static final String WRONG_STYLE = "fail";
18:
19: public void doRow(Parse row) {
20: if (row.parts.body.indexOf(ERROR_INDICATOR) != -1)
21: return;
22: super .doRow(row);
23: try {
24: enterRow();
25: right(appendCell(row, "entered"));
26: } catch (Exception e) {
27: wrong(appendCell(row, "skipped"));
28: reportError(row, e);
29: }
30: }
31:
32: protected Parse appendCell(Parse row, String text) {
33: Parse lastCell = new Parse("td", text, null, null);
34: row.parts.last().more = lastCell;
35: return lastCell;
36: }
37:
38: public void reportError(Parse row, Exception e) {
39: Parse errorCell = makeMessageCell(e);
40: insertRowAfter(row, new Parse("tr", null, errorCell, null));
41: }
42:
43: public Parse makeMessageCell(Exception e) {
44: Parse errorCell = new Parse("td", "", null, null);
45: final StringWriter buffer = new StringWriter();
46:
47: e.printStackTrace(new PrintWriter(buffer));
48: errorCell.addToTag(" colspan=\"" + (columnBindings.length + 1)
49: + "\"");
50: errorCell.addToBody("<i>" + ERROR_INDICATOR + e.getMessage()
51: + "</i>");
52: errorCell.addToBody("<pre>" + (buffer.toString()) + "</pre>");
53: wrong(errorCell);
54:
55: return errorCell;
56: }
57:
58: public void insertRowAfter(Parse currentRow, Parse rowToAdd) {
59: Parse nextRow = currentRow.more;
60: currentRow.more = rowToAdd;
61: rowToAdd.more = nextRow;
62: }
63:
64: }
|