KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > view > jsp > model > test > ParamTagTest


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.model.test;
8
9
10 import javax.servlet.jsp.JspException JavaDoc;
11 import javax.servlet.jsp.tagext.Tag JavaDoc;
12
13 import com.inversoft.junit.JspTestCallback;
14 import com.inversoft.junit.JspTestCase;
15 import com.inversoft.verge.mvc.view.jsp.html.ATag;
16 import com.inversoft.verge.mvc.view.jsp.model.ParamTag;
17 import com.inversoft.verge.util.ScopeConstants;
18
19
20 /**
21  * <p>
22  * This class has the test cases for the param tag
23  * </p>
24  *
25  * @author Brian Pontarelli
26  * @since 2.0
27  * @version 2.0
28  */

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

36     public ParamTagTest(String JavaDoc name) {
37         super(name);
38         setLocal(true);
39     }
40
41
42     /**
43      * Tests the link to a web object
44      */

45     public void testLinkWeb() {
46         Bean bean = new Bean();
47         request.setAttribute("bean", bean);
48         //pageContext.setAttribute("beanVar", bean);
49

50         ATag parent = new ATag();
51         parent.setHref("/url");
52         parent.setPageContext(pageContext);
53         parent.setBodyContent(createBodyContent("link"));
54         final ParamTag tag = new ParamTag();
55         tag.setParent(parent);
56         tag.setPageContext(pageContext);
57         tag.setName("tagName");
58         tag.setModel("bean.text");
59         tag.setValue("value");
60
61         JspTestCallback callback = new JspTestCallback() {
62             public void callback() {
63                 try {
64                     assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
65                 } catch (JspException JavaDoc jspe) {
66                     fail(jspe.toString());
67                 }
68             }
69         };
70
71         try {
72             assertEquals("Should return EVAL_PAGE", runTag(parent, callback), Tag.EVAL_PAGE);
73             String JavaDoc tagStr = getPageContext().getMockOut().getText();
74             String JavaDoc compStr = "<a HREF=\"/url?" +
75                 TestTools.createWebParam(tag.getName(), "bean.text",
76                     "com.inversoft.verge.mvc.view.jsp.model.test.Bean",
77                     ScopeConstants.REQUEST_INT) +
78                 "&tagName=value\">link</a>";
79
80             System.out.println("Anchor tag: " + tagStr);
81             System.out.println("Compare string: " + compStr);
82             assertEquals(tagStr, compStr);
83         } catch (JspException JavaDoc e) {
84             fail(e.toString());
85         }
86     }
87
88     /**
89      * Tests the tag creates its own name if needed
90      */

91     public void testNoName() {
92         Bean bean = new Bean();
93         request.setAttribute("bean", bean);
94         //pageContext.setAttribute("beanVar", bean);
95

96         ATag parent = new ATag();
97         parent.setHref("/url");
98         parent.setPageContext(pageContext);
99         parent.setBodyContent(createBodyContent("link"));
100         final ParamTag tag = new ParamTag();
101         tag.setParent(parent);
102         tag.setPageContext(pageContext);
103         tag.setModel("bean.text");
104         tag.setValue("value");
105
106         JspTestCallback callback = new JspTestCallback() {
107             public void callback() {
108                 try {
109                     assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
110                 } catch (JspException JavaDoc jspe) {
111                     fail(jspe.toString());
112                 }
113             }
114         };
115
116         try {
117             assertEquals("Should return EVAL_PAGE", runTag(parent, callback), Tag.EVAL_PAGE);
118             String JavaDoc tagStr = getPageContext().getMockOut().getText();
119             String JavaDoc compStr = "<a HREF=\"/url?" +
120                 TestTools.createWebParam("_input-0", "bean.text",
121                     "com.inversoft.verge.mvc.view.jsp.model.test.Bean",
122                     ScopeConstants.REQUEST_INT) +
123                 "&_input-0=value\">link</a>";
124
125             System.out.println("Anchor tag: " + tagStr);
126             System.out.println("Compare string: " + compStr);
127             assertEquals(tagStr, compStr);
128         } catch (JspException JavaDoc e) {
129             fail(e.toString());
130         }
131     }
132 }
Popular Tags