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