001: /*
002: * $Id: $
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.struts.taglib;
022:
023: import junit.framework.TestCase;
024:
025: import org.apache.struts.Globals;
026: import org.apache.struts.config.ForwardConfig;
027: import org.apache.struts.config.ModuleConfig;
028: import org.apache.struts.config.impl.ModuleConfigImpl;
029: import org.apache.struts.mock.MockHttpServletRequest;
030: import org.apache.struts.mock.MockHttpServletResponse;
031: import org.apache.struts.mock.MockHttpSession;
032: import org.apache.struts.mock.MockPageContext;
033: import org.apache.struts.mock.MockServletConfig;
034: import org.apache.struts.mock.MockServletContext;
035: import org.apache.struts.util.MessageResources;
036: import org.apache.struts.util.MessageResourcesFactory;
037: import org.apache.struts.util.PropertyMessageResources;
038:
039: public class TagTestBase extends TestCase {
040: protected TagUtils tagutils = TagUtils.getInstance();
041: protected MockServletConfig servletConfig;
042: protected MockServletContext servletContext;
043: protected MockHttpServletRequest request;
044: protected MockPageContext pageContext;
045: protected ModuleConfig moduleConfig;
046: protected ModuleConfig moduleConfig2;
047: protected ModuleConfig moduleConfig3;
048:
049: public TagTestBase() {
050: super ();
051: }
052:
053: public TagTestBase(String theName) {
054: super (theName);
055: }
056:
057: /**
058: * Helper method that creates/configures a basic configuration of Mock
059: * Objects.
060: *
061: *
062: * PageContext ServletConfig ServletContext HttpServletRequest HttpSession
063: * HttpServletResponse
064: *
065: * "/myapp", "/foo", null, null,
066: */
067: public void setUp() {
068: // -- default Module
069: this .moduleConfig = new ModuleConfigImpl("");
070: this .moduleConfig.addForwardConfig(new ForwardConfig("foo",
071: "/bar.jsp", false));
072: this .moduleConfig.addForwardConfig(new ForwardConfig(
073: "relative1", "relative.jsp", false));
074: this .moduleConfig.addForwardConfig(new ForwardConfig(
075: "relative2", "relative.jsp", false));
076: this .moduleConfig.addForwardConfig(new ForwardConfig(
077: "external", "http://struts.apache.org/", false));
078:
079: // -- module "/2"
080: this .moduleConfig2 = new ModuleConfigImpl("/2");
081: this .moduleConfig2.addForwardConfig(new ForwardConfig("foo",
082: "/baz.jsp", false));
083: this .moduleConfig2.addForwardConfig(new ForwardConfig(
084: "relative1", "relative.jsp", false));
085: this .moduleConfig2.addForwardConfig(new ForwardConfig(
086: "relative2", "relative.jsp", false));
087: this .moduleConfig2.addForwardConfig(new ForwardConfig(
088: "external", "http://struts.apache.org/", false));
089:
090: // -- module "/3"
091: this .moduleConfig3 = new ModuleConfigImpl("/3");
092:
093: // -- configure the ServletContext
094: this .servletContext = new MockServletContext();
095: this .servletContext.setAttribute(Globals.MODULE_KEY,
096: moduleConfig);
097: this .servletContext.setAttribute(Globals.MODULE_KEY + "/2",
098: moduleConfig2);
099: this .servletContext.setAttribute(Globals.MODULE_KEY + "/3",
100: moduleConfig3);
101:
102: // -- configure the ServletConfig
103: this .servletConfig = new MockServletConfig();
104: this .servletConfig.setServletContext(servletContext);
105:
106: // -- configure the request
107: this .request = new MockHttpServletRequest(new MockHttpSession());
108:
109: pageContext = new MockPageContext(servletConfig, request,
110: new MockHttpServletResponse());
111: }
112:
113: public void tearDown() {
114: this .moduleConfig = null;
115: this .moduleConfig2 = null;
116: this .moduleConfig3 = null;
117: this .pageContext = null;
118: this .request = null;
119: }
120:
121: protected void putBundleInScope(int scope, boolean returnNull) {
122: MessageResourcesFactory factory = MessageResourcesFactory
123: .createFactory();
124: MessageResources messageResources = new PropertyMessageResources(
125: factory, "org.apache.struts.taglib.sample");
126:
127: messageResources.setReturnNull(returnNull);
128: pageContext.setAttribute(Globals.MESSAGES_KEY,
129: messageResources, scope);
130: }
131: }
|