1 package org.apache.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.archiva.model.ArtifactReference;
23 import org.apache.archiva.policies.CachedFailuresPolicy;
24 import org.apache.archiva.policies.ChecksumPolicy;
25 import org.apache.archiva.policies.ReleasesPolicy;
26 import org.apache.archiva.policies.SnapshotsPolicy;
27 import org.junit.Test;
28
29 import java.io.File;
30
31 import static org.junit.Assert.assertFalse;
32 import static org.junit.Assert.assertTrue;
33
34
35
36
37
38
39 public class SnapshotTransferTest
40 extends AbstractProxyTestCase
41 {
42 @Test
43 public void testSnapshotNonExistant()
44 throws Exception
45 {
46 String path = "org/apache/maven/test/does-not-exist/1.0-SNAPSHOT/does-not-exist-1.0-SNAPSHOT.jar";
47 setupTestableManagedRepository( path );
48
49 File expectedFile = new File( managedDefaultDir, path );
50 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
51
52 expectedFile.delete();
53 assertFalse( expectedFile.exists() );
54
55
56 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
57
58 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
59 assertNotDownloaded( downloadedFile );
60 assertNoTempFiles( expectedFile );
61 }
62
63 @Test
64 public void testTimestampDrivenSnapshotNotPresentAlready()
65 throws Exception
66 {
67 String path = "org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar";
68 setupTestableManagedRepository( path );
69
70 File expectedFile = new File( managedDefaultDir, path );
71 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
72
73 expectedFile.delete();
74 assertFalse( expectedFile.exists() );
75
76
77 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
78
79 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
80
81 File proxiedFile = new File( REPOPATH_PROXIED1, path );
82 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
83 assertNoTempFiles( expectedFile );
84 }
85
86 @Test
87 public void testNewerTimestampDrivenSnapshotOnFirstRepo()
88 throws Exception
89 {
90 String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
91 setupTestableManagedRepository( path );
92
93 File expectedFile = new File( managedDefaultDir, path );
94 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
95
96 assertTrue( expectedFile.exists() );
97 expectedFile.setLastModified( getPastDate().getTime() );
98
99
100 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
101
102 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
103
104 File proxiedFile = new File( REPOPATH_PROXIED1, path );
105 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
106 assertNoTempFiles( expectedFile );
107 }
108
109 @Test
110 public void testOlderTimestampDrivenSnapshotOnFirstRepo()
111 throws Exception
112 {
113 String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
114 setupTestableManagedRepository( path );
115
116 File expectedFile = new File( managedDefaultDir, path );
117 File remoteFile = new File( REPOPATH_PROXIED1, path );
118
119 setManagedNewerThanRemote( expectedFile, remoteFile );
120
121 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
122
123
124 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
125
126
127 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
128
129
130 assertNotDownloaded( downloadedFile );
131 assertNoTempFiles( expectedFile );
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
194
195
196
197
198
199
200
201 @Test
202 public void testTimestampDrivenSnapshotNotExpired()
203 throws Exception
204 {
205 String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
206 setupTestableManagedRepository( path );
207
208 File expectedFile = new File( managedDefaultDir, path );
209 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
210
211 assertTrue( expectedFile.exists() );
212
213 File proxiedFile = new File( REPOPATH_PROXIED1, path );
214 proxiedFile.setLastModified( getFutureDate().getTime() );
215
216
217 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
218
219 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
220
221 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
222 assertNoTempFiles( expectedFile );
223 }
224
225 @Test
226 public void testTimestampDrivenSnapshotNotUpdated()
227 throws Exception
228 {
229 String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
230 setupTestableManagedRepository( path );
231
232 File expectedFile = new File( managedDefaultDir, path );
233 File remoteFile = new File( REPOPATH_PROXIED1, path );
234
235 setManagedNewerThanRemote( expectedFile, remoteFile, 12000000 );
236 long expectedTimestamp = expectedFile.lastModified();
237
238 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
239
240
241 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
242
243 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
244
245 assertNotDownloaded( downloadedFile );
246 assertNotModified( expectedFile, expectedTimestamp );
247 assertNoTempFiles( expectedFile );
248 }
249
250 @Test
251 public void testTimestampDrivenSnapshotNotPresentAlreadyExpiredCacheFailure()
252 throws Exception
253 {
254 String path = "org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar";
255 setupTestableManagedRepository( path );
256
257 File expectedFile = new File( managedDefaultDir, path );
258 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
259
260 expectedFile.delete();
261 assertFalse( expectedFile.exists() );
262
263
264 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
265 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES , false);
266 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
267 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES , false);
268
269 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
270
271 File proxiedFile = new File( REPOPATH_PROXIED1, path );
272 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
273 assertNoTempFiles( expectedFile );
274 }
275
276 @Test
277 public void testMetadataDrivenSnapshotNotPresentAlready()
278 throws Exception
279 {
280 String path = "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/get-metadata-snapshot-1.0-20050831.101112-1.jar";
281 setupTestableManagedRepository( path );
282
283 File expectedFile = new File( managedDefaultDir, path );
284 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
285
286 expectedFile.delete();
287 assertFalse( expectedFile.exists() );
288
289
290 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
291
292 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
293
294 File proxiedFile = new File( REPOPATH_PROXIED1, path );
295 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
296 assertNoTempFiles( expectedFile );
297 }
298
299 @Test
300 public void testGetMetadataDrivenSnapshotRemoteUpdate()
301 throws Exception
302 {
303
304
305
306 String path = "org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar";
307 setupTestableManagedRepository( path );
308
309 File expectedFile = new File( managedDefaultDir, path );
310 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
311
312 assertTrue( expectedFile.exists() );
313
314 expectedFile.setLastModified( getPastDate().getTime() );
315
316
317 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
318
319 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
320
321 File proxiedFile = new File( REPOPATH_PROXIED1, path );
322 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
323 assertNoTempFiles( expectedFile );
324 }
325 }