View Javadoc

1   /*
2    * $Id: SetTagTest.java 651946 2008-04-27 13:41:38Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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 }