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