001: /*
002: * $Id: MockActionServlet.java 471754 2006-11-06 14:55:09Z 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.struts.mock;
022:
023: import org.apache.struts.action.ActionServlet;
024:
025: import javax.servlet.ServletConfig;
026: import javax.servlet.ServletContext;
027: import javax.servlet.ServletException;
028:
029: /**
030: * <p>Mock <strong>ActionServlet</strong> object for low-level unit tests of
031: * Struts controller components. Coarser grained tests should be implemented
032: * in terms of the Cactus framework, instead of the mock object classes.</p>
033: *
034: * <p><strong>WARNING</strong> - Only getter methods for servletContext and
035: * servletConfig are provided, plus additional methods to configure this
036: * object as necessary. Methods for unsupported operations will throw
037: * <code>UnsupportedOperationException</code>.</p>
038: *
039: * <p><strong>WARNING</strong> - Because unit tests operate in a single
040: * threaded environment, no synchronization is performed.</p>
041: *
042: * @version $Rev: 471754 $ $Date: 2005-05-14 02:09:06 -0400 (Sat, 14 May 2005)
043: * $
044: */
045: public class MockActionServlet extends ActionServlet {
046: protected ServletContext servletContext;
047: protected ServletConfig servletConfig;
048:
049: /**
050: * <p>Constructor.</p>
051: */
052: public MockActionServlet(ServletContext servletContext,
053: ServletConfig servletConfig) {
054: this .servletContext = servletContext;
055: this .servletConfig = servletConfig;
056: }
057:
058: /**
059: * <p>Constructor.</p>
060: */
061: public MockActionServlet() {
062: ; // do nothing
063: }
064:
065: /**
066: * <p> Set property </p>
067: *
068: * @param servletContext
069: */
070: public void setServletContext(ServletContext servletContext) {
071: this .servletContext = servletContext;
072: }
073:
074: /**
075: * <p> Get property </p>
076: *
077: * @return
078: */
079: public ServletContext getServletContext() {
080: return servletContext;
081: }
082:
083: /**
084: * <p> Set property
085: *
086: * @param servletConfig
087: */
088: public void setServletConfig(ServletConfig servletConfig) {
089: this .servletConfig = servletConfig;
090: }
091:
092: /**
093: * <p> Get property </p>
094: *
095: * @return
096: */
097: public ServletConfig getServletConfig() {
098: return servletConfig;
099: }
100:
101: /**
102: * <p> Expose as public so that test classes can exercise things which
103: * retrieve messages. </p>
104: */
105: public void initInternal() throws ServletException {
106: super.initInternal();
107: }
108: }
|