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