01: /*
02: * ========================================================================
03: *
04: * Copyright 2001-2004 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.internal.util;
21:
22: import java.net.URL;
23:
24: import org.apache.cactus.Cookie;
25: import org.apache.cactus.WebRequest;
26: import org.apache.cactus.internal.WebRequestImpl;
27: import org.apache.commons.httpclient.HttpState;
28:
29: import junit.framework.TestCase;
30:
31: /**
32: * Unit tests for the {@link CookieUtil} class.
33: *
34: * @version $Id: TestCookieUtil.java 238991 2004-05-22 11:34:50Z vmassol $
35: */
36: public class TestCookieUtil extends TestCase {
37: /**
38: * Verify that an HttpClient HttpState object can be created when
39: * no Cactus cookies have been defined.
40: *
41: * @exception Exception on error
42: */
43: public void testCreateHttpStateWhenNoCactusCookieDefined()
44: throws Exception {
45: WebRequest request = new WebRequestImpl();
46: HttpState state = new HttpState();
47: state.addCookies(CookieUtil.createHttpClientCookies(request,
48: new URL("http://jakarta.apache.org")));
49: assertEquals(0, state.getCookies().length);
50: }
51:
52: /**
53: * Verify that an HttpClient HttpState object can be created when
54: * several Cactus cookies exist.
55: *
56: * @exception Exception on error
57: */
58: public void testCreateHttpStateWhenSeveralCactusCookieExist()
59: throws Exception {
60: WebRequest request = new WebRequestImpl();
61: request.addCookie(new Cookie("domain1", "name1", "value1"));
62: request.addCookie(new Cookie("domain2", "name2", "value2"));
63:
64: HttpState state = new HttpState();
65: state.addCookies(CookieUtil.createHttpClientCookies(request,
66: new URL("http://jakarta.apache.org")));
67:
68: assertEquals(2, state.getCookies().length);
69: }
70:
71: }
|