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 Header header = method.getFirstHeader( "Cache-control" );
100 assertNotNull( header );
101 assertEquals( "no-cache", header.getValue() );
102
103 header = method.getFirstHeader( "Pragma" );
104 assertNotNull( header );
105 assertEquals( "no-cache", header.getValue() );
106 }
107
108 public void testTurnOffDefaultHeaders()
109 {
110 HttpConfiguration config = new HttpConfiguration();
111 config.setAll( new HttpMethodConfiguration().setUseDefaultHeaders( false ) );
112
113 TestWagon wagon = new TestWagon();
114 wagon.setHttpConfiguration( config );
115
116 HttpHead method = new HttpHead();
117 wagon.setHeaders( method );
118
119
120
121
122
123 Header header = method.getFirstHeader( "Cache-control" );
124 assertNull( header );
125
126 header = method.getFirstHeader( "Pragma" );
127 assertNull( header );
128 }
129
130 @Ignore("not sure how to test this")
131 public void testNTCredentialsWithUsernameNull()
132 throws AuthenticationException, ConnectionException
133 {
134 TestWagon wagon = new TestWagon();
135
136 Repository repository = new Repository( "mockRepoId", "mockRepoURL" );
137 wagon.connect( repository );
138
139 wagon.openConnection();
140
141 assertNull( wagon.getAuthenticationInfo().getUserName() );
142 assertNull( wagon.getAuthenticationInfo().getPassword() );
143
144
145 }
146
147 @Ignore("not sure how to test this")
148 public void testNTCredentialsNoNTDomain()
149 throws AuthenticationException, ConnectionException
150 {
151 TestWagon wagon = new TestWagon();
152
153 AuthenticationInfo authenticationInfo = new AuthenticationInfo();
154 String myUsernameNoNTDomain = "myUserNameNoNTDomain";
155 authenticationInfo.setUserName( myUsernameNoNTDomain );
156
157 String myPassword = "myPassword";
158 authenticationInfo.setPassword( myPassword );
159
160 Repository repository = new Repository( "mockRepoId", "mockRepoURL" );
161
162 wagon.connect( repository, authenticationInfo, (ProxyInfo) null );
163
164 wagon.openConnection();
165
166 assertEquals( myUsernameNoNTDomain, wagon.getAuthenticationInfo().getUserName() );
167 assertEquals( myPassword, wagon.getAuthenticationInfo().getPassword() );
168
169
170 }
171
172 @Ignore("not sure how to test this")
173 public void testNTCredentialsWithNTDomain()
174 throws AuthenticationException, ConnectionException
175 {
176 TestWagon wagon = new TestWagon();
177
178 AuthenticationInfo authenticationInfo = new AuthenticationInfo();
179 String myNTDomain = "myNTDomain";
180 String myUsername = "myUsername";
181 String myNTDomainAndUser = myNTDomain + "\\" + myUsername;
182 authenticationInfo.setUserName( myNTDomainAndUser );
183
184 String myPassword = "myPassword";
185 authenticationInfo.setPassword( myPassword );
186
187 Repository repository = new Repository( "mockRepoId", "mockRepoURL" );
188
189 wagon.connect( repository, authenticationInfo, (ProxyInfo) null );
190
191 wagon.openConnection();
192
193 assertEquals( myNTDomainAndUser, wagon.getAuthenticationInfo().getUserName() );
194 assertEquals( myPassword, wagon.getAuthenticationInfo().getPassword() );
195
196
197
198
199
200
201
202
203 }
204
205 private static final class TestWagon
206 extends WebDavWagon
207 {
208 @Override
209 public void fillOutputData( OutputData outputData )
210 throws TransferFailedException
211 {
212
213 }
214 }
215
216 }