1 25 26 package org.objectweb.jonas.examples.clients.petstore; 27 28 import junit.framework.TestSuite; 29 30 import org.objectweb.jonas.examples.util.JExampleTestCase; 31 32 import com.meterware.httpunit.TableCell; 33 import com.meterware.httpunit.WebForm; 34 import com.meterware.httpunit.WebLink; 35 import com.meterware.httpunit.WebResponse; 36 import com.meterware.httpunit.WebTable; 37 38 42 public class F_Petstore extends JExampleTestCase { 43 44 47 private static final String URL_BASEPETSTORE = "/petstore/populating.jsp?forcefully=true"; 48 private static final String URL_MAINPAGE = "/petstore/main.screen"; 49 private static final String URL_CART = "/petstore/cart.do"; 50 private static final String URL_SIGNON = "/petstore/signon_welcome.screen"; 51 52 56 public static void main(String [] args) { 57 58 String testtorun = null; 59 for (int argn = 0; argn < args.length; argn++) { 61 String sArg = args[argn]; 62 if (sArg.equals("-n")) { 63 testtorun = args[++argn]; 64 } 65 } 66 67 if (testtorun == null) { 68 junit.textui.TestRunner.run(suite()); 69 } else { 70 junit.textui.TestRunner.run(new F_Petstore(testtorun)); 71 } 72 } 73 74 78 public static TestSuite suite() { 79 return new TestSuite(F_Petstore.class); 80 } 81 82 87 protected void setUp() throws Exception { 88 super.setUp(); 89 useEar("opc"); 90 useEar("petstoreadmin"); 91 useEar("petstore"); 92 useEar("supplier"); 93 } 94 95 99 public F_Petstore(String s) { 100 super(s, URL_BASEPETSTORE); 101 } 102 103 107 public void testHomePage() throws Exception { 108 WebResponse wr = wc.getResponse(getAbsoluteUrl(URL_MAINPAGE)); 109 WebTable[] webTables = wr.getTables(); 110 111 WebTable wTable = webTables[0]; 112 assertNotNull("There must be a table in the html page", wTable); 113 114 int rows = wTable.getRowCount(); 115 int cols = wTable.getColumnCount(); 116 117 TableCell tableCell = wTable.getTableCell(1, 0); 118 assertNotNull("There must be a cell in this row", tableCell); 119 WebLink[] links = tableCell.getLinks(); 120 assertNotNull("There must have links in this cell", links); 121 if (links.length == 5) { 122 String lk1 = links[0].asText(); 123 String lk2 = links[1].asText(); 124 String lk3 = links[2].asText(); 125 String lk4 = links[3].asText(); 126 String lk5 = links[4].asText(); 127 if (!lk1.equalsIgnoreCase("Birds")) { 128 fail("The first link must be egal to Birds and the value is " + lk1 + "."); 129 } else if (!lk2.equalsIgnoreCase("Cats")) { 130 fail("The first link must be egal to Cats and the value is " + lk2 + "."); 131 } else if (!lk3.equalsIgnoreCase("Dogs")) { 132 fail("The first link must be egal to Dogs and the value is " + lk3 + "."); 133 } else if (!lk4.equalsIgnoreCase("Fish")) { 134 fail("The first link must be egal to Fish and the value is " + lk4 + "."); 135 } else if (!lk5.equalsIgnoreCase("Reptiles")) { 136 fail("The first link must be egal to Reptiles and the value is " + lk5 + "."); 137 } 138 } else { 139 fail("There must have 5 links into this cell but there are " + links.length + " links !"); 140 } 141 } 142 143 147 public void testFirstNavigation() throws Exception { 148 WebResponse wr = wc.getResponse(getAbsoluteUrl(URL_MAINPAGE)); 149 WebTable[] webTables = wr.getTables(); 150 151 WebTable wTable = webTables[0]; 152 assertNotNull("There must be a table in the html page", wTable); 153 154 int rows = wTable.getRowCount(); 155 int cols = wTable.getColumnCount(); 156 157 TableCell tableCell = wTable.getTableCell(1, 0); 158 assertNotNull("There must be a cell in this row", tableCell); 159 WebLink[] links = tableCell.getLinks(); 160 assertNotNull("There must have links in this cell", links); 161 if (links.length == 5) { 162 wr = links[4].click(); 163 webTables = wr.getTables(); 164 165 wTable = webTables[0]; 166 assertNotNull("There must be a table in the html page", wTable); 167 168 rows = wTable.getRowCount(); 169 cols = wTable.getColumnCount(); 170 171 tableCell = wTable.getTableCell(1, 1); 172 assertNotNull("There must be a cell in this row", tableCell); 173 links = tableCell.getLinks(); 174 assertNotNull("There must have links in this cell", links); 175 String lk1 = links[0].asText(); 176 String lk2 = links[1].asText(); 177 if (!lk1.equalsIgnoreCase("Iguana")) { 178 fail("The first link must be egal to Iguana and the value is " + lk1 + "."); 179 } else if (!lk2.equalsIgnoreCase("Rattlesnake")) { 180 fail("The first link must be egal to Rattlesnake and the value is " + lk2 + "."); 181 } 182 183 } else { 184 fail("There must have 5 links into this cell but there are " + links.length + " links !"); 185 } 186 } 187 188 192 public void testAddCartRattlelessVenomless() throws Exception { 193 WebResponse wr = wc.getResponse(getAbsoluteUrl(URL_MAINPAGE)); 194 WebTable[] webTables = wr.getTables(); 195 196 WebTable wTable = webTables[0]; 197 assertNotNull("There must be a table in the html page", wTable); 198 199 int rows = wTable.getRowCount(); 200 int cols = wTable.getColumnCount(); 201 202 TableCell tableCell = wTable.getTableCell(1, 0); 203 assertNotNull("There must be a cell in this row", tableCell); 204 WebLink[] links = tableCell.getLinks(); 205 assertNotNull("There must have links in this cell", links); 206 if (links.length == 5) { 207 wr = links[4].click(); webTables = wr.getTables(); 209 210 wTable = webTables[0]; 211 assertNotNull("There must be a table in the html page", wTable); 212 213 rows = wTable.getRowCount(); 214 cols = wTable.getColumnCount(); 215 216 tableCell = wTable.getTableCell(1, 1); 217 assertNotNull("There must be a cell in this row", tableCell); 218 links = tableCell.getLinks(); 219 assertNotNull("There must have links in this cell", links); 220 221 WebLink rattlesnake = links[1]; 222 wr = rattlesnake.click(); 224 webTables = wr.getTables(); 225 226 wTable = webTables[0]; 227 assertNotNull("There must be a table in the html page", wTable); 228 229 rows = wTable.getRowCount(); 230 cols = wTable.getColumnCount(); 231 232 tableCell = wTable.getTableCell(1, 1); 233 assertNotNull("There must be a cell in this row", tableCell); 234 links = tableCell.getLinks(); 235 assertNotNull("There must have links in this cell", links); 236 if (links.length != 4) { 237 fail("There must have 4 links into this cell but there are " + links.length + " links !"); 238 } 239 wr = links[3].click(); webTables = wr.getTables(); 241 WebForm[] webForms = wr.getForms(); 242 WebForm webForm = webForms[4]; 243 assertNotNull("There must be a form in the html page", webForm); 244 WebResponse wFormRes = webForm.submit(); 245 246 wr = rattlesnake.click(); 248 webTables = wr.getTables(); 249 250 wTable = webTables[0]; 251 assertNotNull("There must be a table in the html page", wTable); 252 253 rows = wTable.getRowCount(); 254 cols = wTable.getColumnCount(); 255 256 tableCell = wTable.getTableCell(1, 1); 257 assertNotNull("There must be a cell in this row", tableCell); 258 links = tableCell.getLinks(); 259 assertNotNull("There must have links in this cell", links); 260 if (links.length != 4) { 261 fail("There must have 4 links into this cell but there are " + links.length + " links !"); 262 } 263 wr = links[1].click(); webTables = wr.getTables(); 265 webForms = wr.getForms(); 266 webForm = webForms[4]; 267 assertNotNull("There must be a form in the html page", webForm); 268 wFormRes = webForm.submit(); 269 270 wr = wc.getResponse(getAbsoluteUrl(URL_CART)); 272 webTables = wr.getTables(); 273 274 wTable = webTables[0]; 275 assertNotNull("There must be a table in the html page", wTable); 276 277 rows = wTable.getRowCount(); 278 cols = wTable.getColumnCount(); 279 280 tableCell = wTable.getTableCell(1, 1); 281 assertNotNull("There must be a cell in this row", tableCell); 282 webTables = tableCell.getTables(); 283 284 wTable = webTables[0]; 285 assertNotNull("There must be a table in the html page", wTable); 286 287 rows = wTable.getRowCount(); 288 cols = wTable.getColumnCount(); 289 290 tableCell = wTable.getTableCell(0, 0); 291 292 webTables = tableCell.getTables(); 293 294 wTable = webTables[0]; 295 assertNotNull("There must be a table in the html page", wTable); 296 297 rows = wTable.getRowCount(); 298 cols = wTable.getColumnCount(); 299 tableCell = wTable.getTableCell(2, 3); 300 String total = tableCell.asText().trim(); 301 if (!total.equalsIgnoreCase("$37.00")) { 302 fail("Total of the card must be $37.00 and it is " + total); 303 } 304 } else { 305 fail("There must have 5 links into this cell but there are " + links.length + " links !"); 306 } 307 } 308 309 } 310 | Popular Tags |