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