KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > sample > servlet > unit > TestCookie


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

20 package org.apache.cactus.sample.servlet.unit;
21
22 import org.apache.cactus.ServletTestCase;
23 import org.apache.cactus.WebRequest;
24
25 /**
26  * Tests related to Cookies.
27  *
28  * @version $Id: TestCookie.java,v 1.3 2004/02/29 16:36:44 vmassol Exp $
29  */

30 public class TestCookie extends ServletTestCase
31 {
32     /**
33      * Verify that special characters in cookies are not URL encoded
34      *
35      * @param theRequest the request object that serves to initialize the
36      * HTTP connection to the server redirector.
37      */

38     public void beginCookieEncoding(WebRequest theRequest)
39     {
40         // Note: the pipe ('&') character is a special character regarding
41
// URL encoding
42
theRequest.addCookie("testcookie", "user&pwd");
43     }
44
45     /**
46      * Verify that special characters in cookies are not encoded
47      */

48     public void testCookieEncoding()
49     {
50         javax.servlet.http.Cookie JavaDoc[] cookies = request.getCookies();
51
52         assertNotNull("No cookies in request", cookies);
53
54         for (int i = 0; i < cookies.length; i++)
55         {
56             if (cookies[i].getName().equals("testcookie"))
57             {
58                 assertEquals("user&pwd", cookies[i].getValue());
59                 return;
60             }
61         }
62
63         fail("No cookie named 'testcookie' found");
64     }
65
66 }
67
Popular Tags