Skip to content

Commit 52a4e7b

Browse files
committed
Expand Cookie tests for new generic attribute support
See jakartaee/servlet#175
1 parent d6ee0d2 commit 52a4e7b

File tree

3 files changed

+116
-1
lines changed

3 files changed

+116
-1
lines changed

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

+65-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* *
44
* * The Apache Software License, Version 1.1
55
* *
6-
* * Copyright (c) 2001, 2020 Oracle and/or its affiliates and others.
6+
* * Copyright (c) 2001, 2021 Oracle and/or its affiliates and others.
77
* * All rights reserved.
88
* * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
99
* * reserved.
@@ -63,8 +63,11 @@
6363
import java.io.PrintWriter;
6464
import java.text.SimpleDateFormat;
6565
import java.util.Date;
66+
import java.util.Map;
6667
import java.util.TimeZone;
6768

69+
import javax.management.AttributeValueExp;
70+
6871
import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet;
6972
import com.sun.ts.tests.servlet.common.util.ServletTestUtil;
7073

@@ -672,4 +675,65 @@ public void setVersionVer1Test(HttpServletRequest request,
672675
}
673676
ServletTestUtil.printResult(pw, passed);
674677
}
678+
679+
public void setAttributeTest(HttpServletRequest request,
680+
HttpServletResponse response) throws IOException {
681+
682+
PrintWriter pw = response.getWriter();
683+
boolean passed = true;
684+
Cookie testCookie = new Cookie("name1", "value1");
685+
686+
String attrName = "some-name";
687+
String attrValue = "some-value";
688+
testCookie.setAttribute(attrName, attrValue);
689+
String result = testCookie.getAttribute(attrName);
690+
691+
response.addCookie(testCookie);
692+
if (result != null) {
693+
if (!result.equalsIgnoreCase(attrValue)) {
694+
passed = false;
695+
pw.println("setAttribute(" + attrName + "," + attrValue +
696+
") did not set the attribute properly ");
697+
pw.println("Expected value = " + attrValue + " ");
698+
pw.println("Actual value = |" + result + "| ");
699+
}
700+
} else {
701+
passed = false;
702+
pw.println("getAttribute(" + attrName + ") returned a null result ");
703+
}
704+
ServletTestUtil.printResult(pw, passed);
705+
}
706+
707+
public void getAttributesTest(HttpServletRequest request,
708+
HttpServletResponse response) throws IOException {
709+
710+
PrintWriter pw = response.getWriter();
711+
boolean passed = true;
712+
String name = "name1";
713+
String value = "value1";
714+
Cookie testCookie = new Cookie(name, value);
715+
716+
String attrName = "some-name";
717+
String attrValue = "some-value";
718+
testCookie.setAttribute(attrName, attrValue);
719+
Map<String,String> result = testCookie.getAttributes();
720+
721+
response.addCookie(testCookie);
722+
if (result != null) {
723+
if (result.size() == 1) {
724+
if (!result.get(attrName).equals(attrValue)) {
725+
passed = false;
726+
pw.println("getAttributes() returned a map that contained [" + result.get(attrName) +
727+
"] as the value for key [" + attrName + "] rather than [" + attrValue + "]");
728+
}
729+
} else {
730+
passed = false;
731+
pw.println("getAttributes() returned a map of size [" + result.size() + "] rather than 1.");
732+
}
733+
} else {
734+
passed = false;
735+
pw.println("getAttributes() returned a null result ");
736+
}
737+
ServletTestUtil.printResult(pw, passed);
738+
}
675739
}

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

+24
Original file line numberDiff line numberDiff line change
@@ -438,4 +438,28 @@ public void setVersionTest() throws Fault {
438438
TEST_PROPS.setProperty(APITEST, "setVersionVer1Test");
439439
invoke();
440440
}
441+
442+
/*
443+
* @testName: setAttributeTest
444+
*
445+
* @assertion_ids:
446+
*
447+
* @test_Strategy: Servlet tests method and returns result to client
448+
*/
449+
public void setAttributeTest() throws Fault {
450+
TEST_PROPS.setProperty(APITEST, "setAttributeTest");
451+
invoke();
452+
}
453+
454+
/*
455+
* @testName: getAttributesTest
456+
*
457+
* @assertion_ids:
458+
*
459+
* @test_Strategy: Servlet tests method and returns result to client
460+
*/
461+
public void getAttributesTest() throws Fault {
462+
TEST_PROPS.setProperty(APITEST, "getAttributesTest");
463+
invoke();
464+
}
441465
}

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

+27
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.commons.httpclient.cookie.CookieSpec;
3232

3333
import com.sun.javatest.Status;
34+
import com.sun.ts.lib.harness.EETest.Fault;
3435
import com.sun.ts.lib.util.TestUtil;
3536
import com.sun.ts.tests.common.webclient.http.HttpRequest;
3637
import com.sun.ts.tests.common.webclient.http.HttpResponse;
@@ -477,4 +478,30 @@ public void setVersionTest() throws Fault {
477478
TEST_PROPS.setProperty(APITEST, "setVersionVer1Test");
478479
invoke();
479480
}
481+
482+
/*
483+
* @testName: setAttributeTest
484+
*
485+
* @assertion_ids:
486+
*
487+
* @test_Strategy: Create a web application with no web.xml and one fragment;
488+
* Define everything in web-fragment.xml; Package everything in the fragment;
489+
* Servlet tests method Cookie.setAttribute
490+
*/
491+
public void setAttributeTest() throws Fault {
492+
TEST_PROPS.setProperty(APITEST, "setAttributeTest");
493+
invoke();
494+
}
495+
496+
/*
497+
* @testName: getAttributesTest
498+
*
499+
* @assertion_ids:
500+
*
501+
* @test_Strategy: Servlet tests method and returns result to client
502+
*/
503+
public void getAttributesTest() throws Fault {
504+
TEST_PROPS.setProperty(APITEST, "getAttributesTest");
505+
invoke();
506+
}
480507
}

0 commit comments

Comments
 (0)