Testes em aplicações Web com o Cactus
Testes em aplicações Web com o Cactus
Testes em aplicações Web com o Cactus
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Veja MapperServletTest2.java<br />
HttpUnit <strong>com</strong> <strong>Cactus</strong><br />
• Troque o <strong>Web</strong>Response <strong>em</strong> cada endXXX() por<br />
<strong>com</strong>.meterware.httpunit.<strong>Web</strong>Response<br />
public void endDoGet(<strong>com</strong>.meterware.httpunit.<strong>Web</strong>Response resp)<br />
throws org.xml.sax.SAXException {<br />
<strong>Web</strong>Table[] tables = resp.getTables();<br />
assertNotNull(tables);<br />
assertEquals(tables.length, 1); // só há uma tabela<br />
<strong>Web</strong>Table table = tables[0];<br />
int rows = table.getRowCount();<br />
boolean keyDefined = false;<br />
for (int i = 0; i < rows; i++) {<br />
String key = table.getCellAsText(i, 0); // col 1<br />
String value = table.getCellAsText(i, 1); // col 2<br />
if (key.equals("USER")) {<br />
keyDefined = true;<br />
assertEquals("JABBERWOCK", value);<br />
}<br />
}<br />
if (!keyDefined) {<br />
fail("No key named USER was found!");<br />
}<br />
}<br />
15