001: /*
002: * $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 $
003: * $Revision: 480424 $
004: * $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
005: * ====================================================================
006: *
007: * Licensed to the Apache Software Foundation (ASF) under one or more
008: * contributor license agreements. See the NOTICE file distributed with
009: * this work for additional information regarding copyright ownership.
010: * The ASF licenses this file to You under the Apache License, Version 2.0
011: * (the "License"); you may not use this file except in compliance with
012: * the License. You may obtain a copy of the License at
013: *
014: * http://www.apache.org/licenses/LICENSE-2.0
015: *
016: * Unless required by applicable law or agreed to in writing, software
017: * distributed under the License is distributed on an "AS IS" BASIS,
018: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019: * See the License for the specific language governing permissions and
020: * limitations under the License.
021: * ====================================================================
022: *
023: * This software consists of voluntary contributions made by many
024: * individuals on behalf of the Apache Software Foundation. For more
025: * information on the Apache Software Foundation, please see
026: * <http://www.apache.org/>.
027: *
028: */
029:
030: package org.apache.commons.httpclient.cookie;
031:
032: import java.io.IOException;
033:
034: import junit.framework.Test;
035: import junit.framework.TestSuite;
036:
037: import org.apache.commons.httpclient.Cookie;
038: import org.apache.commons.httpclient.Header;
039: import org.apache.commons.httpclient.HttpClientTestBase;
040: import org.apache.commons.httpclient.HttpStatus;
041: import org.apache.commons.httpclient.HttpVersion;
042: import org.apache.commons.httpclient.methods.GetMethod;
043: import org.apache.commons.httpclient.server.HttpService;
044: import org.apache.commons.httpclient.server.SimpleRequest;
045: import org.apache.commons.httpclient.server.SimpleResponse;
046:
047: /**
048: * Test cases for ignore cookie apec
049: *
050: * @author Michael Becke
051: *
052: * @version $Revision: 480424 $
053: */
054: public class TestCookieIgnoreSpec extends HttpClientTestBase {
055:
056: // ------------------------------------------------------------ Constructor
057:
058: public TestCookieIgnoreSpec(final String testName)
059: throws IOException {
060: super (testName);
061: }
062:
063: // ------------------------------------------------------- TestCase Methods
064:
065: public static Test suite() {
066: return new TestSuite(TestCookieIgnoreSpec.class);
067: }
068:
069: private class BasicAuthService implements HttpService {
070:
071: public BasicAuthService() {
072: super ();
073: }
074:
075: public boolean process(final SimpleRequest request,
076: final SimpleResponse response) throws IOException {
077: HttpVersion ver = request.getRequestLine().getHttpVersion();
078: response.setStatusLine(ver, HttpStatus.SC_OK);
079: response.addHeader(new Header("Connection", "close"));
080: response
081: .addHeader(new Header(
082: "Set-Cookie",
083: "custno = 12345; comment=test; version=1,"
084: + " name=John; version=1; max-age=600; secure; domain=.apache.org"));
085: return true;
086: }
087: }
088:
089: public void testIgnoreCookies() throws Exception {
090: this .server.setHttpService(new BasicAuthService());
091:
092: GetMethod httpget = new GetMethod("/");
093: httpget.getParams()
094: .setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
095:
096: try {
097: this .client.executeMethod(httpget);
098: } finally {
099: httpget.releaseConnection();
100: }
101: assertEquals("Cookie parsing should have been disabled", 0,
102: this .client.getState().getCookies().length);
103: }
104:
105: public void testKeepCloverHappy() throws Exception {
106: CookieSpec cookiespec = new IgnoreCookiesSpec();
107: cookiespec.parseAttribute(null, null);
108: cookiespec.parse("host", 80, "/", false, (String) null);
109: cookiespec.parse("host", 80, "/", false, (Header) null);
110: cookiespec.validate("host", 80, "/", false, (Cookie) null);
111: cookiespec.match("host", 80, "/", false, (Cookie) null);
112: cookiespec.match("host", 80, "/", false, (Cookie[]) null);
113: cookiespec.domainMatch(null, null);
114: cookiespec.pathMatch(null, null);
115: cookiespec.match("host", 80, "/", false, (Cookie[]) null);
116: cookiespec.formatCookie(null);
117: cookiespec.formatCookies(null);
118: cookiespec.formatCookieHeader((Cookie) null);
119: cookiespec.formatCookieHeader((Cookie[]) null);
120: }
121: }
|