KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

34     public FormTagTest(String JavaDoc name) {
35         super(name);
36         setLocal(true);
37     }
38
39     /**
40      * Tests that the form tag sets up the action correctly
41      */

42     public void testAction() {
43         FormTag tag = new FormTag();
44         tag.setPageContext(pageContext);
45         tag.setAction("testAction");
46         
47         try {
48             assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
49             String JavaDoc tagStr = getPageContext().getMockOut().getText();
50
51             System.out.println("Form tag: " + tagStr);
52             assertEquals("Should have tag", tagStr,
53                 "<form action=\"testAction\"></form>");
54         } catch (JspException JavaDoc e) {
55             fail(e.toString());
56         }
57     }
58
59     public void beginAction2(Request request) {
60         URL url = new URL("MyContext", null, "https", null, "www.inversoft.com", null);
61         request.setURL(url);
62     }
63
64     /**
65      * Tests that the repository tag is correctly finding the repository items
66      */

67     public void testAction2() {
68         FormTag tag = new FormTag();
69         tag.setPageContext(pageContext);
70         tag.setAction("/testAction");
71         
72         try {
73             assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
74             String JavaDoc tagStr = getPageContext().getMockOut().getText();
75             String JavaDoc expected = "<form action=\"/MyContext/testAction\"></form>";
76             System.out.println("Form tag: " + tagStr);
77             System.out.println("Expected: " + expected);
78             assertEquals("Should have tag", tagStr, expected);
79         } catch (JspException JavaDoc e) {
80             fail(e.toString());
81         }
82     }
83
84     /**
85      * Tests that the repository tag is correctly finding the repository items
86      */

87     public void testNameMethod() {
88         FormTag tag = new FormTag();
89         tag.setPageContext(pageContext);
90         tag.setName("testName");
91         tag.setMethod("post");
92         //tag.setOnsubmit("testOnsubmit");
93
//tag.setOnreset("testOnreset");
94

95         try {
96             tag.doStartTag();
97             String JavaDoc tagStr = getPageContext().getMockOut().getText();
98
99             System.out.println("Form tag: " + tagStr);
100             assertEquals("Should have tag", tagStr,
101                 "<form name=\"testName\" method=\"post\">");
102
103             tag.doEndTag();
104             tagStr = getPageContext().getMockOut().getText();
105
106             System.out.println("Form tag: " + tagStr);
107             assertEquals("Should have tag", tagStr,
108                 "<form name=\"testName\" method=\"post\"></form>");
109         } catch (JspException JavaDoc e) {
110             fail(e.toString());
111         }
112     }
113
114     /**
115      * Tests that the repository tag is correctly finding the repository items
116      */

117     public void testJS() {
118         FormTag tag = new FormTag();
119         tag.setPageContext(pageContext);
120         //tag.setName("testName");
121
//tag.setMethod("post");
122
tag.setOnsubmit("testOnsubmit");
123         //tag.setOnreset("testOnreset");
124

125         try {
126             tag.doStartTag();
127             String JavaDoc tagStr = getPageContext().getMockOut().getText();
128
129             System.out.println("Form tag: " + tagStr);
130             assertEquals("Should have tag", tagStr,
131                 "<form onsubmit=\"testOnsubmit\">");
132
133             tag.doEndTag();
134             tagStr = getPageContext().getMockOut().getText();
135
136             System.out.println("Form tag: " + tagStr);
137             assertEquals("Should have tag", tagStr,
138                 "<form onsubmit=\"testOnsubmit\"></form>");
139         } catch (JspException JavaDoc e) {
140             fail(e.toString());
141         }
142
143         tag = new FormTag();
144         tag.setPageContext(pageContext);
145         //tag.setOnsubmit("testOnsubmit");
146
tag.setOnreset("testOnreset");
147         
148         try {
149             getPageContext().getMockOut().clear();
150             tag.doStartTag();
151             String JavaDoc tagStr = getPageContext().getMockOut().getText();
152
153             System.out.println("Form tag: " + tagStr);
154             assertEquals("Should have tag", tagStr,
155                 "<form onreset=\"testOnreset\">");
156
157             tag.doEndTag();
158             tagStr = getPageContext().getMockOut().getText();
159
160             System.out.println("Form tag: " + tagStr);
161             assertEquals("Should have tag", tagStr,
162                 "<form onreset=\"testOnreset\"></form>");
163         } catch (JspException JavaDoc e) {
164             fail(e.toString());
165         }
166     }
167 }
Popular Tags