1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 package org.apache.commons.httpclient;
33 import java.io.IOException;
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$
47 */
48 public class TestEffectiveHttpVersion extends HttpClientTestBase {
49
50
51 public TestEffectiveHttpVersion(final String testName) throws IOException {
52 super(testName);
53 }
54
55
56 public static void main(String args[]) {
57 String[] testCaseName = { TestEffectiveHttpVersion.class.getName() };
58 junit.textui.TestRunner.main(testCaseName);
59 }
60
61
62
63 public static Test suite() {
64 return new TestSuite(TestEffectiveHttpVersion.class);
65 }
66
67 public void testClientLevelHttpVersion() throws IOException {
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 {
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 {
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 }