MockActionServlet xref

View Javadoc

    1   /*
    2    * $Id: MockActionServlet.java 471754 2006-11-06 14:55:09Z 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.struts.mock;
    22
    23  import org.apache.struts.action.ActionServlet;
    24
    25  import javax.servlet.ServletConfig;
    26  import javax.servlet.ServletContext;
    27  import javax.servlet.ServletException;
    28
    29  /**
    30   * <p>Mock <strong>ActionServlet</strong> object for low-level unit tests of
    31   * Struts controller components.  Coarser grained tests should be implemented
    32   * in terms of the Cactus framework, instead of the mock object classes.</p>
    33   *
    34   * <p><strong>WARNING</strong> - Only getter methods for servletContext and
    35   * servletConfig are provided, plus additional methods to configure this
    36   * object as necessary.  Methods for unsupported operations will throw
    37   * <code>UnsupportedOperationException</code>.</p>
    38   *
    39   * <p><strong>WARNING</strong> - Because unit tests operate in a single
    40   * threaded environment, no synchronization is performed.</p>
    41   *
    42   * @version $Rev: 471754 $ $Date: 2005-05-14 02:09:06 -0400 (Sat, 14 May 2005)
    43   *          $
    44   */
    45  public class MockActionServlet extends ActionServlet {
    46      protected ServletContext servletContext;
    47      protected ServletConfig servletConfig;
    48
    49      /**
    50       * <p>Constructor.</p>
    51       */
    52      public MockActionServlet(ServletContext servletContext,
    53          ServletConfig servletConfig) {
    54          this.servletContext = servletContext;
    55          this.servletConfig = servletConfig;
    56      }
    57
    58      /**
    59       * <p>Constructor.</p>
    60       */
    61      public MockActionServlet() {
    62          ; // do nothing
    63      }
    64
    65      /**
    66       * <p> Set property </p>
    67       *
    68       * @param servletContext
    69       */
    70      public void setServletContext(ServletContext servletContext) {
    71          this.servletContext = servletContext;
    72      }
    73
    74      /**
    75       * <p> Get property </p>
    76       *
    77       * @return
    78       */
    79      public ServletContext getServletContext() {
    80          return servletContext;
    81      }
    82
    83      /**
    84       * <p> Set property
    85       *
    86       * @param servletConfig
    87       */
    88      public void setServletConfig(ServletConfig servletConfig) {
    89          this.servletConfig = servletConfig;
    90      }
    91
    92      /**
    93       * <p> Get property </p>
    94       *
    95       * @return
    96       */
    97      public ServletConfig getServletConfig() {
    98          return servletConfig;
    99      }
    100
    101     /**
    102      * <p> Expose as public so that test classes can exercise things which
    103      * retrieve messages. </p>
    104      */
    105     public void initInternal()
    106         throws ServletException {
    107         super.initInternal();
    108     }
    109 }