KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > httptest > ButtonTest


1 package info.magnolia.httptest;
2
3 import org.apache.commons.lang.StringUtils;
4
5 import com.meterware.httpunit.GetMethodWebRequest;
6 import com.meterware.httpunit.HTMLElement;
7 import com.meterware.httpunit.WebRequest;
8 import com.meterware.httpunit.WebResponse;
9
10
11 /**
12  * A simple basic test case to see httpunit working.
13  * @author fgiust
14  * @version $Revision: 365 $ ($Author: fgiust $)
15  */

16 public class ButtonTest extends HttpUnitTestCase {
17
18     /**
19      * @see info.magnolia.httptest.HttpUnitTestCase#getJspName()
20      */

21     public String JavaDoc getJspName() {
22         return "button.jsp";
23     }
24
25     /**
26      * @see info.magnolia.httptest.HttpUnitTestCase#doTest(java.lang.String)
27      */

28     public void doTest(String JavaDoc jspName) throws Exception JavaDoc {
29         WebRequest request = new GetMethodWebRequest(jspName);
30         WebResponse response = runner.getResponse(request);
31
32         String JavaDoc textContent = response.getText();
33
34         if (log.isDebugEnabled()) {
35             log.debug(textContent);
36         }
37
38         // this contains the button
39
HTMLElement container = response.getElementWithID("button");
40
41         // an example of checking the button label using html dom
42
assertEquals("Bad or missing button label.", "value", container.getText());
43
44         // and check nobr and nbsp using text
45
assertFalse("nobr tag is not a standard html tag", StringUtils.contains(textContent, "nobr"));
46         assertFalse("If a style is not set, the style attribute should not be written", StringUtils.contains(
47             textContent,
48             "style=\"\""));
49         assertFalse("nbsp should not be used for padding", StringUtils.contains(textContent, " "));
50
51     }
52 }
53
Popular Tags