1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.cubby.unit;
17
18 import java.io.InputStream;
19 import java.net.MalformedURLException;
20 import java.net.URL;
21 import java.util.Enumeration;
22 import java.util.Hashtable;
23 import java.util.Set;
24
25 import javax.servlet.RequestDispatcher;
26 import javax.servlet.Servlet;
27 import javax.servlet.ServletContext;
28 import javax.servlet.ServletException;
29
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33
34
35
36
37
38 class MockServletContext implements ServletContext {
39
40 private static final Logger logger = LoggerFactory
41 .getLogger(MockServletContext.class);
42
43 private Hashtable<String, String> initParameters = new Hashtable<String, String>();
44
45 private Hashtable<String, Object> attributes = new Hashtable<String, Object>();
46
47
48
49
50 public String getContextPath() {
51 throw new UnsupportedOperationException();
52 }
53
54
55
56
57 public ServletContext getContext(String uripath) {
58 throw new UnsupportedOperationException();
59 }
60
61
62
63
64 public int getMajorVersion() {
65 return 2;
66 }
67
68
69
70
71 public int getMinorVersion() {
72 return 5;
73 }
74
75
76
77
78 public String getMimeType(String file) {
79 throw new UnsupportedOperationException();
80 }
81
82
83
84
85 @SuppressWarnings("unchecked")
86 public Set getResourcePaths(String path) {
87 throw new UnsupportedOperationException();
88 }
89
90
91
92
93 public URL getResource(String path) throws MalformedURLException {
94 throw new UnsupportedOperationException();
95 }
96
97
98
99
100 public InputStream getResourceAsStream(String path) {
101 throw new UnsupportedOperationException();
102 }
103
104
105
106
107 public RequestDispatcher getRequestDispatcher(String path) {
108 throw new UnsupportedOperationException();
109 }
110
111
112
113
114 public RequestDispatcher getNamedDispatcher(String name) {
115 throw new UnsupportedOperationException();
116 }
117
118
119
120
121 public Servlet getServlet(String name) throws ServletException {
122 throw new UnsupportedOperationException();
123 }
124
125
126
127
128 @SuppressWarnings("unchecked")
129 public Enumeration getServlets() {
130 throw new UnsupportedOperationException();
131 }
132
133
134
135
136 @SuppressWarnings("unchecked")
137 public Enumeration getServletNames() {
138 throw new UnsupportedOperationException();
139 }
140
141
142
143
144 public void log(String msg) {
145 logger.info(msg);
146 }
147
148
149
150
151 public void log(Exception exception, String msg) {
152 this.log(msg, exception);
153 }
154
155
156
157
158 public void log(String message, Throwable throwable) {
159 logger.info(message, throwable);
160 }
161
162
163
164
165 public String getRealPath(String path) {
166 throw new UnsupportedOperationException();
167 }
168
169
170
171
172 public String getServerInfo() {
173 throw new UnsupportedOperationException();
174 }
175
176
177
178
179 public String getInitParameter(String name) {
180 return initParameters.get(name);
181 }
182
183
184
185
186 @SuppressWarnings("unchecked")
187 public Enumeration getInitParameterNames() {
188 return initParameters.keys();
189 }
190
191
192
193
194 public Object getAttribute(String name) {
195 return attributes.get(name);
196 }
197
198
199
200
201 @SuppressWarnings("unchecked")
202 public Enumeration getAttributeNames() {
203 return attributes.keys();
204 }
205
206
207
208
209 public void setAttribute(String name, Object object) {
210 attributes.put(name, object);
211 }
212
213
214
215
216 public void removeAttribute(String name) {
217 attributes.remove(name);
218 }
219
220
221
222
223 public String getServletContextName() {
224 throw new UnsupportedOperationException();
225 }
226
227 }