KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > view > jsp > actionflow > 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.actionflow.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.actionflow.ActionFlowURLTools;
15 import com.inversoft.verge.mvc.view.jsp.actionflow.FormTag;
16 import com.inversoft.verge.mvc.view.jsp.actionflow.SubmitTag;
17
18
19 /**
20  * <p>
21  * This class has the tests for the image tag
22  * </p>
23  *
24  * @author Brian Pontarelli
25  * @since 2.0
26  * @version 2.0
27  */

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

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

43     public void testAction() {
44         FormTag parent = new FormTag();
45         parent.setPageContext(pageContext);
46         parent.setNamespace("ns");
47
48         SubmitTag tag = new SubmitTag();
49         tag.setParent(parent);
50         tag.setPageContext(pageContext);
51         tag.setId("test");
52         tag.setName("test");
53         tag.setAction("testAction");
54         
55         try {
56             runTag(parent);
57             getPageContext().clearMockOut();
58
59             assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
60             String JavaDoc tagStr = getPageContext().getMockOut().getText();
61
62             String JavaDoc expected = "<input type=\"submit\" id=\"test\" name=\"test\"/>" +
63                 "<input type=\"hidden\" name=\"" +
64                 ActionFlowURLTools.SUBMIT_PARAMETER + "\"" +
65                 " value=\"" + ActionFlowURLTools.generateSubmitParameter("test",
66                     "testAction", null, null) + "\"/>";
67             System.out.println("Expected: " + expected);
68             System.out.println("Actual: " + tagStr);
69             assertEquals("Should start with input", expected, tagStr);
70         } catch (JspException JavaDoc e) {
71             fail(e.toString());
72         }
73     }
74
75     /**
76      * Tests entry node
77      */

78     public void testEntry() {
79         FormTag parent = new FormTag();
80         parent.setPageContext(pageContext);
81         parent.setNamespace("ns");
82
83         SubmitTag tag = new SubmitTag();
84         tag.setParent(parent);
85         tag.setPageContext(pageContext);
86         tag.setId("test");
87         tag.setName("test");
88         tag.setEntry("testEntry");
89         tag.setAction("testAction");
90
91         try {
92             runTag(parent);
93             getPageContext().clearMockOut();
94
95             assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
96             String JavaDoc tagStr = getPageContext().getMockOut().getText();
97
98             String JavaDoc expected = "<input type=\"submit\" id=\"test\" name=\"test\"/>" +
99                 "<input type=\"hidden\" name=\"" +
100                 ActionFlowURLTools.SUBMIT_PARAMETER + "\"" +
101                 " value=\"" + ActionFlowURLTools.generateSubmitParameter("test",
102                     "testAction", "testEntry", null) + "\"/>";
103             System.out.println("Expected: " + expected);
104             System.out.println("Actual: " + tagStr);
105             assertEquals("Should start with input", expected, tagStr);
106         } catch (JspException JavaDoc e) {
107             fail(e.toString());
108         }
109     }
110 }
Popular Tags