KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > httpclient > TestEffectiveHttpVersion


1 /*
2  * $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 $
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  * [Additional notices, if required by prior licensing conditions]
29  *
30  */

31
32 package org.apache.commons.httpclient;
33 import java.io.IOException JavaDoc;
34
35 import junit.framework.Test;
36 import junit.framework.TestSuite;
37
38 import org.apache.commons.httpclient.methods.GetMethod;
39 import org.apache.commons.httpclient.params.HttpMethodParams;
40
41 /**
42  * HTTP protocol versioning tests.
43  *
44  * @author Oleg Kalnichevski
45  *
46  * @version $Revision: 480424 $
47  */

48 public class TestEffectiveHttpVersion extends HttpClientTestBase {
49
50     // ------------------------------------------------------------ Constructor
51
public TestEffectiveHttpVersion(final String JavaDoc testName) throws IOException JavaDoc {
52         super(testName);
53     }
54
55     // ------------------------------------------------------------------- Main
56
public static void main(String JavaDoc args[]) {
57         String JavaDoc[] testCaseName = { TestEffectiveHttpVersion.class.getName() };
58         junit.textui.TestRunner.main(testCaseName);
59     }
60
61     // ------------------------------------------------------- TestCase Methods
62

63     public static Test suite() {
64         return new TestSuite(TestEffectiveHttpVersion.class);
65     }
66
67     public void testClientLevelHttpVersion() throws IOException JavaDoc {
68         this.server.setHttpService(new EchoService());
69
70         HttpVersion testver = new HttpVersion(1, 10);
71
72         this.client.getParams().setVersion(testver);
73         GetMethod httpget = new GetMethod("/test/");
74         try {
75             this.client.executeMethod(httpget);
76         } finally {
77             httpget.releaseConnection();
78         }
79         assertEquals(testver, httpget.getEffectiveVersion());
80     }
81
82     public void testMethodLevelHttpVersion() throws IOException JavaDoc {
83         this.server.setHttpService(new EchoService());
84
85         HttpVersion globalver = new HttpVersion(1, 10);
86         HttpVersion testver1 = new HttpVersion(1, 11);
87         HttpVersion testver2 = new HttpVersion(1, 12);
88
89         this.client.getParams().setVersion(globalver);
90         
91         GetMethod httpget1 = new GetMethod("/test/");
92         httpget1.getParams().setVersion(testver1);
93         try {
94             this.client.executeMethod(httpget1);
95         } finally {
96             httpget1.releaseConnection();
97         }
98         assertEquals(testver1, httpget1.getEffectiveVersion());
99
100         GetMethod httpget2 = new GetMethod("/test/");
101         httpget2.getParams().setVersion(testver2);
102         try {
103             this.client.executeMethod(httpget2);
104         } finally {
105             httpget2.releaseConnection();
106         }
107         assertEquals(testver2, httpget2.getEffectiveVersion());
108
109         GetMethod httpget3 = new GetMethod("/test/");
110         try {
111             this.client.executeMethod(httpget3);
112         } finally {
113             httpget3.releaseConnection();
114         }
115         assertEquals(globalver, httpget3.getEffectiveVersion());
116     }
117
118     public void testHostLevelHttpVersion() throws IOException JavaDoc {
119         this.server.setHttpService(new EchoService());
120
121         HttpVersion testver = new HttpVersion(1, 11);
122         HttpVersion hostver = new HttpVersion(1, 12);
123
124         this.client.getParams().setVersion(testver);
125         
126         GetMethod httpget1 = new GetMethod("/test/");
127         httpget1.getParams().setVersion(testver);
128         
129         HostConfiguration hostconf = new HostConfiguration();
130         hostconf.setHost(this.server.getLocalAddress(), this.server.getLocalPort(), "http");
131         try {
132             this.client.executeMethod(hostconf, httpget1);
133         } finally {
134             httpget1.releaseConnection();
135         }
136         assertEquals(testver, httpget1.getEffectiveVersion());
137
138         GetMethod httpget2 = new GetMethod("/test/");
139         hostconf.setHost(this.server.getLocalAddress(), this.server.getLocalPort(), "http");
140         hostconf.getParams().setParameter(HttpMethodParams.PROTOCOL_VERSION, hostver);
141         try {
142             this.client.executeMethod(hostconf, httpget2);
143         } finally {
144             httpget2.releaseConnection();
145         }
146         assertEquals(hostver, httpget2.getEffectiveVersion());
147     }
148 }
149
Popular Tags