1 package org.apache.maven.wagon.providers.http;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import junit.framework.TestCase;
24
25 import org.apache.http.Header;
26
27
28 import org.apache.http.client.config.RequestConfig;
29 import org.apache.http.client.methods.HttpHead;
30 import org.apache.maven.wagon.OutputData;
31 import org.apache.maven.wagon.TransferFailedException;
32 import org.apache.maven.wagon.shared.http.AbstractHttpClientWagon;
33 import org.apache.maven.wagon.shared.http.ConfigurationUtils;
34 import org.apache.maven.wagon.shared.http.HttpConfiguration;
35 import org.apache.maven.wagon.shared.http.HttpMethodConfiguration;
36
37 public class HttpClientWagonTest
38 extends TestCase
39 {
40
41 public void testSetMaxRedirectsParamViaConfig()
42 {
43 HttpMethodConfiguration methodConfig = new HttpMethodConfiguration();
44 int maxRedirects = 2;
45 methodConfig.addParam("http.protocol.max-redirects", "%i," + maxRedirects);
46
47 HttpConfiguration config = new HttpConfiguration();
48 config.setAll( methodConfig );
49
50 HttpHead method = new HttpHead();
51 RequestConfig.Builder builder = RequestConfig.custom();
52 ConfigurationUtils.copyConfig( config.getMethodConfiguration( method ), builder );
53 RequestConfig requestConfig = builder.build();
54
55 assertEquals(2, requestConfig.getMaxRedirects());
56 }
57
58 public void testDefaultHeadersUsedByDefault()
59 {
60 HttpConfiguration config = new HttpConfiguration();
61 config.setAll( new HttpMethodConfiguration() );
62
63 TestWagon wagon = new TestWagon();
64 wagon.setHttpConfiguration( config );
65
66 HttpHead method = new HttpHead();
67 wagon.setHeaders( method );
68
69
70
71
72
73
74 Header header = method.getFirstHeader( "Cache-control" );
75 assertNotNull( header );
76 assertEquals( "no-cache", header.getValue() );
77
78 header = method.getFirstHeader( "Pragma" );
79 assertNotNull( header );
80 assertEquals( "no-cache", header.getValue() );
81 }
82
83 public void testTurnOffDefaultHeaders()
84 {
85 HttpConfiguration config = new HttpConfiguration();
86 config.setAll( new HttpMethodConfiguration().setUseDefaultHeaders( false ) );
87
88 TestWagon wagon = new TestWagon();
89 wagon.setHttpConfiguration( config );
90
91 HttpHead method = new HttpHead();
92 wagon.setHeaders( method );
93
94
95
96
97
98 Header header = method.getFirstHeader( "Cache-control" );
99 assertNull( header );
100
101 header = method.getFirstHeader( "Pragma" );
102 assertNull( header );
103 }
104
105 private static final class TestWagon
106 extends AbstractHttpClientWagon
107 {
108 @Override
109 public void fillOutputData( OutputData outputData )
110 throws TransferFailedException
111 {
112
113 }
114 }
115
116 }