View Javadoc

1   /*
2    * $Id: SetTagTest.java 418521 2006-07-01 23:36:50Z mrdon $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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 }