View Javadoc

    1   /*
    2    * $Id: SetTagTest.java 471756 2006-11-06 15:01:43Z husted $
    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  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 }