KickJava   Java API By Example, From Geeks To Geeks.

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


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.TextTag;
16
17
18 /**
19  * <p>
20  * This class test the text tag
21  * </p>
22  *
23  * @author Brian Pontarelli
24  * @since 2.0
25  * @version 2.0
26  */

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

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

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

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

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

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