1 package org.apache.maven.wagon.shared.http;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.commons.httpclient.Header;
23 import org.apache.commons.httpclient.methods.HeadMethod;
24 import org.apache.commons.httpclient.params.HttpClientParams;
25 import org.apache.commons.httpclient.params.HttpMethodParams;
26
27 import junit.framework.TestCase;
28
29 public class AbstractHttpClientWagonTest
30 extends TestCase
31 {
32
33 public void testSetPreemptiveAuthParamViaConfig()
34 {
35 HttpMethodConfiguration methodConfig = new HttpMethodConfiguration();
36 methodConfig.addParam( HttpClientParams.PREEMPTIVE_AUTHENTICATION, "%b,true" );
37
38 HttpConfiguration config = new HttpConfiguration();
39 config.setAll( methodConfig );
40
41 TestWagon wagon = new TestWagon();
42 wagon.setHttpConfiguration( config );
43
44 HeadMethod method = new HeadMethod();
45 wagon.setParameters( method );
46
47 HttpMethodParams params = method.getParams();
48 assertNotNull( params );
49 assertTrue( params.isParameterTrue( HttpClientParams.PREEMPTIVE_AUTHENTICATION ) );
50 }
51
52 public void testSetMaxRedirectsParamViaConfig()
53 {
54 HttpMethodConfiguration methodConfig = new HttpMethodConfiguration();
55 int maxRedirects = 2;
56 methodConfig.addParam( HttpClientParams.MAX_REDIRECTS, "%i," + maxRedirects );
57
58 HttpConfiguration config = new HttpConfiguration();
59 config.setAll( methodConfig );
60
61 TestWagon wagon = new TestWagon();
62 wagon.setHttpConfiguration( config );
63
64 HeadMethod method = new HeadMethod();
65 wagon.setParameters( method );
66
67 HttpMethodParams params = method.getParams();
68 assertNotNull( params );
69 assertEquals( maxRedirects, params.getIntParameter( HttpClientParams.MAX_REDIRECTS, -1 ) );
70 }
71
72 public void testDefaultHeadersUsedByDefault()
73 {
74 HttpConfiguration config = new HttpConfiguration();
75 config.setAll( new HttpMethodConfiguration() );
76
77 TestWagon wagon = new TestWagon();
78 wagon.setHttpConfiguration( config );
79
80 HeadMethod method = new HeadMethod();
81 wagon.setHeaders( method );
82
83
84
85
86
87
88
89
90 Header header = method.getRequestHeader( "Cache-control" );
91 assertNotNull( header );
92 assertEquals( "no-cache", header.getValue() );
93
94 header = method.getRequestHeader( "Cache-store" );
95 assertNotNull( header );
96 assertEquals( "no-store", header.getValue() );
97
98 header = method.getRequestHeader( "Pragma" );
99 assertNotNull( header );
100 assertEquals( "no-cache", header.getValue() );
101
102 header = method.getRequestHeader( "Expires" );
103 assertNotNull( header );
104 assertEquals( "0", header.getValue() );
105
106 header = method.getRequestHeader( "Accept-Encoding" );
107 assertNotNull( header );
108 assertEquals( "gzip", header.getValue() );
109 }
110
111 public void testTurnOffDefaultHeaders()
112 {
113 HttpConfiguration config = new HttpConfiguration();
114 config.setAll( new HttpMethodConfiguration().setUseDefaultHeaders( false ) );
115
116 TestWagon wagon = new TestWagon();
117 wagon.setHttpConfiguration( config );
118
119 HeadMethod method = new HeadMethod();
120 wagon.setHeaders( method );
121
122
123
124
125
126
127
128
129 Header header = method.getRequestHeader( "Cache-control" );
130 assertNull( header );
131
132 header = method.getRequestHeader( "Cache-store" );
133 assertNull( header );
134
135 header = method.getRequestHeader( "Pragma" );
136 assertNull( header );
137
138 header = method.getRequestHeader( "Expires" );
139 assertNull( header );
140
141 header = method.getRequestHeader( "Accept-Encoding" );
142 assertNull( header );
143 }
144
145 private static final class TestWagon
146 extends AbstractHttpClientWagon
147 {
148 }
149
150 }