1 package org.apache.maven.archiva.proxy;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.archiva.model.ArtifactReference;
23 import org.apache.maven.archiva.policies.CachedFailuresPolicy;
24 import org.apache.maven.archiva.policies.ChecksumPolicy;
25 import org.apache.maven.archiva.policies.ReleasesPolicy;
26 import org.apache.maven.archiva.policies.SnapshotsPolicy;
27
28 import java.io.File;
29
30
31
32
33
34
35 public class SnapshotTransferTest
36 extends AbstractProxyTestCase
37 {
38 public void testSnapshotNonExistant()
39 throws Exception
40 {
41 String path = "org/apache/maven/test/does-not-exist/1.0-SNAPSHOT/does-not-exist-1.0-SNAPSHOT.jar";
42 setupTestableManagedRepository( path );
43
44 File expectedFile = new File( managedDefaultDir, path );
45 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
46
47 expectedFile.delete();
48 assertFalse( expectedFile.exists() );
49
50
51 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
52
53 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
54 assertNotDownloaded( downloadedFile );
55 assertNoTempFiles( expectedFile );
56 }
57
58 public void testTimestampDrivenSnapshotNotPresentAlready()
59 throws Exception
60 {
61 String path = "org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar";
62 setupTestableManagedRepository( path );
63
64 File expectedFile = new File( managedDefaultDir, path );
65 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
66
67 expectedFile.delete();
68 assertFalse( expectedFile.exists() );
69
70
71 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
72
73 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
74
75 File proxiedFile = new File( REPOPATH_PROXIED1, path );
76 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
77 assertNoTempFiles( expectedFile );
78 }
79
80 public void testNewerTimestampDrivenSnapshotOnFirstRepo()
81 throws Exception
82 {
83 String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
84 setupTestableManagedRepository( path );
85
86 File expectedFile = new File( managedDefaultDir, path );
87 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
88
89 assertTrue( expectedFile.exists() );
90 expectedFile.setLastModified( getPastDate().getTime() );
91
92
93 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
94
95 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
96
97 File proxiedFile = new File( REPOPATH_PROXIED1, path );
98 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
99 assertNoTempFiles( expectedFile );
100 }
101
102 public void testOlderTimestampDrivenSnapshotOnFirstRepo()
103 throws Exception
104 {
105 String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
106 setupTestableManagedRepository( path );
107
108 File expectedFile = new File( managedDefaultDir, path );
109 File remoteFile = new File( REPOPATH_PROXIED1, path );
110
111 setManagedNewerThanRemote( expectedFile, remoteFile );
112
113 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
114
115
116 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
117
118
119 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
120
121
122 assertNotDownloaded( downloadedFile );
123 assertNoTempFiles( expectedFile );
124 }
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193 public void testTimestampDrivenSnapshotNotExpired()
194 throws Exception
195 {
196 String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
197 setupTestableManagedRepository( path );
198
199 File expectedFile = new File( managedDefaultDir, path );
200 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
201
202 assertTrue( expectedFile.exists() );
203
204 File proxiedFile = new File( REPOPATH_PROXIED1, path );
205 proxiedFile.setLastModified( getFutureDate().getTime() );
206
207
208 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
209
210 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
211
212 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
213 assertNoTempFiles( expectedFile );
214 }
215
216 public void testTimestampDrivenSnapshotNotUpdated()
217 throws Exception
218 {
219 String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
220 setupTestableManagedRepository( path );
221
222 File expectedFile = new File( managedDefaultDir, path );
223 File remoteFile = new File( REPOPATH_PROXIED1, path );
224
225 setManagedNewerThanRemote( expectedFile, remoteFile );
226 long expectedTimestamp = expectedFile.lastModified();
227
228 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
229
230
231 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
232
233 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
234
235 assertNotDownloaded( downloadedFile );
236 assertNotModified( expectedFile, expectedTimestamp );
237 assertNoTempFiles( expectedFile );
238 }
239
240 public void testTimestampDrivenSnapshotNotPresentAlreadyExpiredCacheFailure()
241 throws Exception
242 {
243 String path = "org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar";
244 setupTestableManagedRepository( path );
245
246 File expectedFile = new File( managedDefaultDir, path );
247 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
248
249 expectedFile.delete();
250 assertFalse( expectedFile.exists() );
251
252
253 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
254 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES , false);
255 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
256 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES , false);
257
258 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
259
260 File proxiedFile = new File( REPOPATH_PROXIED1, path );
261 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
262 assertNoTempFiles( expectedFile );
263 }
264
265 public void testMetadataDrivenSnapshotNotPresentAlready()
266 throws Exception
267 {
268 String path = "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/get-metadata-snapshot-1.0-20050831.101112-1.jar";
269 setupTestableManagedRepository( path );
270
271 File expectedFile = new File( managedDefaultDir, path );
272 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
273
274 expectedFile.delete();
275 assertFalse( expectedFile.exists() );
276
277
278 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
279
280 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
281
282 File proxiedFile = new File( REPOPATH_PROXIED1, path );
283 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
284 assertNoTempFiles( expectedFile );
285 }
286
287 public void testGetMetadataDrivenSnapshotRemoteUpdate()
288 throws Exception
289 {
290
291
292
293 String path = "org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar";
294 setupTestableManagedRepository( path );
295
296 File expectedFile = new File( managedDefaultDir, path );
297 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
298
299 assertTrue( expectedFile.exists() );
300
301 expectedFile.setLastModified( getPastDate().getTime() );
302
303
304 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
305
306 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
307
308 File proxiedFile = new File( REPOPATH_PROXIED1, path );
309 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
310 assertNoTempFiles( expectedFile );
311 }
312 }