KickJava   Java API By Example, From Geeks To Geeks.

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


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

5 package com.opensymphony.webwork.views.jsp;
6
7 import com.mockobjects.dynamic.C;
8 import com.mockobjects.dynamic.Mock;
9
10 import javax.servlet.ServletContext JavaDoc;
11 import javax.servlet.http.HttpSession JavaDoc;
12 import javax.servlet.jsp.JspException JavaDoc;
13 import javax.servlet.jsp.tagext.Tag JavaDoc;
14
15
16 /**
17  * @author $Author: plightbo $
18  * @version $Revision: 1.6 $
19  */

20 public class SetTagTest extends AbstractUITagTest {
21     //~ Instance fields ////////////////////////////////////////////////////////
22

23     Chewbacca chewie;
24     SetTag tag;
25
26     //~ Methods ////////////////////////////////////////////////////////////////
27

28     public void testApplicationScope() throws JspException JavaDoc {
29         Mock application = new Mock(ServletContext JavaDoc.class);
30         application.expect("setAttribute", C.args(C.eq("foo"), C.eq("chewie")));
31         pageContext.setServletContext((ServletContext JavaDoc) application.proxy());
32
33         tag.setName("foo");
34         tag.setValue("name");
35         tag.setScope("application");
36         assertEquals(Tag.SKIP_BODY, tag.doStartTag());
37         application.verify();
38     }
39
40     public void testPageScope() throws JspException JavaDoc {
41         tag.setName("foo");
42         tag.setValue("name");
43         tag.setScope("page");
44         assertEquals(Tag.SKIP_BODY, tag.doStartTag());
45     }
46
47     public void testRequestScope() throws JspException JavaDoc {
48         tag.setName("foo");
49         tag.setValue("name");
50         tag.setScope("request");
51         assertEquals(Tag.SKIP_BODY, tag.doStartTag());
52         assertEquals("chewie", request.getAttribute("foo"));
53     }
54
55     public void testSessionScope() throws JspException JavaDoc {
56         Mock session = new Mock(HttpSession JavaDoc.class);
57         session.expect("setAttribute", C.args(C.eq("foo"), C.eq("chewie")));
58         pageContext.setSession((HttpSession JavaDoc) session.proxy());
59
60         tag.setName("foo");
61         tag.setValue("name");
62         tag.setScope("session");
63         assertEquals(Tag.SKIP_BODY, tag.doStartTag());
64         session.verify();
65     }
66
67     public void testWebWorkScope() throws JspException JavaDoc {
68         tag.setName("foo");
69         tag.setValue("name");
70         assertEquals(Tag.SKIP_BODY, tag.doStartTag());
71         assertEquals("chewie", context.get("foo"));
72     }
73
74     public void testWebWorkScope2() throws JspException JavaDoc {
75         tag.setName("chewie");
76         assertEquals(Tag.SKIP_BODY, tag.doStartTag());
77         assertEquals(chewie, context.get("chewie"));
78     }
79
80     protected void setUp() throws Exception JavaDoc {
81         super.setUp();
82
83         tag = new SetTag();
84         chewie = new Chewbacca("chewie", true);
85         stack.push(chewie);
86         tag.setPageContext(pageContext);
87     }
88
89     //~ Inner Classes //////////////////////////////////////////////////////////
90

91     public class Chewbacca {
92         String JavaDoc name;
93         boolean furry;
94
95         public Chewbacca(String JavaDoc name, boolean furry) {
96             this.name = name;
97             this.furry = furry;
98         }
99
100         public void setFurry(boolean furry) {
101             this.furry = furry;
102         }
103
104         public boolean isFurry() {
105             return furry;
106         }
107
108         public void setName(String JavaDoc name) {
109             this.name = name;
110         }
111
112         public String JavaDoc getName() {
113             return name;
114         }
115     }
116 }
117
Popular Tags