|
3 | 3 | * *
|
4 | 4 | * * The Apache Software License, Version 1.1
|
5 | 5 | * *
|
6 |
| - * * Copyright (c) 2001, 2020 Oracle and/or its affiliates and others. |
| 6 | + * * Copyright (c) 2001, 2021 Oracle and/or its affiliates and others. |
7 | 7 | * * All rights reserved.
|
8 | 8 | * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
|
9 | 9 | * * reserved.
|
|
63 | 63 | import java.io.PrintWriter;
|
64 | 64 | import java.text.SimpleDateFormat;
|
65 | 65 | import java.util.Date;
|
| 66 | +import java.util.Map; |
66 | 67 | import java.util.TimeZone;
|
67 | 68 |
|
| 69 | +import javax.management.AttributeValueExp; |
| 70 | + |
68 | 71 | import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet;
|
69 | 72 | import com.sun.ts.tests.servlet.common.util.ServletTestUtil;
|
70 | 73 |
|
@@ -672,4 +675,65 @@ public void setVersionVer1Test(HttpServletRequest request,
|
672 | 675 | }
|
673 | 676 | ServletTestUtil.printResult(pw, passed);
|
674 | 677 | }
|
| 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 | + } |
675 | 739 | }
|
0 commit comments