1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts.mock;
19
20 import javax.servlet.ServletConfig;
21 import javax.servlet.ServletContext;
22
23 import java.util.Enumeration;
24 import java.util.HashMap;
25
26 /***
27 * <p>Mock <strong>ServletConfig</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 the minimal set of methods needed to
32 * create unit tests is 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-07 12:11:38 -0400 (Sat, 07 May 2005)
40 * $
41 */
42 public class MockServletConfig implements ServletConfig {
43
44 protected ServletContext context = null;
45 protected HashMap parameters = new HashMap();
46
47
48 public MockServletConfig() {
49 super();
50 }
51
52 public MockServletConfig(ServletContext context) {
53 super();
54 setServletContext(context);
55 }
56
57
58 public void addInitParameter(String name, String value) {
59 parameters.put(name, value);
60 }
61
62 public void setServletContext(ServletContext context) {
63 this.context = context;
64 }
65
66
67 public String getInitParameter(String name) {
68 return ((String) parameters.get(name));
69 }
70
71 public Enumeration getInitParameterNames() {
72 return (new MockEnumeration(parameters.keySet().iterator()));
73 }
74
75 public ServletContext getServletContext() {
76 return (this.context);
77 }
78
79 public String getServletName() {
80 return ("action");
81 }
82 }