1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
47 protected ServletContext context = null;
48 protected HashMap parameters = new HashMap();
49
50
51 public MockServletConfig() {
52 super();
53 }
54
55 public MockServletConfig(ServletContext context) {
56 super();
57 setServletContext(context);
58 }
59
60
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
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 }