KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > view > jsp > html > test > CheckboxTagTest


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.view.jsp.html.test;
8
9
10 import javax.servlet.jsp.JspException JavaDoc;
11 import javax.servlet.jsp.tagext.Tag JavaDoc;
12
13 import com.inversoft.junit.JspTestCase;
14 import com.inversoft.verge.mvc.view.jsp.html.CheckboxTag;
15 import com.inversoft.verge.mvc.view.jsp.html.FormTag;
16
17
18 /**
19  * <p>
20  * This class has the test cases for the img tag
21  * </p>
22  *
23  * @author Brian Pontarelli
24  * @since 2.0
25  * @version 2.0
26  */

27 public class CheckboxTagTest extends JspTestCase {
28
29     /**
30      * Constructor for ImgTagTest.
31      * @param name
32      */

33     public CheckboxTagTest(String JavaDoc name) {
34         super(name);
35         setLocal(true);
36     }
37
38
39     /**
40      * Tests the id attribute
41      */

42     public void testId() {
43         FormTag parent = new FormTag();
44         CheckboxTag tag = new CheckboxTag();
45         tag.setParent(parent);
46         tag.setPageContext(pageContext);
47         tag.setId("test");
48         
49         try {
50             assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
51             String JavaDoc tagStr = getPageContext().getMockOut().getText();
52
53             System.out.println("Checkbox tag: " + tagStr);
54             assertTrue("Should start with input", tagStr.startsWith(
55                 "<input type=\"checkbox\" id=\"test\""));
56         } catch (JspException JavaDoc e) {
57             fail(e.toString());
58         }
59     }
60
61     /**
62      * Tests the name attribute
63      */

64     public void testName() {
65         FormTag parent = new FormTag();
66         CheckboxTag tag = new CheckboxTag();
67         tag.setParent(parent);
68         tag.setPageContext(pageContext);
69         tag.setName("test");
70         
71         try {
72             assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
73             String JavaDoc tagStr = getPageContext().getMockOut().getText();
74
75             System.out.println("Checkbox tag: " + tagStr);
76             assertTrue("Should start with input", tagStr.startsWith(
77                 "<input type=\"checkbox\" name=\"test\""));
78         } catch (JspException JavaDoc e) {
79             fail(e.toString());
80         }
81     }
82
83     /**
84      * Tests the checked attribute
85      */

86     public void testChecked() {
87         FormTag parent = new FormTag();
88         CheckboxTag tag = new CheckboxTag();
89         tag.setParent(parent);
90         tag.setPageContext(pageContext);
91         tag.setName("test");
92         tag.setChecked(Boolean.TRUE);
93         
94         try {
95             assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
96             String JavaDoc tagStr = getPageContext().getMockOut().getText();
97
98             System.out.println("Checkbox tag: " + tagStr);
99             assertTrue("Should start with input", tagStr.startsWith(
100                 "<input type=\"checkbox\" name=\"test\""));
101             assertTrue("Should end with checked", tagStr.endsWith(
102                 "checked/>"));
103         } catch (JspException JavaDoc e) {
104             fail(e.toString());
105         }
106     }
107 }
Popular Tags