001: /*
002: * Copyright 1999,2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.catalina.util;
018:
019: import javax.servlet.http.Cookie;
020: import junit.framework.Test;
021: import junit.framework.TestCase;
022: import junit.framework.TestSuite;
023:
024: /**
025: * Unit tests for the <code>CookieTools</code> class.
026: *
027: * @author Craig R. McClanahan
028: * @version $Revision: 1.2 $ $Date: 2004/02/27 14:58:55 $
029: */
030:
031: public class CookieToolsTestCase extends TestCase {
032:
033: public static void main(String args[]) {
034: System.out.println("TestCase started");
035: }
036:
037: // ----------------------------------------------------- Instance Variables
038:
039: /**
040: * A "version 0" cookie.
041: */
042: protected Cookie version0 = null;
043:
044: /**
045: * A "version 1" cookie.
046: */
047: protected Cookie version1 = null;
048:
049: // ----------------------------------------------------------- Constructors
050:
051: /**
052: * Construct a new instance of this test case.
053: *
054: * @param name Name of the test case
055: */
056: public CookieToolsTestCase(String name) {
057:
058: super (name);
059:
060: }
061:
062: // --------------------------------------------------- Overall Test Methods
063:
064: /**
065: * Set up instance variables required by this test case.
066: */
067: public void setUp() {
068:
069: version0 = new Cookie("Version 0 Name", "Version 0 Value");
070: version0.setComment("Version 0 Comment");
071: version0.setDomain("localhost");
072: version0.setPath("/version0");
073: version0.setVersion(0);
074:
075: version1 = new Cookie("Version 1 Name", "Version 1 Value");
076: version1.setComment("Version 1 Comment");
077: version1.setDomain("localhost");
078: version1.setPath("/version1");
079: version1.setVersion(1);
080:
081: }
082:
083: /**
084: * Return the tests included in this test suite.
085: */
086: public static Test suite() {
087:
088: return (new TestSuite(CookieToolsTestCase.class));
089:
090: }
091:
092: /**
093: * Tear down instance variables required by this test case.
094: */
095: public void tearDown() {
096:
097: version0 = null;
098: version1 = null;
099:
100: }
101:
102: // ------------------------------------------------ Individual Test Methods
103:
104: /**
105: * Check the value returned by <code>getCookieHeaderName()</code>.
106: */
107: public void testGetCookieHeaderName() {
108:
109: assertEquals("Version 0 cookie header name", "Set-Cookie",
110: CookieTools.getCookieHeaderName(version0));
111: assertEquals("Version 1 cookie header name", "Set-Cookie2",
112: CookieTools.getCookieHeaderName(version1));
113:
114: }
115:
116: /**
117: * Check the value returned by <code>getCookieHeaderValue()</code>
118: */
119: public void testGetCookieHeaderValue() {
120:
121: StringBuffer sb = null;
122:
123: sb = new StringBuffer();
124: CookieTools.getCookieHeaderValue(version0, sb);
125: assertEquals(
126: "Version 0 cookie header value",
127: "Version 0 Name=Version 0 Value;Domain=localhost;Path=/version0",
128: sb.toString());
129:
130: sb = new StringBuffer();
131: CookieTools.getCookieHeaderValue(version1, sb);
132: assertEquals(
133: "Version 1 cookie header value",
134: "Version 1 Name=\"Version 1 Value\";Version=1;Comment=\"Version 1 Comment\";Domain=localhost;Discard;Path=\"/version1\"",
135: sb.toString());
136:
137: }
138:
139: }
|