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 import org.apache.maven.wagon.OutputData;
29 import org.apache.maven.wagon.TransferFailedException;
30
31 public class AbstractHttpClientWagonTest
32 extends TestCase
33 {
34
35 public void testSetPreemptiveAuthParamViaConfig()
36 {
37 HttpMethodConfiguration methodConfig = new HttpMethodConfiguration();
38 methodConfig.addParam( HttpClientParams.PREEMPTIVE_AUTHENTICATION, "%b,true" );
39
40 HttpConfiguration config = new HttpConfiguration();
41 config.setAll( methodConfig );
42
43 TestWagon wagon = new TestWagon();
44 wagon.setHttpConfiguration( config );
45
46 HeadMethod method = new HeadMethod();
47 wagon.setParameters( method );
48
49 HttpMethodParams params = method.getParams();
50 assertNotNull( params );
51 assertTrue( params.isParameterTrue( HttpClientParams.PREEMPTIVE_AUTHENTICATION ) );
52 }
53
54 public void testSetMaxRedirectsParamViaConfig()
55 {
56 HttpMethodConfiguration methodConfig = new HttpMethodConfiguration();
57 int maxRedirects = 2;
58 methodConfig.addParam( HttpClientParams.MAX_REDIRECTS, "%i," + maxRedirects );
59
60 HttpConfiguration config = new HttpConfiguration();
61 config.setAll( methodConfig );
62
63 TestWagon wagon = new TestWagon();
64 wagon.setHttpConfiguration( config );
65
66 HeadMethod method = new HeadMethod();
67 wagon.setParameters( method );
68
69 HttpMethodParams params = method.getParams();
70 assertNotNull( params );
71 assertEquals( maxRedirects, params.getIntParameter( HttpClientParams.MAX_REDIRECTS, -1 ) );
72 }
73
74 public void testDefaultHeadersUsedByDefault()
75 {
76 HttpConfiguration config = new HttpConfiguration();
77 config.setAll( new HttpMethodConfiguration() );
78
79 TestWagon wagon = new TestWagon();
80 wagon.setHttpConfiguration( config );
81
82 HeadMethod method = new HeadMethod();
83 wagon.setHeaders( method );
84
85
86
87
88
89
90
91
92 Header header = method.getRequestHeader( "Cache-control" );
93 assertNotNull( header );
94 assertEquals( "no-cache", header.getValue() );
95
96 header = method.getRequestHeader( "Cache-store" );
97 assertNotNull( header );
98 assertEquals( "no-store", header.getValue() );
99
100 header = method.getRequestHeader( "Pragma" );
101 assertNotNull( header );
102 assertEquals( "no-cache", header.getValue() );
103
104 header = method.getRequestHeader( "Expires" );
105 assertNotNull( header );
106 assertEquals( "0", header.getValue() );
107
108 header = method.getRequestHeader( "Accept-Encoding" );
109 assertNotNull( header );
110 assertEquals( "gzip", header.getValue() );
111 }
112
113 public void testTurnOffDefaultHeaders()
114 {
115 HttpConfiguration config = new HttpConfiguration();
116 config.setAll( new HttpMethodConfiguration().setUseDefaultHeaders( false ) );
117
118 TestWagon wagon = new TestWagon();
119 wagon.setHttpConfiguration( config );
120
121 HeadMethod method = new HeadMethod();
122 wagon.setHeaders( method );
123
124
125
126
127
128
129
130
131 Header header = method.getRequestHeader( "Cache-control" );
132 assertNull( header );
133
134 header = method.getRequestHeader( "Cache-store" );
135 assertNull( header );
136
137 header = method.getRequestHeader( "Pragma" );
138 assertNull( header );
139
140 header = method.getRequestHeader( "Expires" );
141 assertNull( header );
142
143 header = method.getRequestHeader( "Accept-Encoding" );
144 assertNull( header );
145 }
146
147 private static final class TestWagon
148 extends AbstractHttpClientWagon
149 {
150 @Override
151 public void fillOutputData( OutputData outputData )
152 throws TransferFailedException
153 {
154
155 }
156 }
157
158 }