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 package org.apache.commons.httpclient;
32 import java.io.IOException;
33
34 import junit.framework.Test;
35 import junit.framework.TestSuite;
36
37 import org.apache.commons.httpclient.methods.GetMethod;
38 import org.apache.commons.httpclient.params.HttpMethodParams;
39
40 /***
41 * HTTP protocol versioning tests.
42 *
43 * @author Oleg Kalnichevski
44 *
45 * @version $Revision: 155418 $
46 */
47 public class TestEffectiveHttpVersion extends HttpClientTestBase {
48
49
50 public TestEffectiveHttpVersion(final String testName) throws IOException {
51 super(testName);
52 }
53
54
55 public static void main(String args[]) {
56 String[] testCaseName = { TestEffectiveHttpVersion.class.getName() };
57 junit.textui.TestRunner.main(testCaseName);
58 }
59
60
61
62 public static Test suite() {
63 return new TestSuite(TestEffectiveHttpVersion.class);
64 }
65
66 public void testClientLevelHttpVersion() throws IOException {
67 this.server.setHttpService(new EchoService());
68
69 HttpVersion testver = new HttpVersion(1, 10);
70
71 this.client.getParams().setVersion(testver);
72 GetMethod httpget = new GetMethod("/test/");
73 try {
74 this.client.executeMethod(httpget);
75 } finally {
76 httpget.releaseConnection();
77 }
78 assertEquals(testver, httpget.getEffectiveVersion());
79 }
80
81 public void testMethodLevelHttpVersion() throws IOException {
82 this.server.setHttpService(new EchoService());
83
84 HttpVersion globalver = new HttpVersion(1, 10);
85 HttpVersion testver1 = new HttpVersion(1, 11);
86 HttpVersion testver2 = new HttpVersion(1, 12);
87
88 this.client.getParams().setVersion(globalver);
89
90 GetMethod httpget1 = new GetMethod("/test/");
91 httpget1.getParams().setVersion(testver1);
92 try {
93 this.client.executeMethod(httpget1);
94 } finally {
95 httpget1.releaseConnection();
96 }
97 assertEquals(testver1, httpget1.getEffectiveVersion());
98
99 GetMethod httpget2 = new GetMethod("/test/");
100 httpget2.getParams().setVersion(testver2);
101 try {
102 this.client.executeMethod(httpget2);
103 } finally {
104 httpget2.releaseConnection();
105 }
106 assertEquals(testver2, httpget2.getEffectiveVersion());
107
108 GetMethod httpget3 = new GetMethod("/test/");
109 try {
110 this.client.executeMethod(httpget3);
111 } finally {
112 httpget3.releaseConnection();
113 }
114 assertEquals(globalver, httpget3.getEffectiveVersion());
115 }
116
117 public void testHostLevelHttpVersion() throws IOException {
118 this.server.setHttpService(new EchoService());
119
120 HttpVersion testver = new HttpVersion(1, 11);
121 HttpVersion hostver = new HttpVersion(1, 12);
122
123 this.client.getParams().setVersion(testver);
124
125 GetMethod httpget1 = new GetMethod("/test/");
126 httpget1.getParams().setVersion(testver);
127
128 HostConfiguration hostconf = new HostConfiguration();
129 hostconf.setHost(this.server.getLocalAddress(), this.server.getLocalPort(), "http");
130 try {
131 this.client.executeMethod(hostconf, httpget1);
132 } finally {
133 httpget1.releaseConnection();
134 }
135 assertEquals(testver, httpget1.getEffectiveVersion());
136
137 GetMethod httpget2 = new GetMethod("/test/");
138 hostconf.setHost(this.server.getLocalAddress(), this.server.getLocalPort(), "http");
139 hostconf.getParams().setParameter(HttpMethodParams.PROTOCOL_VERSION, hostver);
140 try {
141 this.client.executeMethod(hostconf, httpget2);
142 } finally {
143 httpget2.releaseConnection();
144 }
145 assertEquals(hostver, httpget2.getEffectiveVersion());
146 }
147 }