001: /*
002: * $Id: SetTagTest.java 471756 2006-11-06 15:01:43Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.views.jsp;
022:
023: import javax.servlet.jsp.JspException;
024:
025: /**
026: */
027: public class SetTagTest extends AbstractUITagTest {
028:
029: Chewbacca chewie;
030: SetTag tag;
031:
032: public void testApplicationScope() throws JspException {
033: tag.setName("foo");
034: tag.setValue("name");
035: tag.setScope("application");
036: tag.doStartTag();
037: tag.doEndTag();
038:
039: assertEquals("chewie", servletContext.getAttribute("foo"));
040: }
041:
042: public void testPageScope() throws JspException {
043: tag.setName("foo");
044: tag.setValue("name");
045: tag.setScope("page");
046: tag.doStartTag();
047: tag.doEndTag();
048:
049: assertEquals("chewie", pageContext.getAttribute("foo"));
050: }
051:
052: public void testRequestScope() throws JspException {
053: tag.setName("foo");
054: tag.setValue("name");
055: tag.setScope("request");
056: tag.doStartTag();
057: tag.doEndTag();
058: assertEquals("chewie", request.getAttribute("foo"));
059: }
060:
061: public void testSessionScope() throws JspException {
062: tag.setName("foo");
063: tag.setValue("name");
064: tag.setScope("session");
065: tag.doStartTag();
066: tag.doEndTag();
067:
068: assertEquals("chewie", session.get("foo"));
069: }
070:
071: public void testStrutsScope() throws JspException {
072: tag.setName("foo");
073: tag.setValue("name");
074: tag.doStartTag();
075: tag.doEndTag();
076: assertEquals("chewie", context.get("foo"));
077: }
078:
079: public void testStrutsScope2() throws JspException {
080: tag.setName("chewie");
081: tag.doStartTag();
082: tag.doEndTag();
083: assertEquals(chewie, context.get("chewie"));
084: }
085:
086: protected void setUp() throws Exception {
087: super .setUp();
088:
089: tag = new SetTag();
090: chewie = new Chewbacca("chewie", true);
091: stack.push(chewie);
092: tag.setPageContext(pageContext);
093: }
094:
095: public class Chewbacca {
096: String name;
097: boolean furry;
098:
099: 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: }
|