01: /*
02: * ========================================================================
03: *
04: * Copyright 2001-2003 The Apache Software Foundation.
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
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 238816 2004-02-29 16:36:46Z vmassol $
29: */
30: public class TestCookie extends ServletTestCase {
31: /**
32: * Verify that special characters in cookies are not URL encoded
33: *
34: * @param theRequest the request object that serves to initialize the
35: * HTTP connection to the server redirector.
36: */
37: public void beginCookieEncoding(WebRequest theRequest) {
38: // Note: the pipe ('&') character is a special character regarding
39: // URL encoding
40: theRequest.addCookie("testcookie", "user&pwd");
41: }
42:
43: /**
44: * Verify that special characters in cookies are not encoded
45: */
46: public void testCookieEncoding() {
47: javax.servlet.http.Cookie[] cookies = request.getCookies();
48:
49: assertNotNull("No cookies in request", cookies);
50:
51: for (int i = 0; i < cookies.length; i++) {
52: if (cookies[i].getName().equals("testcookie")) {
53: assertEquals("user&pwd", cookies[i].getValue());
54: return;
55: }
56: }
57:
58: fail("No cookie named 'testcookie' found");
59: }
60:
61: }
|