KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > views > jsp > ParamTagTest


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.webwork.views.jsp;
6
7 import javax.servlet.jsp.JspException JavaDoc;
8 import javax.servlet.jsp.tagext.BodyTag JavaDoc;
9 import javax.servlet.jsp.tagext.Tag JavaDoc;
10 import java.io.StringWriter JavaDoc;
11 import java.util.Map JavaDoc;
12
13
14 /**
15  * ParamTagTest
16  *
17  * @author Jason Carreira
18  * Date: Mar 15, 2004 9:48:06 PM
19  */

20 public class ParamTagTest extends AbstractTagTest {
21     //~ Static fields/initializers /////////////////////////////////////////////
22

23     private static final String JavaDoc NAME_EXP = "name";
24     private static final String JavaDoc NAME_VAL = "name";
25     private static final String JavaDoc VAL_EXP = "%{'value'}";
26     private static final String JavaDoc VAL_VAL = "value";
27
28     //~ Instance fields ////////////////////////////////////////////////////////
29

30     private ParamTag tag;
31     private ParametereizedBodyTagSupport parentTag;
32
33     //~ Methods ////////////////////////////////////////////////////////////////
34

35     public void testParamSetWithNameAndBodyContent() throws JspException JavaDoc {
36         StringWriter JavaDoc writer = new StringWriter JavaDoc();
37         tag.setName(NAME_EXP);
38
39         WebWorkMockBodyContent webWorkMockBodyContent = new WebWorkMockBodyContent(new WebWorkMockJspWriter(writer));
40         webWorkMockBodyContent.setString(VAL_VAL);
41         tag.setBodyContent(webWorkMockBodyContent);
42         assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag());
43         assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
44
45         Map JavaDoc params = parentTag.getParameters();
46         assertEquals(1, params.size());
47         assertTrue(params.containsKey(NAME_VAL));
48         assertEquals(VAL_VAL, params.get(NAME_VAL));
49     }
50
51     public void testParamSetWithNameAndValueAttributes() throws JspException JavaDoc {
52         tag.setName(NAME_EXP);
53         tag.setValue(VAL_EXP);
54         assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag());
55         assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
56
57         Map JavaDoc params = parentTag.getParameters();
58         assertEquals(1, params.size());
59         assertTrue(params.containsKey(NAME_VAL));
60         assertEquals(VAL_VAL, params.get(NAME_VAL));
61     }
62
63     public void testParamSetWithValueAttributeWhenBothValueAttrAndBodyAreSet() throws JspException JavaDoc {
64         StringWriter JavaDoc writer = new StringWriter JavaDoc();
65         tag.setName(NAME_EXP);
66         tag.setValue(VAL_EXP);
67
68         WebWorkMockBodyContent webWorkMockBodyContent = new WebWorkMockBodyContent(new WebWorkMockJspWriter(writer));
69         webWorkMockBodyContent.setString("Will not be used");
70         tag.setBodyContent(webWorkMockBodyContent);
71         assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag());
72         assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
73
74         Map JavaDoc params = parentTag.getParameters();
75         assertEquals(1, params.size());
76         assertTrue(params.containsKey(NAME_VAL));
77         assertEquals(VAL_VAL, params.get(NAME_VAL));
78     }
79
80     protected void setUp() throws Exception JavaDoc {
81         super.setUp();
82         tag = new ParamTag();
83         tag.setPageContext(pageContext);
84         parentTag = new ParametereizedBodyTagSupport();
85         tag.setParent(parentTag);
86     }
87 }
88
Popular Tags