-
Notifications
You must be signed in to change notification settings - Fork 78
/
GenericServletTests.java
253 lines (232 loc) · 7.38 KB
/
GenericServletTests.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
/*
* 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.api.jakarta_servlet.genericservlet;
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 GenericServletTests 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_js_genericservlet_web.war")
.addAsLibraries(CommonServlets.getCommonServletsArchive())
.addClasses(DestroyTestServlet.class, Init_ServletConfigServletExceptionTestServlet.class,
Init_ServletConfigTestServlet.class, InitServletExceptionTestServlet.class,
InitTestServlet.class, ServiceTestServlet.class, ServletErrorPage.class, TestServlet.class)
.setWebXML(GenericServletTests.class.getResource("servlet_js_genericservlet_web.xml"));
}
/*
* @class.setup_props: webServerHost; webServerPort; ts_home;
*
*/
/* Run test */
/*
* @testName: destroyTest
*
* @assertion_ids: Servlet:JAVADOC:119
*
* @test_Strategy: Create a GenericServlet and take out of service using
* destroy method
*
*/
@Test
public void destroyTest() throws Exception {
String testName = "destroyTest";
TEST_PROPS.setProperty(TEST_NAME, testName);
TEST_PROPS.setProperty(REQUEST,
"GET " + getContextRoot() + "/" + testName + " HTTP/1.1");
TEST_PROPS.setProperty(IGNORE_BODY, "true");
invoke();
TEST_PROPS.setProperty(REQUEST,
"GET " + getContextRoot() + "/" + testName + " HTTP/1.1");
TEST_PROPS.setProperty(IGNORE_BODY, "true");
invoke();
}
/*
* @testName: getServletConfigTest
*
* @assertion_ids: Servlet:JAVADOC:124
*
* @test_Strategy: Create a GenericServlet and check for its ServletConfig
* object existence
*
*/
@Test
public void getServletConfigTest() throws Exception {
TEST_PROPS.setProperty(APITEST, "getServletConfigTest");
invoke();
}
/*
* @testName: getServletContextTest
*
* @assertion_ids: Servlet:JAVADOC:125
*
* @test_Strategy: Create a GenericServlet and check for its ServletContext
* object existence
*
*/
@Test
public void getServletContextTest() throws Exception {
TEST_PROPS.setProperty(APITEST, "getServletContextTest");
invoke();
}
/*
* @testName: getServletInfoTest
*
* @assertion_ids: Servlet:JAVADOC:126
*
* @test_Strategy: Create a GenericServlet and check for its ServletInfo
* object values
*
*/
@Test
public void getServletInfoTest() throws Exception {
TEST_PROPS.setProperty(APITEST, "getServletInfoTest");
invoke();
}
/*
* @testName: getInitParameterTest
*
* @assertion_ids: Servlet:JAVADOC:120
*
* @test_Strategy: Servlet tries to access a parameter that exists
*/
@Test
public void getInitParameterTest() throws Exception {
TEST_PROPS.setProperty(APITEST, "getInitParameterTest");
invoke();
}
/*
* @testName: getInitParameterNamesTest
*
* @assertion_ids: Servlet:JAVADOC:122
*
* @test_Strategy: Servlet tries to get all parameter names
*/
@Test
public void getInitParameterNamesTest() throws Exception {
TEST_PROPS.setProperty(APITEST, "getInitParameterNamesTest");
invoke();
}
/*
* @testName: getServletNameTest
*
* @assertion_ids: Servlet:JAVADOC:136
*
* @test_Strategy: Servlet gets name of servlet
*/
@Test
public void getServletNameTest() throws Exception {
TEST_PROPS.setProperty(APITEST, "getServletNameTest");
invoke();
}
/*
* @testName: initServletExceptionTest
*
* @assertion_ids: Servlet:JAVADOC:130
*
* @test_Strategy: Servlet throws a ServletException
*/
@Test
public void initServletExceptionTest() throws Exception {
String testName = "initServletExceptionTest";
TEST_PROPS.setProperty(TEST_NAME, testName);
TEST_PROPS.setProperty(STATUS_CODE, INTERNAL_SERVER_ERROR);
TEST_PROPS.setProperty(REQUEST,
"GET " + getContextRoot() + "/" + testName + " HTTP/1.1");
TEST_PROPS.setProperty(SEARCH_STRING,
"Status Code: 500|Exception: jakarta.servlet.ServletException: in init of InitServletExceptionTestServlet");
invoke();
}
/*
* @testName: initTest
*
* @assertion_ids: Servlet:JAVADOC:129
*
* @test_Strategy: Servlet has init method that puts a value into the context.
* Servlet when called reads value from context
*/
@Test
public void initTest() throws Exception {
String testName = "initTest";
TEST_PROPS.setProperty(TEST_NAME, testName);
TEST_PROPS.setProperty(REQUEST,
"GET " + getContextRoot() + "/" + testName + " HTTP/1.1");
invoke();
}
/*
* @testName: init_ServletConfigServletExceptionTest
*
* @assertion_ids: Servlet:JAVADOC:128
*
* @test_Strategy: Servlet throws a ServletException
*/
@Test
public void init_ServletConfigServletExceptionTest() throws Exception {
String testName = "init_ServletConfigServletExceptionTest";
TEST_PROPS.setProperty(TEST_NAME, testName);
TEST_PROPS.setProperty(STATUS_CODE, INTERNAL_SERVER_ERROR);
TEST_PROPS.setProperty(REQUEST,
"GET " + getContextRoot() + "/" + testName + " HTTP/1.1");
TEST_PROPS.setProperty(SEARCH_STRING,
"Status Code: 500|Exception: jakarta.servlet.ServletException: in init of Init_ServletConfigServletExceptionTestServlet");
invoke();
}
/*
* @testName: init_ServletConfigTest
*
* @assertion_ids: Servlet:JAVADOC:127
*
* @test_Strategy: Servlet has init method that puts a value into the context.
* Servlet when called reads value from context
*/
@Test
public void init_ServletConfigTest() throws Exception {
String testName = "init_ServletConfigTest";
TEST_PROPS.setProperty(TEST_NAME, testName);
TEST_PROPS.setProperty(REQUEST,
"GET " + getContextRoot() + "/" + testName + " HTTP/1.1");
invoke();
}
/*
* @testName: serviceTest
*
* @assertion_ids: Servlet:JAVADOC:133
*
* @test_Strategy: Servlet which has a service method that is called
*/
@Test
public void serviceTest() throws Exception {
String testName = "serviceTest";
TEST_PROPS.setProperty(TEST_NAME, testName);
TEST_PROPS.setProperty(REQUEST,
"GET " + getContextRoot() + "/" + testName + " HTTP/1.1");
invoke();
}
}