KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > httpclient > cookie > TestCookieIgnoreSpec


1 /*
2  * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/cookie/TestCookieIgnoreSpec.java,v 1.5 2004/10/31 14:42:59 olegk Exp $
3  * $Revision: 480424 $
4  * $Date: 2006-11-29 05:56:49 +0000 (Wed, 29 Nov 2006) $
5  * ====================================================================
6  *
7  * Licensed to the Apache Software Foundation (ASF) under one or more
8  * contributor license agreements. See the NOTICE file distributed with
9  * this work for additional information regarding copyright ownership.
10  * The ASF licenses this file to You under the Apache License, Version 2.0
11  * (the "License"); you may not use this file except in compliance with
12  * the License. You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ====================================================================
22  *
23  * This software consists of voluntary contributions made by many
24  * individuals on behalf of the Apache Software Foundation. For more
25  * information on the Apache Software Foundation, please see
26  * <http://www.apache.org/>.
27  *
28  */

29
30 package org.apache.commons.httpclient.cookie;
31
32 import java.io.IOException JavaDoc;
33
34 import junit.framework.Test;
35 import junit.framework.TestSuite;
36
37 import org.apache.commons.httpclient.Cookie;
38 import org.apache.commons.httpclient.Header;
39 import org.apache.commons.httpclient.HttpClientTestBase;
40 import org.apache.commons.httpclient.HttpStatus;
41 import org.apache.commons.httpclient.HttpVersion;
42 import org.apache.commons.httpclient.methods.GetMethod;
43 import org.apache.commons.httpclient.server.HttpService;
44 import org.apache.commons.httpclient.server.SimpleRequest;
45 import org.apache.commons.httpclient.server.SimpleResponse;
46
47
48 /**
49  * Test cases for ignore cookie apec
50  *
51  * @author Michael Becke
52  *
53  * @version $Revision: 480424 $
54  */

55 public class TestCookieIgnoreSpec extends HttpClientTestBase {
56
57     // ------------------------------------------------------------ Constructor
58

59     public TestCookieIgnoreSpec(final String JavaDoc testName) throws IOException JavaDoc {
60         super(testName);
61     }
62
63     // ------------------------------------------------------- TestCase Methods
64

65     public static Test suite() {
66         return new TestSuite(TestCookieIgnoreSpec.class);
67     }
68
69     private class BasicAuthService implements HttpService {
70
71         public BasicAuthService() {
72             super();
73         }
74
75         public boolean process(final SimpleRequest request, final SimpleResponse response)
76             throws IOException JavaDoc
77         {
78             HttpVersion ver = request.getRequestLine().getHttpVersion();
79             response.setStatusLine(ver, HttpStatus.SC_OK);
80             response.addHeader(new Header("Connection", "close"));
81             response.addHeader(new Header("Set-Cookie",
82                 "custno = 12345; comment=test; version=1," +
83                 " name=John; version=1; max-age=600; secure; domain=.apache.org"));
84             return true;
85         }
86     }
87
88     public void testIgnoreCookies() throws Exception JavaDoc {
89         this.server.setHttpService(new BasicAuthService());
90
91         GetMethod httpget = new GetMethod("/");
92         httpget.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
93         
94         try {
95             this.client.executeMethod(httpget);
96         } finally {
97             httpget.releaseConnection();
98         }
99         assertEquals("Cookie parsing should have been disabled",
100                 0, this.client.getState().getCookies().length);
101     }
102
103     public void testKeepCloverHappy() throws Exception JavaDoc {
104         CookieSpec cookiespec = new IgnoreCookiesSpec();
105         cookiespec.parseAttribute(null, null);
106         cookiespec.parse("host", 80, "/", false, (String JavaDoc)null);
107         cookiespec.parse("host", 80, "/", false, (Header)null);
108         cookiespec.validate("host", 80, "/", false, (Cookie)null);
109         cookiespec.match("host", 80, "/", false, (Cookie)null);
110         cookiespec.match("host", 80, "/", false, (Cookie [])null);
111         cookiespec.domainMatch(null, null);
112         cookiespec.pathMatch(null, null);
113         cookiespec.match("host", 80, "/", false, (Cookie [])null);
114         cookiespec.formatCookie(null);
115         cookiespec.formatCookies(null);
116         cookiespec.formatCookieHeader((Cookie)null);
117         cookiespec.formatCookieHeader((Cookie [])null);
118     }
119 }
120
121
Popular Tags