KickJava   Java API By Example, From Geeks To Geeks.

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


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.FormTag;
15 import com.inversoft.verge.mvc.view.jsp.html.HiddenTag;
16
17
18 /**
19  * <p>
20  * This class test the hidden tag
21  * </p>
22  *
23  * @author Brian Pontarelli
24  * @since 2.0
25  * @version 2.0
26  */

27 public class HiddenTagTest extends JspTestCase {
28
29     /**
30      * Constructor for HiddenTagTest.
31      *
32      * @param name The name of the test to run
33      */

34     public HiddenTagTest(String JavaDoc name) {
35         super(name);
36         setLocal(true);
37     }
38
39
40     /**
41      * Tests the the tag
42      */

43     public void testAll() {
44         FormTag parent = new FormTag();
45         HiddenTag tag = new HiddenTag();
46         tag.setParent(parent);
47         tag.setPageContext(pageContext);
48         tag.setId("test");
49         tag.setName("test");
50
51         try {
52             assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
53             String JavaDoc tagStr = getPageContext().getMockOut().getText();
54
55             System.out.println("Hidden tag: " + tagStr);
56             assertEquals("Should be hidden tag", tagStr,
57                 "<input type=\"hidden\" id=\"test\" name=\"test\" value=\"\"/>");
58         } catch (JspException JavaDoc e) {
59             fail(e.toString());
60         }
61     }
62
63     /**
64      * Tests the auto name generation of the tag
65      */

66     public void testNameGeneration() {
67         FormTag parent = new FormTag();
68         HiddenTag tag = new HiddenTag();
69         tag.setParent(parent);
70         tag.setPageContext(pageContext);
71         //tag.setId("test");
72
//tag.setName("test");
73

74         try {
75             assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
76             String JavaDoc tagStr = getPageContext().getMockOut().getText();
77
78             System.out.println("Hidden tag: " + tagStr);
79             assertEquals("Should be hidden tag with name", tagStr,
80                 "<input type=\"hidden\" name=\"_input-0\" value=\"\"/>");
81
82             // The container may reuse the same instance, so we need to make sure
83
// that that works
84
getPageContext().clearMockOut();
85             assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
86             tagStr = getPageContext().getMockOut().getText();
87
88             System.out.println("Hidden tag: " + tagStr);
89             assertEquals("Should be hidden tag with name", tagStr,
90                 "<input type=\"hidden\" name=\"_input-1\" value=\"\"/>");
91         } catch (JspException JavaDoc e) {
92             fail(e.toString());
93         }
94     }
95
96     /**
97      * Tests the auto name generation of the tag
98      */

99     public void testValue() {
100         FormTag parent = new FormTag();
101         HiddenTag tag = new HiddenTag();
102         tag.setParent(parent);
103         tag.setPageContext(pageContext);
104         tag.setName("test");
105         tag.setValue("${requestScope.test}");
106
107         try {
108             request.setAttribute("test", "TestValue");
109             assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
110             String JavaDoc tagStr = getPageContext().getMockOut().getText();
111
112             System.out.println("Hidden tag: " + tagStr);
113             assertEquals("Should be hidden tag with name", tagStr,
114                 "<input type=\"hidden\" name=\"test\" value=\"TestValue\"/>");
115
116             // The container may reuse the same instance, so we need to make sure
117
// that that works
118
getPageContext().clearMockOut();
119             tag.setName("test");
120             tag.setValue("${requestScope.test}");
121             request.setAttribute("test", "TestValue2");
122             assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
123             tagStr = getPageContext().getMockOut().getText();
124
125             System.out.println("Hidden tag: " + tagStr);
126             assertEquals("Should be hidden tag with name", tagStr,
127                 "<input type=\"hidden\" name=\"test\" value=\"TestValue2\"/>");
128         } catch (JspException JavaDoc e) {
129             fail(e.toString());
130         }
131     }
132 }
Popular Tags