1 package org.apache.maven.wagon.shared.http4;
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 import org.apache.http.Header;
25 import org.apache.http.client.methods.HttpHead;
26 import org.apache.http.client.params.ClientPNames;
27 import org.apache.http.params.HttpParams;
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
39
40 HttpConfiguration config = new HttpConfiguration();
41 config.setAll( methodConfig );
42
43 TestWagon wagon = new TestWagon();
44 wagon.setHttpConfiguration( config );
45
46 HttpHead method = new HttpHead();
47 wagon.setParameters( method );
48
49 HttpParams params = method.getParams();
50 assertNotNull( params );
51
52 }
53
54 public void testSetMaxRedirectsParamViaConfig()
55 {
56 HttpMethodConfiguration methodConfig = new HttpMethodConfiguration();
57 int maxRedirects = 2;
58 methodConfig.addParam( ClientPNames.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 HttpHead method = new HttpHead();
67 wagon.setParameters( method );
68
69 HttpParams params = method.getParams();
70 assertNotNull( params );
71 assertEquals( maxRedirects, params.getIntParameter( ClientPNames.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 HttpHead method = new HttpHead();
83 wagon.setHeaders( method );
84
85
86
87
88
89
90
91
92 Header header = method.getFirstHeader( "Cache-control" );
93 assertNotNull( header );
94 assertEquals( "no-cache", header.getValue() );
95
96 header = method.getFirstHeader( "Cache-store" );
97 assertNotNull( header );
98 assertEquals( "no-store", header.getValue() );
99
100 header = method.getFirstHeader( "Pragma" );
101 assertNotNull( header );
102 assertEquals( "no-cache", header.getValue() );
103
104 header = method.getFirstHeader( "Expires" );
105 assertNotNull( header );
106 assertEquals( "0", header.getValue() );
107
108 header = method.getFirstHeader( "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 HttpHead method = new HttpHead();
122 wagon.setHeaders( method );
123
124
125
126
127
128
129
130
131 Header header = method.getFirstHeader( "Cache-control" );
132 assertNull( header );
133
134 header = method.getFirstHeader( "Cache-store" );
135 assertNull( header );
136
137 header = method.getFirstHeader( "Pragma" );
138 assertNull( header );
139
140 header = method.getFirstHeader( "Expires" );
141 assertNull( header );
142
143 header = method.getFirstHeader( "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 }