KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > catalina > util > CookieToolsTestCase


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17
18 package org.apache.catalina.util;
19
20 import javax.servlet.http.Cookie JavaDoc;
21 import junit.framework.Test;
22 import junit.framework.TestCase;
23 import junit.framework.TestSuite;
24
25
26 /**
27  * Unit tests for the <code>CookieTools</code> class.
28  *
29  * @author Craig R. McClanahan
30  * @version $Revision: 1.2 $ $Date: 2004/02/27 14:58:55 $
31  */

32
33 public class CookieToolsTestCase extends TestCase {
34
35
36     public static void main(String JavaDoc args[]) {
37         System.out.println("TestCase started");
38     }
39
40     // ----------------------------------------------------- Instance Variables
41

42
43     /**
44      * A "version 0" cookie.
45      */

46     protected Cookie JavaDoc version0 = null;
47
48
49     /**
50      * A "version 1" cookie.
51      */

52     protected Cookie JavaDoc version1 = null;
53
54
55
56     // ----------------------------------------------------------- Constructors
57

58
59     /**
60      * Construct a new instance of this test case.
61      *
62      * @param name Name of the test case
63      */

64     public CookieToolsTestCase(String JavaDoc name) {
65
66         super(name);
67
68     }
69
70
71     // --------------------------------------------------- Overall Test Methods
72

73
74     /**
75      * Set up instance variables required by this test case.
76      */

77     public void setUp() {
78
79         version0 = new Cookie JavaDoc("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 JavaDoc("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     /**
95      * Return the tests included in this test suite.
96      */

97     public static Test suite() {
98
99         return (new TestSuite(CookieToolsTestCase.class));
100
101     }
102
103
104     /**
105      * Tear down instance variables required by this test case.
106      */

107     public void tearDown() {
108
109         version0 = null;
110         version1 = null;
111
112     }
113
114
115     // ------------------------------------------------ Individual Test Methods
116

117
118     /**
119      * Check the value returned by <code>getCookieHeaderName()</code>.
120      */

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     /**
132      * Check the value returned by <code>getCookieHeaderValue()</code>
133      */

134     public void testGetCookieHeaderValue() {
135
136         StringBuffer JavaDoc sb = null;
137
138         sb = new StringBuffer JavaDoc();
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 JavaDoc();
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