1   /*
2    * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/cookie/TestCookieIgnoreSpec.java,v 1.3 2004/04/27 22:35:21 olegk Exp $
3    * $Revision: 1.3 $
4    * $Date: 2004/04/27 22:35:21 $
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.methods.GetMethod;
40  import org.apache.commons.httpclient.server.HttpService;
41  import org.apache.commons.httpclient.server.SimpleRequest;
42  import org.apache.commons.httpclient.server.SimpleResponse;
43  
44  
45  /***
46   * Test cases for ignore cookie apec
47   *
48   * @author Michael Becke
49   * 
50   * @version $Revision: 1.3 $
51   */
52  public class TestCookieIgnoreSpec extends HttpClientTestBase {
53  
54      // ------------------------------------------------------------ Constructor
55  
56      public TestCookieIgnoreSpec(String name) {
57          super(name);
58      }
59  
60      // ------------------------------------------------------- TestCase Methods
61  
62      public static Test suite() {
63          return new TestSuite(TestCookieIgnoreSpec.class);
64      }
65  
66      private class BasicAuthService implements HttpService {
67  
68          public BasicAuthService() {
69              super();
70          }
71  
72          public boolean process(final SimpleRequest request, final SimpleResponse response)
73              throws IOException
74          {
75              response.setStatusLine("HTTP/1.1 200 OK");
76              response.addHeader(new Header("Connection", "close"));
77              response.addHeader(new Header("Set-Cookie", 
78                  "custno = 12345; comment=test; version=1," +
79                  " name=John; version=1; max-age=600; secure; domain=.apache.org"));
80              return true;
81          }
82      }
83  
84      public void testIgnoreCookies() throws Exception {
85          this.server.setHttpService(new BasicAuthService());
86  
87          GetMethod httpget = new GetMethod("/");
88          httpget.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
89          
90          try {
91              this.client.executeMethod(httpget);
92          } finally {
93              httpget.releaseConnection();
94          }
95          assertEquals("Cookie parsing should have been disabled", 
96                  0, this.client.getState().getCookies().length);
97      }
98  
99      public void testKeepCloverHappy() throws Exception {
100         CookieSpec cookiespec = new IgnoreCookiesSpec();
101         cookiespec.parseAttribute(null, null);
102         cookiespec.parse("host", 80, "/", false, (String)null);
103         cookiespec.parse("host", 80, "/", false, (Header)null);
104         cookiespec.validate("host", 80, "/", false, (Cookie)null);
105         cookiespec.match("host", 80, "/", false, (Cookie)null);
106         cookiespec.match("host", 80, "/", false, (Cookie [])null);
107         cookiespec.domainMatch(null, null);
108         cookiespec.pathMatch(null, null);
109         cookiespec.match("host", 80, "/", false, (Cookie [])null);
110         cookiespec.formatCookie(null);
111         cookiespec.formatCookies(null);
112         cookiespec.formatCookieHeader((Cookie)null);
113         cookiespec.formatCookieHeader((Cookie [])null);
114     }
115 }
116