1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts2.views.jsp;
23
24 import javax.servlet.jsp.JspException;
25
26
27 /***
28 */
29 public class SetTagTest extends AbstractUITagTest {
30
31 Chewbacca chewie;
32 SetTag tag;
33
34
35 public void testApplicationScope() throws JspException {
36 tag.setName("foo");
37 tag.setValue("name");
38 tag.setScope("application");
39 tag.doStartTag();
40 tag.doEndTag();
41
42 assertEquals("chewie", servletContext.getAttribute("foo"));
43 }
44
45 public void testPageScope() throws JspException {
46 tag.setName("foo");
47 tag.setValue("name");
48 tag.setScope("page");
49 tag.doStartTag();
50 tag.doEndTag();
51
52 assertEquals("chewie", pageContext.getAttribute("foo"));
53 }
54
55 public void testRequestScope() throws JspException {
56 tag.setName("foo");
57 tag.setValue("name");
58 tag.setScope("request");
59 tag.doStartTag();
60 tag.doEndTag();
61 assertEquals("chewie", request.getAttribute("foo"));
62 }
63
64 public void testSessionScope() throws JspException {
65 tag.setName("foo");
66 tag.setValue("name");
67 tag.setScope("session");
68 tag.doStartTag();
69 tag.doEndTag();
70
71 assertEquals("chewie", session.get("foo"));
72 }
73
74 public void testStrutsScope() throws JspException {
75 tag.setName("foo");
76 tag.setValue("name");
77 tag.doStartTag();
78 tag.doEndTag();
79 assertEquals("chewie", context.get("foo"));
80 }
81
82 public void testStrutsScope2() throws JspException {
83 tag.setName("chewie");
84 tag.doStartTag();
85 tag.doEndTag();
86 assertEquals(chewie, context.get("chewie"));
87 }
88
89 protected void setUp() throws Exception {
90 super.setUp();
91
92 tag = new SetTag();
93 chewie = new Chewbacca("chewie", true);
94 stack.push(chewie);
95 tag.setPageContext(pageContext);
96 }
97
98
99 public class Chewbacca {
100 String name;
101 boolean furry;
102
103 public Chewbacca(String name, boolean furry) {
104 this.name = name;
105 this.furry = furry;
106 }
107
108 public void setFurry(boolean furry) {
109 this.furry = furry;
110 }
111
112 public boolean isFurry() {
113 return furry;
114 }
115
116 public void setName(String name) {
117 this.name = name;
118 }
119
120 public String getName() {
121 return name;
122 }
123 }
124 }