KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > internal > util > TestCookieUtil


1 /*
2  * ========================================================================
3  *
4  * Copyright 2001-2004 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.internal.util;
21
22 import java.net.URL JavaDoc;
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,v 1.1 2004/05/22 11:34:46 vmassol Exp $
35  */

36 public class TestCookieUtil extends TestCase
37 {
38     /**
39      * Verify that an HttpClient HttpState object can be created when
40      * no Cactus cookies have been defined.
41      *
42      * @exception Exception on error
43      */

44     public void testCreateHttpStateWhenNoCactusCookieDefined()
45         throws Exception JavaDoc
46     {
47         WebRequest request = new WebRequestImpl();
48         HttpState state = new HttpState();
49         state.addCookies(CookieUtil.createHttpClientCookies(request,
50             new URL JavaDoc("http://jakarta.apache.org")));
51         assertEquals(0, state.getCookies().length);
52     }
53
54     /**
55      * Verify that an HttpClient HttpState object can be created when
56      * several Cactus cookies exist.
57      *
58      * @exception Exception on error
59      */

60     public void testCreateHttpStateWhenSeveralCactusCookieExist()
61         throws Exception JavaDoc
62     {
63         WebRequest request = new WebRequestImpl();
64         request.addCookie(new Cookie("domain1", "name1", "value1"));
65         request.addCookie(new Cookie("domain2", "name2", "value2"));
66         
67         HttpState state = new HttpState();
68         state.addCookies(CookieUtil.createHttpClientCookies(request,
69             new URL JavaDoc("http://jakarta.apache.org")));
70
71         assertEquals(2, state.getCookies().length);
72     }
73
74 }
75
Popular Tags