View Javadoc

1   /*
2    * $Id: MockActionServlet.java 421119 2006-07-12 04:49:11Z wsmoak $
3    *
4    * Copyright 1999-2004 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts.mock;
19  
20  import org.apache.struts.action.ActionServlet;
21  
22  import javax.servlet.ServletConfig;
23  import javax.servlet.ServletContext;
24  import javax.servlet.ServletException;
25  
26  /***
27   * <p>Mock <strong>ActionServlet</strong> object for low-level unit tests of
28   * Struts controller components.  Coarser grained tests should be implemented
29   * in terms of the Cactus framework, instead of the mock object classes.</p>
30   *
31   * <p><strong>WARNING</strong> - Only getter methods for servletContext and
32   * servletConfig are provided, plus additional methods to configure this
33   * object as necessary.  Methods for unsupported operations will throw
34   * <code>UnsupportedOperationException</code>.</p>
35   *
36   * <p><strong>WARNING</strong> - Because unit tests operate in a single
37   * threaded environment, no synchronization is performed.</p>
38   *
39   * @version $Rev: 421119 $ $Date: 2005-05-14 02:09:06 -0400 (Sat, 14 May 2005)
40   *          $
41   */
42  public class MockActionServlet extends ActionServlet {
43      protected ServletContext servletContext;
44      protected ServletConfig servletConfig;
45  
46      /***
47       * <p>Constructor.</p>
48       */
49      public MockActionServlet(ServletContext servletContext,
50          ServletConfig servletConfig) {
51          this.servletContext = servletContext;
52          this.servletConfig = servletConfig;
53      }
54  
55      /***
56       * <p>Constructor.</p>
57       */
58      public MockActionServlet() {
59          ; // do nothing
60      }
61  
62      /***
63       * <p> Set property </p>
64       *
65       * @param servletContext
66       */
67      public void setServletContext(ServletContext servletContext) {
68          this.servletContext = servletContext;
69      }
70  
71      /***
72       * <p> Get property </p>
73       *
74       * @return
75       */
76      public ServletContext getServletContext() {
77          return servletContext;
78      }
79  
80      /***
81       * <p> Set property
82       *
83       * @param servletConfig
84       */
85      public void setServletConfig(ServletConfig servletConfig) {
86          this.servletConfig = servletConfig;
87      }
88  
89      /***
90       * <p> Get property </p>
91       *
92       * @return
93       */
94      public ServletConfig getServletConfig() {
95          return servletConfig;
96      }
97  
98      /***
99       * <p> Expose as public so that test classes can exercise things which
100      * retrieve messages. </p>
101      */
102     public void initInternal()
103         throws ServletException {
104         super.initInternal();
105     }
106 }