2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shale.test.mock;
19
20 import java.util.Enumeration;
21 import java.util.Hashtable;
22
23 import javax.servlet.ServletConfig;
24 import javax.servlet.ServletContext;
25
26 /***
27 * <p>Mock implementation of <code>ServletConfig</code>.</p>
28 *
29 * $Id$
30 */
31
32 public class MockServletConfig implements ServletConfig {
33
34
35
36
37
38 /***
39 * <p>Construct a default instance.</p>
40 */
41 public MockServletConfig() {
42 }
43
44
45 /***
46 * <p>Construct an instance associated with the specified
47 * servlet context.</p>
48 *
49 * @param context The associated ServletContext
50 */
51 public MockServletConfig(ServletContext context) {
52 setServletContext(context);
53 }
54
55
56
57
58
59 /***
60 * <p>Add a servlet initialization parameter.</p>
61 *
62 * @param name Parameter name
63 * @param value Parameter value
64 */
65 public void addInitParameter(String name, String value) {
66
67 parameters.put(name, value);
68
69 }
70
71
72 /***
73 * <p>Set the servlet context for this application.</p>
74 *
75 * @param context The new servlet context
76 */
77 public void setServletContext(ServletContext context) {
78
79 this.context = context;
80
81 }
82
83
84
85
86
87 private ServletContext context;
88 private Hashtable parameters = new Hashtable();
89
90
91
92
93
94 /*** {@inheritDoc} */
95 public String getInitParameter(String name) {
96
97 return (String) parameters.get(name);
98
99 }
100
101
102 /*** {@inheritDoc} */
103 public Enumeration getInitParameterNames() {
104
105 return parameters.keys();
106
107 }
108
109
110 /*** {@inheritDoc} */
111 public ServletContext getServletContext() {
112
113 return this.context;
114
115 }
116
117
118 /*** {@inheritDoc} */
119 public String getServletName() {
120
121 return "MockServlet";
122
123 }
124
125
126 }