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