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.text.ParseException;
06:
07: import fit.Parse;
08: import junit.framework.TestCase;
09:
10: public class RowEntryFixtureTest extends TestCase {
11: private RowEntryFixture fixture;
12: private Parse simpleTable;
13: private String ERROR_MESSAGE = "bad input";
14:
15: protected void setUp() throws ParseException {
16: fixture = new RowEntryFixture() {
17: public int a = 0;
18: public int b = 0;
19:
20: public void enterRow() throws Exception {
21: throw new Exception(ERROR_MESSAGE);
22: }
23: };
24: simpleTable = new Parse(
25: "<table><tr><td>a</td></tr><tr><td>b</td></tr></table>");
26: }
27:
28: public void testExplore() {
29: assertEquals("<table>", simpleTable.tag);
30: assertEquals("<tr>", simpleTable.parts.tag);
31: assertEquals("<td>", simpleTable.parts.parts.tag);
32: assertEquals("a", simpleTable.parts.parts.body);
33:
34: assertEquals("<tr>", simpleTable.parts.more.tag);
35: assertEquals("<td>", simpleTable.parts.more.parts.tag);
36: assertEquals("b", simpleTable.parts.more.parts.body);
37: }
38:
39: public void testInsertRowAfter() {
40: Parse errorCell = new Parse("td", "error", null, null);
41: Parse row = new Parse("tr", null, errorCell, null);
42: fixture.insertRowAfter(simpleTable.parts.more, row);
43:
44: assertEquals("<tr>", simpleTable.parts.more.more.tag);
45: assertEquals("error", simpleTable.parts.more.more.parts.body);
46: }
47:
48: public void testInsertRowBetween() {
49: Parse errorCell = new Parse("td", "error", null, null);
50: Parse row = new Parse("tr", null, errorCell, null);
51: fixture.insertRowAfter(simpleTable.parts, row);
52:
53: assertEquals("<tr>", simpleTable.parts.more.tag);
54: assertEquals("error", simpleTable.parts.more.parts.body);
55:
56: assertEquals("<tr>", simpleTable.parts.more.more.tag);
57: assertEquals("b", simpleTable.parts.more.more.parts.body);
58: }
59:
60: public void testBadInput() throws ParseException {
61: Parse table = new Parse("<table>" + "<tr><td>Fixture</td></tr>"
62: + "<tr><td>a</td><td>b</td></tr>"
63: + "<tr><td>1</td><td>2</td></tr>" + "</table>");
64: fixture.doTable(table);
65: assertTrue(table.at(0, 3, 1).body.indexOf(ERROR_MESSAGE) != -1);
66: }
67:
68: public void testMessageFormat() throws ParseException {
69: Parse table = new Parse("<table>" + "<tr><td>Fixture</td></tr>"
70: + "<tr><td>a</td><td>b</td></tr>"
71: + "<tr><td>1</td><td>2</td></tr>" + "</table>");
72: fixture.doTable(table);
73: assertTrue(table.at(0, 3, 1).tag.indexOf("colspan=\"3\"") != -1);
74: }
75: }
|