001: /*
002: * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/TestEffectiveHttpVersion.java,v 1.4 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: * [Additional notices, if required by prior licensing conditions]
029: *
030: */
031:
032: package org.apache.commons.httpclient;
033:
034: import java.io.IOException;
035:
036: import junit.framework.Test;
037: import junit.framework.TestSuite;
038:
039: import org.apache.commons.httpclient.methods.GetMethod;
040: import org.apache.commons.httpclient.params.HttpMethodParams;
041:
042: /**
043: * HTTP protocol versioning tests.
044: *
045: * @author Oleg Kalnichevski
046: *
047: * @version $Revision: 480424 $
048: */
049: public class TestEffectiveHttpVersion extends HttpClientTestBase {
050:
051: // ------------------------------------------------------------ Constructor
052: public TestEffectiveHttpVersion(final String testName)
053: throws IOException {
054: super (testName);
055: }
056:
057: // ------------------------------------------------------------------- Main
058: public static void main(String args[]) {
059: String[] testCaseName = { TestEffectiveHttpVersion.class
060: .getName() };
061: junit.textui.TestRunner.main(testCaseName);
062: }
063:
064: // ------------------------------------------------------- TestCase Methods
065:
066: public static Test suite() {
067: return new TestSuite(TestEffectiveHttpVersion.class);
068: }
069:
070: public void testClientLevelHttpVersion() throws IOException {
071: this .server.setHttpService(new EchoService());
072:
073: HttpVersion testver = new HttpVersion(1, 10);
074:
075: this .client.getParams().setVersion(testver);
076: GetMethod httpget = new GetMethod("/test/");
077: try {
078: this .client.executeMethod(httpget);
079: } finally {
080: httpget.releaseConnection();
081: }
082: assertEquals(testver, httpget.getEffectiveVersion());
083: }
084:
085: public void testMethodLevelHttpVersion() throws IOException {
086: this .server.setHttpService(new EchoService());
087:
088: HttpVersion globalver = new HttpVersion(1, 10);
089: HttpVersion testver1 = new HttpVersion(1, 11);
090: HttpVersion testver2 = new HttpVersion(1, 12);
091:
092: this .client.getParams().setVersion(globalver);
093:
094: GetMethod httpget1 = new GetMethod("/test/");
095: httpget1.getParams().setVersion(testver1);
096: try {
097: this .client.executeMethod(httpget1);
098: } finally {
099: httpget1.releaseConnection();
100: }
101: assertEquals(testver1, httpget1.getEffectiveVersion());
102:
103: GetMethod httpget2 = new GetMethod("/test/");
104: httpget2.getParams().setVersion(testver2);
105: try {
106: this .client.executeMethod(httpget2);
107: } finally {
108: httpget2.releaseConnection();
109: }
110: assertEquals(testver2, httpget2.getEffectiveVersion());
111:
112: GetMethod httpget3 = new GetMethod("/test/");
113: try {
114: this .client.executeMethod(httpget3);
115: } finally {
116: httpget3.releaseConnection();
117: }
118: assertEquals(globalver, httpget3.getEffectiveVersion());
119: }
120:
121: public void testHostLevelHttpVersion() throws IOException {
122: this .server.setHttpService(new EchoService());
123:
124: HttpVersion testver = new HttpVersion(1, 11);
125: HttpVersion hostver = new HttpVersion(1, 12);
126:
127: this .client.getParams().setVersion(testver);
128:
129: GetMethod httpget1 = new GetMethod("/test/");
130: httpget1.getParams().setVersion(testver);
131:
132: HostConfiguration hostconf = new HostConfiguration();
133: hostconf.setHost(this .server.getLocalAddress(), this .server
134: .getLocalPort(), "http");
135: try {
136: this .client.executeMethod(hostconf, httpget1);
137: } finally {
138: httpget1.releaseConnection();
139: }
140: assertEquals(testver, httpget1.getEffectiveVersion());
141:
142: GetMethod httpget2 = new GetMethod("/test/");
143: hostconf.setHost(this .server.getLocalAddress(), this .server
144: .getLocalPort(), "http");
145: hostconf.getParams().setParameter(
146: HttpMethodParams.PROTOCOL_VERSION, hostver);
147: try {
148: this.client.executeMethod(hostconf, httpget2);
149: } finally {
150: httpget2.releaseConnection();
151: }
152: assertEquals(hostver, httpget2.getEffectiveVersion());
153: }
154: }
|