1 6 package net.sourceforge.jwebunit; 7 8 public class TableAssertionsTest extends JWebUnitTest { 9 10 public void setUp() throws Exception { 11 super.setUp(); 12 addTestPage(); 13 beginAt("/testPage.html"); 14 } 15 16 public void testAssertTablePresent() throws Throwable { 17 assertPassFail("assertTablePresent", "testTable", "noTable"); 18 } 19 20 public void testAssertTableNotPresent() throws Throwable { 21 assertPassFail("assertTableNotPresent", "noTable", "testTable"); 22 } 23 24 public void testAssertTextInTable() throws Throwable { 25 assertPassFail("assertTextInTable", 26 new Object []{"testTable", "table text"}, 27 new Object []{"testTable", "no such text"}); 28 } 29 30 public void testAssertTextNotInTable() throws Throwable { 31 assertPassFail("assertTextNotInTable", 32 new Object []{"testTable", "no such text"}, 33 new Object []{"testTable", "table text"}); 34 } 35 36 public void testAssertTextArrayInTable() throws Throwable { 37 assertPassFail("assertTextInTable", 38 new Object []{"testTable", new String []{"table text", "table text row 2"}}, 39 new Object []{"testTable", new String []{"table text", "no such row 2"}}); 40 } 41 42 public void testAssertTextArrayNotInTable() throws Throwable { 43 assertPassFail("assertTextNotInTable", 44 new Object []{"testTable", new String []{"no such row 1", "no such row 2"}}, 45 new Object []{"testTable", new String []{"no such row 1", "table text row 2"}}); 46 } 47 48 public void testAssertTableEquals() throws Throwable { 49 assertPass("assertTableEquals", 50 new Object []{"testTable", new String [][]{{"table text", ""}, 51 {"table text row 2", ""}, 52 {"table text row 3", "row 3 col 1"}}}); 53 } 54 55 public void testAssertTableEqualsExtraColumn() throws Throwable { 56 assertFail("assertTableEquals", 57 new Object []{"testTable", new String [][]{{"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 { 63 assertFail("assertTableEquals", 64 new Object []{"testTable", new String [][]{{"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 { 71 assertFail("assertTableEquals", 72 new Object []{"testTable", new String [][]{{"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 { 78 assertFail("assertTableEquals", 79 new Object []{"testTable", new String [][]{{"table text", ""}, 80 {"table text row 2", ""}, 81 {"table text row 3", ""}}}); 82 } 83 84 public void testAssertTableRowsEquals() throws Throwable { 85 assertPass("assertTableRowsEqual", 86 new Object []{"testTable", 87 new Integer (1), 88 new String [][]{{"table text row 2", ""}, 89 {"table text row 3", "row 3 col 1"}}}); 90 } 91 92 public void testAssertTableRowsEqualsTooManyExpected() throws Throwable { 93 assertFail("assertTableRowsEqual", 94 new Object []{"testTable", 95 new Integer (2), 96 new String [][]{{"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 |