1 package org.apache.maven.wagon.providers.webdav;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23 import org.apache.http.Header;
24 import org.apache.http.client.methods.HttpHead;
25 import org.apache.http.client.params.HttpClientParams;
26 import org.apache.http.params.HttpParams;
27 import org.apache.maven.wagon.ConnectionException;
28 import org.apache.maven.wagon.OutputData;
29 import org.apache.maven.wagon.TransferFailedException;
30 import org.apache.maven.wagon.authentication.AuthenticationException;
31 import org.apache.maven.wagon.authentication.AuthenticationInfo;
32 import org.apache.maven.wagon.proxy.ProxyInfo;
33 import org.apache.maven.wagon.repository.Repository;
34 import org.apache.maven.wagon.shared.http.HttpConfiguration;
35 import org.apache.maven.wagon.shared.http.HttpMethodConfiguration;
36 import org.junit.Ignore;
37
38 public class HttpClientWagonTest
39 extends TestCase
40 {
41
42 @Ignore("not sure how to test this")
43 public void testSetPreemptiveAuthParamViaConfig()
44 {
45 HttpMethodConfiguration methodConfig = new HttpMethodConfiguration();
46 methodConfig.setUsePreemptive( true );
47
48 HttpConfiguration config = new HttpConfiguration();
49 config.setAll( methodConfig );
50
51 TestWagon wagon = new TestWagon();
52 wagon.setHttpConfiguration( config );
53
54 HttpHead method = new HttpHead();
55 wagon.setHeaders( method );
56
57 HttpParams params = method.getParams();
58 assertNotNull( params );
59
60 }
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 public void testDefaultHeadersUsedByDefault()
84 {
85 HttpConfiguration config = new HttpConfiguration();
86 config.setAll( new HttpMethodConfiguration() );
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
99
100 Header header = method.getFirstHeader( "Cache-control" );
101 assertNotNull( header );
102 assertEquals( "no-cache", header.getValue() );
103
104 header = method.getFirstHeader( "Cache-store" );
105 assertNotNull( header );
106 assertEquals( "no-store", header.getValue() );
107
108 header = method.getFirstHeader( "Pragma" );
109 assertNotNull( header );
110 assertEquals( "no-cache", 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 Header header = method.getFirstHeader( "Cache-control" );
130 assertNull( header );
131
132 header = method.getFirstHeader( "Cache-store" );
133 assertNull( header );
134
135 header = method.getFirstHeader( "Pragma" );
136 assertNull( header );
137 }
138
139 @Ignore("not sure how to test this")
140 public void testNTCredentialsWithUsernameNull()
141 throws AuthenticationException, ConnectionException
142 {
143 TestWagon wagon = new TestWagon();
144
145 Repository repository = new Repository( "mockRepoId", "mockRepoURL" );
146 wagon.connect( repository );
147
148 wagon.openConnection();
149
150 assertNull( wagon.getAuthenticationInfo().getUserName() );
151 assertNull( wagon.getAuthenticationInfo().getPassword() );
152
153
154 }
155
156 @Ignore("not sure how to test this")
157 public void testNTCredentialsNoNTDomain()
158 throws AuthenticationException, ConnectionException
159 {
160 TestWagon wagon = new TestWagon();
161
162 AuthenticationInfo authenticationInfo = new AuthenticationInfo();
163 String myUsernameNoNTDomain = "myUserNameNoNTDomain";
164 authenticationInfo.setUserName( myUsernameNoNTDomain );
165
166 String myPassword = "myPassword";
167 authenticationInfo.setPassword( myPassword );
168
169 Repository repository = new Repository( "mockRepoId", "mockRepoURL" );
170
171 wagon.connect( repository, authenticationInfo, (ProxyInfo) null );
172
173 wagon.openConnection();
174
175 assertEquals( myUsernameNoNTDomain, wagon.getAuthenticationInfo().getUserName() );
176 assertEquals( myPassword, wagon.getAuthenticationInfo().getPassword() );
177
178
179 }
180
181 @Ignore("not sure how to test this")
182 public void testNTCredentialsWithNTDomain()
183 throws AuthenticationException, ConnectionException
184 {
185 TestWagon wagon = new TestWagon();
186
187 AuthenticationInfo authenticationInfo = new AuthenticationInfo();
188 String myNTDomain = "myNTDomain";
189 String myUsername = "myUsername";
190 String myNTDomainAndUser = myNTDomain + "\\" + myUsername;
191 authenticationInfo.setUserName( myNTDomainAndUser );
192
193 String myPassword = "myPassword";
194 authenticationInfo.setPassword( myPassword );
195
196 Repository repository = new Repository( "mockRepoId", "mockRepoURL" );
197
198 wagon.connect( repository, authenticationInfo, (ProxyInfo) null );
199
200 wagon.openConnection();
201
202 assertEquals( myNTDomainAndUser, wagon.getAuthenticationInfo().getUserName() );
203 assertEquals( myPassword, wagon.getAuthenticationInfo().getPassword() );
204
205
206
207
208
209
210
211
212 }
213
214 private static final class TestWagon
215 extends WebDavWagon
216 {
217 @Override
218 public void fillOutputData( OutputData outputData )
219 throws TransferFailedException
220 {
221
222 }
223 }
224
225 }