1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
/*******************************************************************************
* Copyright (c) 2008, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.ua.tests.help.webapp;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
/**
* Class used for tests which require an HttpServletRequest parameter
*/
public class MockServletResponse implements HttpServletResponse {
private List<Cookie> cookies = new ArrayList<Cookie>();
private String illegalCharactersFound = "";
@Override
public String getCharacterEncoding() {
return null;
}
@Override
public String getContentType() {
return null;
}
@Override
public ServletOutputStream getOutputStream() throws IOException {
return null;
}
@Override
public PrintWriter getWriter() throws IOException {
return null;
}
@Override
public void setCharacterEncoding(String charset) {
}
@Override
public void setContentLength(int len) {
}
@Override
public void setContentType(String type) {
}
@Override
public void setBufferSize(int size) {
}
@Override
public int getBufferSize() {
return 0;
}
@Override
public void flushBuffer() throws IOException {
}
@Override
public void resetBuffer() {
}
@Override
public boolean isCommitted() {
return false;
}
@Override
public void reset() {
}
@Override
public void setLocale(Locale loc) {
}
@Override
public Locale getLocale() {
return null;
}
@Override
public void addCookie(Cookie cookie) {
checkForIllegalCharacters(cookie.getValue());
// Replace if it already exists, otherwise set
for (int i = 0; i < cookies.size(); i++) {
Cookie nextCookie = cookies.get(i);
if (nextCookie.getName().equals(cookie.getName())) {
cookies.remove(i);
cookies.add(cookie);
return;
}
}
cookies.add(cookie);
}
private void checkForIllegalCharacters(String value) {
// Check for illegal characters
final String illegalChars = "()<>@,;:\\\"/[]?={} \t";
for (int i = 0; i < illegalChars.length(); i++) {
char ch = illegalChars.charAt(i);
if (value.indexOf(ch) >= 0 && illegalCharactersFound.indexOf(ch) < 0) {
illegalCharactersFound = illegalCharactersFound + ch;
}
}
}
public Cookie[] getCookies() {
return cookies.toArray(new Cookie[cookies.size()]);
}
@Override
public boolean containsHeader(String name) {
// TODO Auto-generated method stub
return false;
}
@Override
public String encodeURL(String url) {
// TODO Auto-generated method stub
return null;
}
@Override
public String encodeRedirectURL(String url) {
// TODO Auto-generated method stub
return null;
}
@Override
public String encodeUrl(String url) {
// TODO Auto-generated method stub
return null;
}
@Override
public String encodeRedirectUrl(String url) {
// TODO Auto-generated method stub
return null;
}
@Override
public void sendError(int sc, String msg) throws IOException {
// TODO Auto-generated method stub
}
@Override
public void sendError(int sc) throws IOException {
// TODO Auto-generated method stub
}
@Override
public void sendRedirect(String location) throws IOException {
// TODO Auto-generated method stub
}
@Override
public void setDateHeader(String name, long date) {
// TODO Auto-generated method stub
}
@Override
public void addDateHeader(String name, long date) {
// TODO Auto-generated method stub
}
@Override
public void setHeader(String name, String value) {
// TODO Auto-generated method stub
}
@Override
public void addHeader(String name, String value) {
// TODO Auto-generated method stub
}
@Override
public void setIntHeader(String name, int value) {
// TODO Auto-generated method stub
}
@Override
public void addIntHeader(String name, int value) {
// TODO Auto-generated method stub
}
@Override
public void setStatus(int sc) {
// TODO Auto-generated method stub
}
@Override
public void setStatus(int sc, String sm) {
// TODO Auto-generated method stub
}
public String getIllegalCharatersFound() {
return illegalCharactersFound;
}
@Override
public int getStatus() {
// TODO Auto-generated method stub
return 0;
}
@Override
public String getHeader(String name) {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<String> getHeaders(String name) {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<String> getHeaderNames() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setContentLengthLong(long len) {
// TODO Auto-generated method stub
}
}
|