1 16 17 18 package org.apache.catalina.util; 19 20 import javax.servlet.http.Cookie ; 21 import junit.framework.Test; 22 import junit.framework.TestCase; 23 import junit.framework.TestSuite; 24 25 26 32 33 public class CookieToolsTestCase extends TestCase { 34 35 36 public static void main(String args[]) { 37 System.out.println("TestCase started"); 38 } 39 40 42 43 46 protected Cookie version0 = null; 47 48 49 52 protected Cookie version1 = null; 53 54 55 56 58 59 64 public CookieToolsTestCase(String name) { 65 66 super(name); 67 68 } 69 70 71 73 74 77 public void setUp() { 78 79 version0 = new Cookie ("Version 0 Name", "Version 0 Value"); 80 version0.setComment("Version 0 Comment"); 81 version0.setDomain("localhost"); 82 version0.setPath("/version0"); 83 version0.setVersion(0); 84 85 version1 = new Cookie ("Version 1 Name", "Version 1 Value"); 86 version1.setComment("Version 1 Comment"); 87 version1.setDomain("localhost"); 88 version1.setPath("/version1"); 89 version1.setVersion(1); 90 91 } 92 93 94 97 public static Test suite() { 98 99 return (new TestSuite(CookieToolsTestCase.class)); 100 101 } 102 103 104 107 public void tearDown() { 108 109 version0 = null; 110 version1 = null; 111 112 } 113 114 115 117 118 121 public void testGetCookieHeaderName() { 122 123 assertEquals("Version 0 cookie header name", "Set-Cookie", 124 CookieTools.getCookieHeaderName(version0)); 125 assertEquals("Version 1 cookie header name", "Set-Cookie2", 126 CookieTools.getCookieHeaderName(version1)); 127 128 } 129 130 131 134 public void testGetCookieHeaderValue() { 135 136 StringBuffer sb = null; 137 138 sb = new StringBuffer (); 139 CookieTools.getCookieHeaderValue(version0, sb); 140 assertEquals("Version 0 cookie header value", 141 "Version 0 Name=Version 0 Value;Domain=localhost;Path=/version0", 142 sb.toString()); 143 144 sb = new StringBuffer (); 145 CookieTools.getCookieHeaderValue(version1, sb); 146 assertEquals("Version 1 cookie header value", 147 "Version 1 Name=\"Version 1 Value\";Version=1;Comment=\"Version 1 Comment\";Domain=localhost;Discard;Path=\"/version1\"", 148 sb.toString()); 149 150 } 151 152 153 } 154 | Popular Tags |