-
Notifications
You must be signed in to change notification settings - Fork 78
/
RequestDispatcherTests.java
497 lines (464 loc) · 19.9 KB
/
RequestDispatcherTests.java
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
/*
* Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
/*
* $Id$
*/
package servlet.tck.spec.requestdispatcher;
import servlet.tck.common.client.AbstractUrlClient;
import servlet.tck.common.servlets.CommonServlets;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class RequestDispatcherTests extends AbstractUrlClient {
@BeforeEach
public void setupServletName() throws Exception {
setServletName("TestServlet");
}
/**
* Deployment for the test
*/
@Deployment(testable = false)
public static WebArchive getTestArchive() throws Exception {
return ShrinkWrap.create(WebArchive.class, "servlet_spec_requestdispatcher_web.war")
.addAsLibraries(CommonServlets.getCommonServletsArchive())
.addClasses(ForwardedServlet.class, HttpTestServlet.class, IncludedServlet.class,
MultiForwardedServlet.class, TestServlet.class, WrapServlet.class)
.setWebXML(RequestDispatcherTests.class.getResource("servlet_spec_requestdispatcher_web.xml"));
}
/*
* @class.setup_props: webServerHost; webServerPort; ts_home;
*/
/*
* @testName: getRequestAttributes
*
* @assertion_ids: Servlet:SPEC:76.1; Servlet:SPEC:76.2; Servlet:SPEC:76.3;
* Servlet:SPEC:76.4; Servlet:SPEC:76.5;
*
* @test_Strategy: 1. Create servlets TestServlet and IncludedServlet; 2. In
* TestServlet, get RequestDispatcher by using
* ServletContext.getRequestDispatcher(String), and access IncludedServlet
* using RequestDispatcher.include. 3. Verify in IncludedServlet the following
* request attributes set correctly required by Servlet 2.4 Spec:
* jakarta.servlet.include.request_uri; jakarta.servlet.include.context_path;
* jakarta.servlet.include.servlet_path; jakarta.servlet.include.path_info;
* jakarta.servlet.include.query_string;
*/
@Test
public void getRequestAttributes() throws Exception {
TEST_PROPS.setProperty(SEARCH_STRING,
"jakarta.servlet.include.request_uri=SET_GOOD;jakarta.servlet.include.context_path=SET_GOOD;jakarta.servlet.include.servlet_path=SET_GOOD;jakarta.servlet.include.path_info=SET_NO;jakarta.servlet.include.query_string=SET_GOOD;");
TEST_PROPS.setProperty(APITEST, "includeAttributes");
invoke();
}
/*
* @testName: getRequestAttributes1
*
* @assertion_ids: Servlet:SPEC:76.1; Servlet:SPEC:76.2; Servlet:SPEC:76.3;
* Servlet:SPEC:76.4; Servlet:SPEC:76.5;
*
* @test_Strategy: 1. Create servlets TestServlet and IncludedServlet; 2. In
* TestServlet, get RequestDispatcher by using
* ServletRequest.getRequestDispatcher(String), and access IncludedServlet
* using RequestDispatcher.include. 3. Verify in IncludedServlet the following
* request attributes set correctly required by Servlet 2.4 Spec:
* jakarta.servlet.include.request_uri; jakarta.servlet.include.context_path;
* jakarta.servlet.include.servlet_path; jakarta.servlet.include.path_info;
* jakarta.servlet.include.query_string;
*/
@Test
public void getRequestAttributes1() throws Exception {
TEST_PROPS.setProperty(SEARCH_STRING,
"jakarta.servlet.include.request_uri=SET_GOOD;jakarta.servlet.include.context_path=SET_GOOD;jakarta.servlet.include.servlet_path=SET_GOOD;jakarta.servlet.include.path_info=SET_NO;jakarta.servlet.include.query_string=SET_GOOD;");
TEST_PROPS.setProperty(APITEST, "includeAttributes1");
invoke();
}
/*
* @testName: getRequestAttributes2
*
* @assertion_ids: Servlet:SPEC:76.1; Servlet:SPEC:76.2; Servlet:SPEC:76.3;
* Servlet:SPEC:76.4; Servlet:SPEC:76.5;
*
* @test_Strategy: 1. Create servlets TestServlet and IncludedServlet; 2. In
* TestServlet, get RequestDispatcher by using
* ServletContext.getNamedDispatcher(String), and access IncludedServlet using
* RequestDispatcher.include. 3. Verify in IncludedServlet the following
* request attributes not set required by Servlet 2.4 Spec:
* jakarta.servlet.include.request_uri; jakarta.servlet.include.context_path;
* jakarta.servlet.include.servlet_path; jakarta.servlet.include.path_info;
* jakarta.servlet.include.query_string;
*/
@Test
public void getRequestAttributes2() throws Exception {
TEST_PROPS.setProperty(SEARCH_STRING,
"jakarta.servlet.include.request_uri=SET_NO;jakarta.servlet.include.context_path=SET_NO;jakarta.servlet.include.servlet_path=SET_NO;jakarta.servlet.include.path_info=SET_NO;jakarta.servlet.include.query_string=SET_NO;");
TEST_PROPS.setProperty(APITEST, "includeAttributes2");
invoke();
}
/*
* @testName: requestDispatcherIncludeIOAndServletExceptionTest
*
* @assertion_ids: Servlet:SPEC:82; Servlet:JAVADOC:279; Servlet:JAVADOC:280;
*
* @test_Strategy: Validate an exception thrown during a
* RequestDispatcher.include() operation results in an IOException or
* ServletException being thrown, the Servlet or IOException will be
* propagated back to the caller and will not be wrapped by a
* ServletException.
*/
@Test
public void requestDispatcherIncludeIOAndServletExceptionTest() throws Exception {
TEST_PROPS.setProperty(REQUEST,
"GET /servlet_spec_requestdispatcher_web/TestServlet?testname=includeIOAndServletException HTTP/1.1");
TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED|Test PASSED");
TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED");
invoke();
}
/*
* @testName: requestDispatcherIncludeRuntimeExceptionTest
*
* @assertion_ids: Servlet:SPEC:82
*
* @test_Strategy: Validate a RuntimeException thrown during a
* RequestDispacher.include() operation results in the RuntimeException being
* propagated back to the caller and will not be wrapped by a
* ServletException.
*/
@Test
public void requestDispatcherIncludeRuntimeExceptionTest() throws Exception {
TEST_PROPS.setProperty(REQUEST,
"GET /servlet_spec_requestdispatcher_web/TestServlet?testname=includeUnCheckedException HTTP/1.1");
TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED");
TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED");
invoke();
}
/*
* @testName: requestDispatcherIncludeCheckedExceptionTest
*
* @assertion_ids: Servlet:SPEC:82
*
* @test_Strategy: Validate a checked exception that is thrown during a
* RequetDispatcher.include() operation and is not an instance of
* ServletException or IOException is returned to the caller wrapped by
* ServletException.
*/
@Test
public void requestDispatcherIncludeCheckedExceptionTest() throws Exception {
TEST_PROPS.setProperty(REQUEST,
"GET /servlet_spec_requestdispatcher_web/TestServlet?testname=includeCheckedException HTTP/1.1");
TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED");
TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED");
invoke();
}
/*
* @testName: requestDispatcherForwardIOAndServletExceptionTest
*
* @assertion_ids: Servlet:SPEC:82; Servlet:JAVADOC:275; Servlet:JAVADOC:276;
*
* @test_Strategy: Validate an exception thrown during a
* RequestDispatcher.forward() operation results in an IOException or
* ServletException being thrown, the Servlet or IOException will be
* propagated back to the caller and will not be wrapped by a
* ServletException.
*/
@Test
public void requestDispatcherForwardIOAndServletExceptionTest() throws Exception {
TEST_PROPS.setProperty(REQUEST,
"GET /servlet_spec_requestdispatcher_web/TestServlet?testname=forwardIOAndServletException HTTP/1.1");
TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED|Test PASSED");
TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED");
invoke();
}
/*
* @testName: requestDispatcherForwardRuntimeExceptionTest
*
* @assertion_ids: Servlet:SPEC:82
*
* @test_Strategy: Validate a RuntimeException thrown during a
* RequestDispacher.forward() operation results in the RuntimeException being
* propagated back to the caller and will not be wrapped by a
* ServletException.
*/
@Test
public void requestDispatcherForwardRuntimeExceptionTest() throws Exception {
TEST_PROPS.setProperty(REQUEST,
"GET /servlet_spec_requestdispatcher_web/TestServlet?testname=forwardUnCheckedException HTTP/1.1");
TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED");
TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED");
invoke();
}
/*
* @testName: requestDispatcherForwardCheckedExceptionTest
*
* @assertion_ids: Servlet:SPEC:82
*
* @test_Strategy: Validate a checked exception that is thrown during a
* RequetDispatcher.forward() operation and is not an instance of
* ServletException or IOException is returned to the caller wrapped by
* ServletException.
*/
@Test
public void requestDispatcherForwardCheckedExceptionTest() throws Exception {
TEST_PROPS.setProperty(REQUEST,
"GET /servlet_spec_requestdispatcher_web/TestServlet?testname=forwardCheckedException HTTP/1.1");
TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED");
TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED");
invoke();
}
/*
* @testName: getRequestAttributes3
*
* @assertion_ids: Servlet:SPEC:180.1; Servlet:SPEC:180.2; Servlet:SPEC:180.3;
* Servlet:SPEC:180.4; Servlet:SPEC:180.5;
*
* @test_Strategy: 1. Create servlets TestServlet and ForwardedServlet; 2. In
* TestServlet, get RequestDispatcher by using
* ServletContext.getRequestDispatcher(String), and access ForwardedServlet
* using RequestDispatcher.forward. 3. Verify in ForwardedServlet the
* following request attributes set correctly required by Servlet 2.4 Spec:
* jakarta.servlet.forward.request_uri; jakarta.servlet.forward.context_path;
* jakarta.servlet.forward.servlet_path; jakarta.servlet.forward.path_info;
* jakarta.servlet.forward.query_string;
*/
@Test
public void getRequestAttributes3() throws Exception {
TEST_PROPS.setProperty(SEARCH_STRING,
"jakarta.servlet.forward.request_uri=SET_GOOD;"
+ "jakarta.servlet.forward.context_path=SET_GOOD;"
+ "jakarta.servlet.forward.servlet_path=SET_GOOD;"
+ "jakarta.servlet.forward.path_info=SET_NO;"
+ "jakarta.servlet.forward.query_string=SET_GOOD;");
TEST_PROPS.setProperty(APITEST, "forwardAttributes");
invoke();
}
/*
* @testName: getRequestAttributes4
*
* @assertion_ids: Servlet:SPEC:180.1; Servlet:SPEC:180.2; Servlet:SPEC:180.3;
* Servlet:SPEC:180.4; Servlet:SPEC:180.5;
*
* @test_Strategy: 1. Create servlets TestServlet and ForwardedServlet; 2. In
* TestServlet, get RequestDispatcher by using
* ServletRequest.getRequestDispatcher(String), and access ForwardedServlet
* using RequestDispatcher.forward. 3. Verify in ForwardedServlet the
* following request attributes set correctly required by Servlet 2.4 Spec:
* jakarta.servlet.forward.request_uri; jakarta.servlet.forward.context_path;
* jakarta.servlet.forward.servlet_path; jakarta.servlet.forward.path_info;
* jakarta.servlet.forward.query_string;
*/
@Test
public void getRequestAttributes4() throws Exception {
TEST_PROPS.setProperty(SEARCH_STRING,
"jakarta.servlet.forward.request_uri=SET_GOOD;"
+ "jakarta.servlet.forward.context_path=SET_GOOD;"
+ "jakarta.servlet.forward.servlet_path=SET_GOOD;"
+ "jakarta.servlet.forward.path_info=SET_NO;"
+ "jakarta.servlet.forward.query_string=SET_GOOD;");
TEST_PROPS.setProperty(APITEST, "forwardAttributes1");
invoke();
}
/*
* @testName: getRequestAttributes5
*
* @assertion_ids: Servlet:SPEC:181.1; Servlet:SPEC:181.2; Servlet:SPEC:181.3;
* Servlet:SPEC:181.4; Servlet:SPEC:181.5;
*
* @test_Strategy: 1. Create servlets TestServlet and ForwardedServlet; 2. In
* TestServlet, get RequestDispatcher by using
* ServletContext.getNamedDispatcher(String), and access ForwardedServlet
* using RequestDispatcher.forward. 3. Verify in ForwardedServlet the
* following request attributes are not set required by Servlet 2.4 Spec:
* jakarta.servlet.forward.request_uri; jakarta.servlet.forward.context_path;
* jakarta.servlet.forward.servlet_path; jakarta.servlet.forward.path_info;
* jakarta.servlet.forward.query_string;
*/
@Test
public void getRequestAttributes5() throws Exception {
TEST_PROPS.setProperty(SEARCH_STRING,
"jakarta.servlet.forward.request_uri=SET_NO;"
+ "jakarta.servlet.forward.context_path=SET_NO;"
+ "jakarta.servlet.forward.servlet_path=SET_NO;"
+ "jakarta.servlet.forward.path_info=SET_NO;"
+ "jakarta.servlet.forward.query_string=SET_NO;");
TEST_PROPS.setProperty(APITEST, "forwardAttributes2");
invoke();
}
/*
* @testName: getRequestAttributes6
*
* @assertion_ids: Servlet:SPEC:181.1; Servlet:SPEC:181.2; Servlet:SPEC:181.3;
* Servlet:SPEC:181.4; Servlet:SPEC:181.5;
*
* @test_Strategy: 1. Create servlets TestServlet, ForwardedServlet and
* MultiForwardedServlet; 2. In TestServlet, get RequestDispatcher by using
* ServletContext.getRequestDispatcher(String), and access
* MultiForwardedServlet using RequestDispatcher.forward. 3. In
* MultiForwardedServlet, get RequestDispatcher by using
* ServletContext.getRequestDispatcher(String), and access ForwardedServlet
* using RequestDispatcher.forward. 4. Verify in ForwardedServlet the
* following request attributes are set required by Servlet 2.4 Spec:
* jakarta.servlet.forward.request_uri; jakarta.servlet.forward.context_path;
* jakarta.servlet.forward.servlet_path; jakarta.servlet.forward.path_info;
* jakarta.servlet.forward.query_string;
*/
@Test
public void getRequestAttributes6() throws Exception {
TEST_PROPS.setProperty(SEARCH_STRING,
"jakarta.servlet.forward.request_uri=SET_GOOD;"
+ "jakarta.servlet.forward.context_path=SET_GOOD;"
+ "jakarta.servlet.forward.servlet_path=SET_GOOD;"
+ "jakarta.servlet.forward.path_info=SET_NO;"
+ "jakarta.servlet.forward.query_string=SET_GOOD;");
TEST_PROPS.setProperty(APITEST, "forwardAttributes6");
invoke();
}
/*
* @testName: bufferContent
*
* @assertion_ids: Servlet:SPEC:77;
*
* @test_Strategy: 1. Create servlets TestServlet and ForwardedServlet; 2. In
* TestServlet, first write "Test FAILED" to ServletResponse; then access
* ForwardedServlet using RequestDispatcher.forward. 3. Verify that the
* message "Test FAILED" wrote to ServletResponse is cleared and not sent to
* Client as required by Servlet 2.4 Spec.
*/
@Test
public void bufferContent() throws Exception {
TEST_PROPS.setProperty(SEARCH_STRING,
"bufferContent_in_ForwardedServlet_invoked");
TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED");
TEST_PROPS.setProperty(APITEST, "bufferContent");
invoke();
}
/*
* @testName: requestDispatcherNoWrappingTest
*
* @assertion_ids: Servlet:SPEC:50;
*
* @test_Strategy: Validate the container passes the same objects from a
* RequestDispatcher operation to the target entity. The container should not
* wrap the object at any point.
*/
@Test
public void requestDispatcherNoWrappingTest() throws Exception {
TEST_PROPS.setProperty(REQUEST,
"GET /servlet_spec_requestdispatcher_web/TestServlet?testname=rdNoWrappingTest&operation=0 HTTP/1.1");
TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED");
TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED");
invoke();
TEST_PROPS.setProperty(REQUEST,
"GET /servlet_spec_requestdispatcher_web/TestServlet?testname=rdNoWrappingTest&operation=1 HTTP/1.1");
TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED");
TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED");
invoke();
}
/*
* @testName: getRequestURIIncludeTest
*
* @assertion_ids: Servlet:SPEC:76; Servlet:JAVADOC:561;
*
* @test_Strategy: 1. Create servlets TestServlet and HttpTestServlet; 2. In
* TestServlet;, access HttpTestServlet using RequestDispatcher.include. 3.
* Verify in HttpTestServlet, that getRequestURI returns correct URI according
* to 8.3
*/
@Test
public void getRequestURIIncludeTest() throws Exception {
TEST_PROPS.setProperty(APITEST, "getRequestURIIncludeTest");
invoke();
}
/*
* @testName: getRequestURLIncludeTest
*
* @assertion_ids: Servlet:SPEC:76; Servlet:JAVADOC:562;
*
* @test_Strategy: 1. Create servlets TestServlet and HttpTestServlet; 2. In
* TestServlet;, access HttpTestServlet using RequestDispatcher.include. 3.
* Verify in HttpTestServlet, that getRequestURL returns correct URI according
* to 8.3
*/
@Test
public void getRequestURLIncludeTest() throws Exception {
TEST_PROPS.setProperty(APITEST, "getRequestURLIncludeTest");
invoke();
}
/*
* @testName: getRequestURIForwardTest
*
* @assertion_ids: Servlet:SPEC:78;; Servlet:JAVADOC:561;
*
* @test_Strategy: 1. Create servlets TestServlet and HttpTestServlet; 2. In
* TestServlet;, access HttpTestServlet using RequestDispatcher.forward. 3.
* Verify in HttpTestServlet, that getRequestURI returns correct URI according
* to 8.4
*/
@Test
public void getRequestURIForwardTest() throws Exception {
TEST_PROPS.setProperty(APITEST, "getRequestURIForwardTest");
invoke();
}
/*
* @testName: getRequestURLForwardTest
*
* @assertion_ids: Servlet:SPEC:78; Servlet:JAVADOC:562;
*
* @test_Strategy: 1. Create servlets TestServlet and HttpTestServlet; 2. In
* TestServlet;, access HttpTestServlet using RequestDispatcher.forward. 3.
* Verify in HttpTestServlet, that getRequestURL returns correct URL according
* to 8.4
*/
@Test
public void getRequestURLForwardTest() throws Exception {
TEST_PROPS.setProperty(APITEST, "getRequestURLForwardTest");
invoke();
}
/*
* @testName: getQueryStringIncludeTest
*
* @assertion_ids: Servlet:SPEC:192; Servlet:JAVADOC:552;
*
* @test_Strategy: 1. Create servlets TestServlet and HttpTestServlet; 2. Send
* request to TestServlet with ?testname=getQueryStringIncludeTest; 3. In
* TestServlet, access HttpTestServlet using RequestDispatcher.include, with
* ?testname=getQueryStringTestInclude; 4. Verify in HttpTestServlet, that
* getQueryString returns correct QueryString
* testname=getQueryStringIncludeTest according to 8.3
*/
@Test
public void getQueryStringIncludeTest() throws Exception {
TEST_PROPS.setProperty(APITEST, "getQueryStringIncludeTest");
invoke();
}
/*
* @testName: getQueryStringForwardTest
*
* @assertion_ids: Servlet:SPEC:78; Servlet:JAVADOC:552;
*
* @test_Strategy: 1. Create servlets TestServlet and HttpTestServlet; 2. Send
* request to TestServlet with ?testname=getQueryStringForwardTest; 3. In
* TestServlet, access HttpTestServlet using RequestDispatcher.forward, with
* ?testname=getQueryStringTestForward; 4. Verify in HttpTestServlet, that
* getQueryString returns correct QueryString
* testname=getQueryStringTestForward according to 8.4.2
*/
@Test
public void getQueryStringForwardTest() throws Exception {
TEST_PROPS.setProperty(APITEST, "getQueryStringForwardTest");
invoke();
}
}