KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > jwebunit > TableAssertionsTest


1 /*
2  * User: djoiner
3  * Date: Sep 9, 2002
4  * Time: 3:26:47 PM
5  */

6 package net.sourceforge.jwebunit;
7
8 public class TableAssertionsTest extends JWebUnitTest {
9
10     public void setUp() throws Exception JavaDoc {
11         super.setUp();
12         addTestPage();
13         beginAt("/testPage.html");
14     }
15
16     public void testAssertTablePresent() throws Throwable JavaDoc {
17         assertPassFail("assertTablePresent", "testTable", "noTable");
18     }
19
20     public void testAssertTableNotPresent() throws Throwable JavaDoc {
21         assertPassFail("assertTableNotPresent", "noTable", "testTable");
22     }
23
24     public void testAssertTextInTable() throws Throwable JavaDoc {
25         assertPassFail("assertTextInTable",
26                        new Object JavaDoc[]{"testTable", "table text"},
27                        new Object JavaDoc[]{"testTable", "no such text"});
28     }
29
30     public void testAssertTextNotInTable() throws Throwable JavaDoc {
31         assertPassFail("assertTextNotInTable",
32                        new Object JavaDoc[]{"testTable", "no such text"},
33                        new Object JavaDoc[]{"testTable", "table text"});
34     }
35
36     public void testAssertTextArrayInTable() throws Throwable JavaDoc {
37         assertPassFail("assertTextInTable",
38                        new Object JavaDoc[]{"testTable", new String JavaDoc[]{"table text", "table text row 2"}},
39                        new Object JavaDoc[]{"testTable", new String JavaDoc[]{"table text", "no such row 2"}});
40     }
41
42     public void testAssertTextArrayNotInTable() throws Throwable JavaDoc {
43         assertPassFail("assertTextNotInTable",
44                        new Object JavaDoc[]{"testTable", new String JavaDoc[]{"no such row 1", "no such row 2"}},
45                        new Object JavaDoc[]{"testTable", new String JavaDoc[]{"no such row 1", "table text row 2"}});
46     }
47
48     public void testAssertTableEquals() throws Throwable JavaDoc {
49         assertPass("assertTableEquals",
50                    new Object JavaDoc[]{"testTable", new String JavaDoc[][]{{"table text", ""},
51                                                             {"table text row 2", ""},
52                                                             {"table text row 3", "row 3 col 1"}}});
53     }
54
55     public void testAssertTableEqualsExtraColumn() throws Throwable JavaDoc {
56         assertFail("assertTableEquals",
57                    new Object JavaDoc[]{"testTable", new String JavaDoc[][]{{"table text", "", "extra column"},
58                                                             {"table text row 2", ""},
59                                                             {"table text row 3", "row 3 col 1"}}});
60     }
61
62     public void testAssertTableEqualsExtraRow() throws Throwable JavaDoc {
63         assertFail("assertTableEquals",
64                    new Object JavaDoc[]{"testTable", new String JavaDoc[][]{{"table text", ""},
65                                                             {"table text row 2", ""},
66                                                             {"table text row 3", "row 3 col 1"},
67                                                             {"no row 4"}}});
68     }
69
70     public void testAssertTableEqualsInvalidColumnText() throws Throwable JavaDoc {
71         assertFail("assertTableEquals",
72                    new Object JavaDoc[]{"testTable", new String JavaDoc[][]{{"table text", ""},
73                                                             {"no such text in row 2", ""},
74                                                             {"table text row 3", "row 3 col 1"}}});
75     }
76
77     public void testAssertTableEqualsMissingText() throws Throwable JavaDoc {
78         assertFail("assertTableEquals",
79                    new Object JavaDoc[]{"testTable", new String JavaDoc[][]{{"table text", ""},
80                                                             {"table text row 2", ""},
81                                                             {"table text row 3", ""}}});
82     }
83
84     public void testAssertTableRowsEquals() throws Throwable JavaDoc {
85         assertPass("assertTableRowsEqual",
86                    new Object JavaDoc[]{"testTable",
87                                 new Integer JavaDoc(1),
88                                 new String JavaDoc[][]{{"table text row 2", ""},
89                                                {"table text row 3", "row 3 col 1"}}});
90     }
91
92     public void testAssertTableRowsEqualsTooManyExpected() throws Throwable JavaDoc {
93         assertFail("assertTableRowsEqual",
94                    new Object JavaDoc[]{"testTable",
95                                 new Integer JavaDoc(2),
96                                 new String JavaDoc[][]{{"table text row 3", "row 3 col 1"},
97                                                {"unexpected", ""}}});
98     }
99
100     private void addTestPage() {
101         defineWebPage("testPage", "This is a test page." +
102                                   "<table id=\"testTable\">" +
103                                   "<tr><td>table text</td></tr>" +
104                                   "<tr><td>table text row 2</td></tr>" +
105                                   "<tr><td>table text row 3</td><td>row 3 col 1</td>" +
106                                   "<a HREF=\"someurl.html\">test link</a>" +
107                                   "<form>" +
108                                   "<input type=\"text\" name=\"testInputElement\" value=\"testValue\"/>" +
109                                   "<input type=\"submit\" name=\"submitButton\" value=\"buttonLabel\"/>" +
110                                   "<input type=\"checkbox\" name=\"checkboxselected\" CHECKED>" +
111                                   "<input type=\"checkbox\" name=\"checkboxnotselected\">" +
112                                   "</form>" +
113                                   "<form name=\"form2\"></form>" +
114                                   "</table>");
115         defineWebPage("noFormPage", "");
116     }
117
118 }
119
Popular Tags