01: /*
02: * $Id: MockServletConfig.java 471754 2006-11-06 14:55:09Z husted $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "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 javax.servlet.ServletConfig;
24: import javax.servlet.ServletContext;
25:
26: import java.util.Enumeration;
27: import java.util.HashMap;
28:
29: /**
30: * <p>Mock <strong>ServletConfig</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 the minimal set of methods needed to
35: * create unit tests is 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-07 12:11:38 -0400 (Sat, 07 May 2005)
43: * $
44: */
45: public class MockServletConfig implements ServletConfig {
46: // ----------------------------------------------------- Instance Variables
47: protected ServletContext context = null;
48: protected HashMap parameters = new HashMap();
49:
50: // ----------------------------------------------------------- Constructors
51: public MockServletConfig() {
52: super ();
53: }
54:
55: public MockServletConfig(ServletContext context) {
56: super ();
57: setServletContext(context);
58: }
59:
60: // --------------------------------------------------------- Public Methods
61: public void addInitParameter(String name, String value) {
62: parameters.put(name, value);
63: }
64:
65: public void setServletContext(ServletContext context) {
66: this .context = context;
67: }
68:
69: // ------------------------------------------------- ServletContext Methods
70: public String getInitParameter(String name) {
71: return ((String) parameters.get(name));
72: }
73:
74: public Enumeration getInitParameterNames() {
75: return (new MockEnumeration(parameters.keySet().iterator()));
76: }
77:
78: public ServletContext getServletContext() {
79: return (this .context);
80: }
81:
82: public String getServletName() {
83: return ("action");
84: }
85: }
|