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: 155418 $
4    * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
5    * ====================================================================
6    *
7    *  Copyright 1999-2004 The Apache Software Foundation
8    *
9    *  Licensed under the Apache License, Version 2.0 (the "License");
10   *  you may not use this file except in compliance with the License.
11   *  You may obtain a copy of the License at
12   *
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   *
15   *  Unless required by applicable law or agreed to in writing, software
16   *  distributed under the License is distributed on an "AS IS" BASIS,
17   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   *  See the License for the specific language governing permissions and
19   *  limitations under the License.
20   * ====================================================================
21   *
22   * This software consists of voluntary contributions made by many
23   * individuals on behalf of the Apache Software Foundation.  For more
24   * information on the Apache Software Foundation, please see
25   * <http://www.apache.org/>.
26   *
27   */
28  
29  package org.apache.commons.httpclient.cookie;
30  
31  import java.io.IOException;
32  
33  import junit.framework.Test;
34  import junit.framework.TestSuite;
35  
36  import org.apache.commons.httpclient.Cookie;
37  import org.apache.commons.httpclient.Header;
38  import org.apache.commons.httpclient.HttpClientTestBase;
39  import org.apache.commons.httpclient.HttpStatus;
40  import org.apache.commons.httpclient.HttpVersion;
41  import org.apache.commons.httpclient.methods.GetMethod;
42  import org.apache.commons.httpclient.server.HttpService;
43  import org.apache.commons.httpclient.server.SimpleRequest;
44  import org.apache.commons.httpclient.server.SimpleResponse;
45  
46  
47  /***
48   * Test cases for ignore cookie apec
49   *
50   * @author Michael Becke
51   * 
52   * @version $Revision: 155418 $
53   */
54  public class TestCookieIgnoreSpec extends HttpClientTestBase {
55  
56      // ------------------------------------------------------------ Constructor
57  
58      public TestCookieIgnoreSpec(final String testName) throws IOException {
59          super(testName);
60      }
61  
62      // ------------------------------------------------------- TestCase Methods
63  
64      public static Test suite() {
65          return new TestSuite(TestCookieIgnoreSpec.class);
66      }
67  
68      private class BasicAuthService implements HttpService {
69  
70          public BasicAuthService() {
71              super();
72          }
73  
74          public boolean process(final SimpleRequest request, final SimpleResponse response)
75              throws IOException
76          {
77          	HttpVersion ver = request.getRequestLine().getHttpVersion();
78              response.setStatusLine(ver, HttpStatus.SC_OK);
79              response.addHeader(new Header("Connection", "close"));
80              response.addHeader(new Header("Set-Cookie", 
81                  "custno = 12345; comment=test; version=1," +
82                  " name=John; version=1; max-age=600; secure; domain=.apache.org"));
83              return true;
84          }
85      }
86  
87      public void testIgnoreCookies() throws Exception {
88          this.server.setHttpService(new BasicAuthService());
89  
90          GetMethod httpget = new GetMethod("/");
91          httpget.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
92          
93          try {
94              this.client.executeMethod(httpget);
95          } finally {
96              httpget.releaseConnection();
97          }
98          assertEquals("Cookie parsing should have been disabled", 
99                  0, this.client.getState().getCookies().length);
100     }
101 
102     public void testKeepCloverHappy() throws Exception {
103         CookieSpec cookiespec = new IgnoreCookiesSpec();
104         cookiespec.parseAttribute(null, null);
105         cookiespec.parse("host", 80, "/", false, (String)null);
106         cookiespec.parse("host", 80, "/", false, (Header)null);
107         cookiespec.validate("host", 80, "/", false, (Cookie)null);
108         cookiespec.match("host", 80, "/", false, (Cookie)null);
109         cookiespec.match("host", 80, "/", false, (Cookie [])null);
110         cookiespec.domainMatch(null, null);
111         cookiespec.pathMatch(null, null);
112         cookiespec.match("host", 80, "/", false, (Cookie [])null);
113         cookiespec.formatCookie(null);
114         cookiespec.formatCookies(null);
115         cookiespec.formatCookieHeader((Cookie)null);
116         cookiespec.formatCookieHeader((Cookie [])null);
117     }
118 }
119