KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > view > jsp > form > test > SubmitTagTest


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.form.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.controller.form.FormURLTools;
15 import com.inversoft.verge.mvc.controller.form.config.test.FormMVCBuilderTest2;
16 import com.inversoft.verge.mvc.view.jsp.form.FormTag;
17 import com.inversoft.verge.mvc.view.jsp.form.SubmitTag;
18
19
20 /**
21  * <p>
22  * This class has the tests for the image tag
23  * </p>
24  *
25  * @author Brian Pontarelli
26  * @since 2.0
27  * @version 2.0
28  */

29 public class SubmitTagTest extends JspTestCase {
30
31     /**
32      * Constructor for ImageTagTest.
33      * @param name
34      */

35     public SubmitTagTest(String JavaDoc name) {
36         super(name);
37         setLocal(true);
38     }
39
40
41     /**
42      * Tests everything
43      */

44     public void testAll() {
45         // Build the config to test
46
FormMVCBuilderTest2 test = new FormMVCBuilderTest2("testValidate");
47         test.testValidate();
48
49         FormTag parent = new FormTag();
50         parent.setForm("form1");
51         parent.setVar("fb");
52         parent.setPageContext(pageContext);
53
54         SubmitTag tag = new SubmitTag();
55         tag.setParent(parent);
56         tag.setPageContext(pageContext);
57         tag.setId("test");
58         tag.setName("test");
59         tag.setAction("testAction");
60
61         try {
62             runTag(parent);
63             getPageContext().clearMockOut();
64
65             assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
66             String JavaDoc tagStr = getPageContext().getMockOut().getText();
67             String JavaDoc expected = "<input type=\"submit\" id=\"test\" name=\"test\"/>" +
68                 "<input type=\"hidden\" name=\"" + FormURLTools.SUBMIT_PARAMETER +
69                 "\" value=\"" + FormURLTools.generateSubmitParameter("test","testAction") + "\"/>";
70
71             System.out.println("Image tag: " + tagStr);
72             assertEquals(expected, tagStr);
73         } catch (JspException JavaDoc e) {
74             fail(e.toString());
75         }
76     }
77
78     /**
79      * Tests the submit tag with no name
80      */

81     public void testNoName() {
82         // Build the config to test
83
FormMVCBuilderTest2 test = new FormMVCBuilderTest2("testValidate");
84         test.testValidate();
85
86         FormTag parent = new FormTag();
87         parent.setForm("form1");
88         parent.setVar("fb");
89         parent.setPageContext(pageContext);
90
91         SubmitTag tag = new SubmitTag();
92         tag.setParent(parent);
93         tag.setPageContext(pageContext);
94         tag.setId("test");
95         tag.setAction("testAction");
96
97         try {
98             runTag(parent);
99             getPageContext().clearMockOut();
100
101             assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
102             String JavaDoc tagStr = getPageContext().getMockOut().getText();
103             String JavaDoc expected = "<input type=\"submit\" id=\"test\" name=\"_input-0\"/>" +
104                 "<input type=\"hidden\" name=\"" + FormURLTools.SUBMIT_PARAMETER +
105                 "\" value=\"" + FormURLTools.generateSubmitParameter("_input-0","testAction") + "\"/>";
106
107             System.out.println("Image tag: " + tagStr);
108             System.out.println("Expected: " + expected);
109             assertEquals(expected, tagStr);
110         } catch (JspException JavaDoc e) {
111             fail(e.toString());
112         }
113     }
114 }
Popular Tags