Skip to content

Commit 65a3a0e

Browse files
committed
Expand SessionCookieConfig tests for new generic attribute support
See jakartaee/servlet#175
1 parent e3715f5 commit 65a3a0e

File tree

4 files changed

+74
-18
lines changed

4 files changed

+74
-18
lines changed

src/com/sun/ts/tests/servlet/api/jakarta_servlet_http/sessioncookieconfig/TestListener.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public void contextInitialized(ServletContextEvent sce) {
3535
Boolean isSecure = true;
3636
Boolean httpOnly = false;
3737
int maxage = 50000;
38+
String attrName = "a1";
39+
String attrValue= "b2";
3840
String name = "TCK_Cookie_Name";
3941

4042
SessionCookieConfig scf = sce.getServletContext().getSessionCookieConfig();
@@ -44,6 +46,7 @@ public void contextInitialized(ServletContextEvent sce) {
4446
scf.setMaxAge(maxage);
4547
scf.setPath(path);
4648
scf.setSecure(isSecure);
49+
scf.setAttribute(attrName, attrValue);
4750

4851
if (!scf.getPath().equals(path)) {
4952
testData.append("|getPathFAILED-expecting-" + path + "-got-" + scf.getPath());
@@ -57,14 +60,18 @@ public void contextInitialized(ServletContextEvent sce) {
5760
testData.append("|isHttpOnlyFAILED-expecting-" + httpOnly + "-got-" + scf.isHttpOnly());
5861
}
5962

60-
if (!scf.getDomain().equals(domain.toString())) {
63+
if (!scf.getDomain().equals(domain)) {
6164
testData.append("|getDomainFAILED-expecting-" + domain + "-got-" + scf.getDomain());
6265
}
6366

6467
if (scf.getMaxAge() != maxage) {
6568
testData.append("|getMaxAgeFAILED-expecting-" + maxage + "-got-" + scf.getMaxAge());
6669
}
6770

71+
if (!scf.getAttribute(attrName).equals(attrValue)) {
72+
testData.append("|getAttributeFAILED-expecting-" + attrValue + "-got-" + scf.getAttribute(attrName));
73+
}
74+
6875
if (scf.getName() != null) {
6976
testData.append("|getNameFAILED-expecting-null-got-" + scf.getName());
7077
}

src/com/sun/ts/tests/servlet/api/jakarta_servlet_http/sessioncookieconfig/TestServlet.java

+37-17
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
public class TestServlet extends HttpTCKServlet {
3434

3535
public void constructortest1(HttpServletRequest request,
36-
HttpServletResponse response) throws ServletException, IOException {
36+
HttpServletResponse response) throws IOException {
3737
request.getSession(true);
3838

3939
String results = (String) getServletContext().getAttribute(TestListener.class.getName());
@@ -46,9 +46,9 @@ public void constructortest1(HttpServletRequest request,
4646
}
4747

4848
public void setNameTest(HttpServletRequest request,
49-
HttpServletResponse response) throws ServletException, IOException {
49+
HttpServletResponse response) throws IOException {
5050
String name = "WHO_SHOULD_NOT_BE_NAMED_HERE";
51-
Boolean pass = true;
51+
boolean pass = true;
5252
PrintWriter pw = response.getWriter();
5353
HttpSession session = request.getSession();
5454

@@ -66,9 +66,9 @@ public void setNameTest(HttpServletRequest request,
6666
}
6767

6868
public void setCommentTest(HttpServletRequest request,
69-
HttpServletResponse response) throws ServletException, IOException {
69+
HttpServletResponse response) throws IOException {
7070
String comment = "WHO_SHOULD_NOT_BE_NAMED_HERE";
71-
Boolean pass = true;
71+
boolean pass = true;
7272
PrintWriter pw = response.getWriter();
7373
HttpSession session = request.getSession();
7474

@@ -86,9 +86,9 @@ public void setCommentTest(HttpServletRequest request,
8686
}
8787

8888
public void setPathTest(HttpServletRequest request,
89-
HttpServletResponse response) throws ServletException, IOException {
89+
HttpServletResponse response) throws IOException {
9090
String path = "WHO_SHOULD_NOT_BE_NAMED_HERE";
91-
Boolean pass = true;
91+
boolean pass = true;
9292
PrintWriter pw = response.getWriter();
9393
HttpSession session = request.getSession();
9494

@@ -106,9 +106,9 @@ public void setPathTest(HttpServletRequest request,
106106
}
107107

108108
public void setDomainTest(HttpServletRequest request,
109-
HttpServletResponse response) throws ServletException, IOException {
109+
HttpServletResponse response) throws IOException {
110110
String domain = "WHO_SHOULD_NOT_BE_NAMED_HERE";
111-
Boolean pass = true;
111+
boolean pass = true;
112112
PrintWriter pw = response.getWriter();
113113
HttpSession session = request.getSession();
114114

@@ -126,9 +126,9 @@ public void setDomainTest(HttpServletRequest request,
126126
}
127127

128128
public void setMaxAgeTest(HttpServletRequest request,
129-
HttpServletResponse response) throws ServletException, IOException {
129+
HttpServletResponse response) throws IOException {
130130
int maxage = 12345;
131-
Boolean pass = true;
131+
boolean pass = true;
132132
PrintWriter pw = response.getWriter();
133133
HttpSession session = request.getSession();
134134

@@ -146,9 +146,9 @@ public void setMaxAgeTest(HttpServletRequest request,
146146
}
147147

148148
public void setHttpOnlyTest(HttpServletRequest request,
149-
HttpServletResponse response) throws ServletException, IOException {
150-
Boolean http = true;
151-
Boolean pass = true;
149+
HttpServletResponse response) throws IOException {
150+
boolean http = true;
151+
boolean pass = true;
152152
PrintWriter pw = response.getWriter();
153153
HttpSession session = request.getSession();
154154

@@ -166,9 +166,9 @@ public void setHttpOnlyTest(HttpServletRequest request,
166166
}
167167

168168
public void setSecureTest(HttpServletRequest request,
169-
HttpServletResponse response) throws ServletException, IOException {
170-
Boolean secure = true;
171-
Boolean pass = true;
169+
HttpServletResponse response) throws IOException {
170+
boolean secure = true;
171+
boolean pass = true;
172172
PrintWriter pw = response.getWriter();
173173
HttpSession session = request.getSession();
174174

@@ -184,4 +184,24 @@ public void setSecureTest(HttpServletRequest request,
184184
ServletTestUtil.printResult(pw, pass);
185185
}
186186
}
187+
188+
public void setAttributeTest(HttpServletRequest request,
189+
HttpServletResponse response) throws IOException {
190+
String attribute = "WHO_SHOULD_NOT_BE_NAMED_HERE";
191+
boolean pass = true;
192+
PrintWriter pw = response.getWriter();
193+
HttpSession session = request.getSession();
194+
195+
try {
196+
pw.println("calling method setAttribute");
197+
getServletContext().getSessionCookieConfig().setAttribute(attribute, attribute);
198+
pass = false;
199+
pw.println("Expected IllegalStateException not thrown");
200+
} catch (IllegalStateException ex) {
201+
pw.println("Expected IllegalStateException thrown");
202+
} finally {
203+
session.invalidate();
204+
ServletTestUtil.printResult(pw, pass);
205+
}
206+
}
187207
}

src/com/sun/ts/tests/servlet/api/jakarta_servlet_http/sessioncookieconfig/URLClient.java

+14
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,18 @@ public void setSecureTest() throws Fault {
177177
TEST_PROPS.setProperty(APITEST, "setSecureTest");
178178
invoke();
179179
}
180+
181+
/*
182+
* @testName: setAttributeTest
183+
*
184+
* @assertion_ids:
185+
*
186+
* @test_Strategy: Create a Servlet TestServlet, In the Servlet, turn
187+
* HttpSession on; Verify in servlet SessionCookieConfig.setAttribute cannot be
188+
* called once is set.
189+
*/
190+
public void setAttributeTest() throws Fault {
191+
TEST_PROPS.setProperty(APITEST, "setAttributeTest");
192+
invoke();
193+
}
180194
}

src/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/sessioncookieconfig/URLClient.java

+15
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.PrintWriter;
2323

2424
import com.sun.javatest.Status;
25+
import com.sun.ts.lib.harness.EETest.Fault;
2526
import com.sun.ts.tests.servlet.common.client.AbstractUrlClient;
2627

2728
public class URLClient extends AbstractUrlClient {
@@ -177,4 +178,18 @@ public void setSecureTest() throws Fault {
177178
TEST_PROPS.setProperty(APITEST, "setSecureTest");
178179
invoke();
179180
}
181+
182+
/*
183+
* @testName: setAttributeTest
184+
*
185+
* @assertion_ids:
186+
*
187+
* @test_Strategy: Create a Servlet TestServlet, In the Servlet, turn
188+
* HttpSession on; Verify in servlet SessionCookieConfig.setAttribute cannot be
189+
* called once is set.
190+
*/
191+
public void setAttributeTest() throws Fault {
192+
TEST_PROPS.setProperty(APITEST, "setAttributeTest");
193+
invoke();
194+
}
180195
}

0 commit comments

Comments
 (0)