1 package org.apache.archiva.proxy;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
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;
31 import static org.junit.Assert.assertFalse;
32 import static org.junit.Assert.assertTrue;
35 * SnapshotTransferTest
39 public class SnapshotTransferTest
40 extends AbstractProxyTestCase
43 public void testSnapshotNonExistant()
46 String path = "org/apache/maven/test/does-not-exist/1.0-SNAPSHOT/does-not-exist-1.0-SNAPSHOT.jar";
47 setupTestableManagedRepository( path );
49 File expectedFile = new File( managedDefaultDir, path );
50 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
52 expectedFile.delete();
53 assertFalse( expectedFile.exists() );
55 // Configure Connector (usually done within archiva.xml configuration)
56 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
58 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
59 assertNotDownloaded( downloadedFile );
60 assertNoTempFiles( expectedFile );
64 public void testTimestampDrivenSnapshotNotPresentAlready()
67 String path = "org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar";
68 setupTestableManagedRepository( path );
70 File expectedFile = new File( managedDefaultDir, path );
71 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
73 expectedFile.delete();
74 assertFalse( expectedFile.exists() );
76 // Configure Connector (usually done within archiva.xml configuration)
77 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
79 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
81 File proxiedFile = new File( REPOPATH_PROXIED1, path );
82 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
83 assertNoTempFiles( expectedFile );
87 public void testNewerTimestampDrivenSnapshotOnFirstRepo()
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 );
93 File expectedFile = new File( managedDefaultDir, path );
94 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
96 assertTrue( expectedFile.exists() );
97 expectedFile.setLastModified( getPastDate().getTime() );
99 // Configure Connector (usually done within archiva.xml configuration)
100 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
102 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
104 File proxiedFile = new File( REPOPATH_PROXIED1, path );
105 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
106 assertNoTempFiles( expectedFile );
110 public void testOlderTimestampDrivenSnapshotOnFirstRepo()
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 );
116 File expectedFile = new File( managedDefaultDir, path );
117 File remoteFile = new File( REPOPATH_PROXIED1, path );
119 setManagedNewerThanRemote( expectedFile, remoteFile );
121 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
123 // Configure Connector (usually done within archiva.xml configuration)
124 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
126 // Attempt to download.
127 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
129 // Should not have downloaded as managed is newer than remote.
130 assertNotDownloaded( downloadedFile );
131 assertNoTempFiles( expectedFile );
135 * TODO: Has problems with wagon implementation not preserving timestamp.
138 public void testNewerTimestampDrivenSnapshotOnSecondRepoThanFirstNotPresentAlready()
141 String path = "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar";
142 setupTestableManagedRepository( path );
144 File expectedFile = new File( managedDefaultDir, path );
145 ArtifactReference artifact = createArtifactReference( "default", path );
147 expectedFile.delete();
148 assertFalse( expectedFile.exists() );
150 // Create customized proxy / target repository
151 File targetProxyDir = saveTargetedRepositoryConfig( ID_PROXIED1_TARGET, REPOPATH_PROXIED1,
152 REPOPATH_PROXIED1_TARGET, "default" );
154 new File( targetProxyDir, path ).setLastModified( getPastDate().getTime() );
156 // Configure Connector (usually done within archiva.xml configuration)
157 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1_TARGET, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
158 SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
159 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
160 SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
162 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
164 // Should have downloaded the content from proxy2, as proxy1 has an old (by file.lastModified check) version.
165 File proxiedFile = new File( REPOPATH_PROXIED2, path );
166 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
167 assertNoTempFiles( expectedFile );
170 public void testOlderTimestampDrivenSnapshotOnSecondRepoThanFirstNotPresentAlready()
173 String path = "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar";
174 setupTestableManagedRepository( path );
176 File expectedFile = new File( managedDefaultDir, path );
177 ArtifactReference artifact = createArtifactReference( "default", path );
179 expectedFile.delete();
180 assertFalse( expectedFile.exists() );
182 // Create customized proxy / target repository
183 File targetProxyDir = saveTargetedRepositoryConfig( ID_PROXIED2_TARGET, REPOPATH_PROXIED2,
184 REPOPATH_PROXIED2_TARGET, "default" );
186 new File( targetProxyDir, path ).setLastModified( getPastDate().getTime() );
188 // Configure Connector (usually done within archiva.xml configuration)
189 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
190 SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
191 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2_TARGET, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
192 SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
194 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
196 File proxiedFile = new File( REPOPATH_PROXIED1_TARGET, path );
197 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
198 assertNoTempFiles( expectedFile );
202 public void testTimestampDrivenSnapshotNotExpired()
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 );
208 File expectedFile = new File( managedDefaultDir, path );
209 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
211 assertTrue( expectedFile.exists() );
213 File proxiedFile = new File( REPOPATH_PROXIED1, path );
214 proxiedFile.setLastModified( getFutureDate().getTime() );
216 // Configure Connector (usually done within archiva.xml configuration)
217 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
219 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
221 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
222 assertNoTempFiles( expectedFile );
226 public void testTimestampDrivenSnapshotNotUpdated()
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 );
232 File expectedFile = new File( managedDefaultDir, path );
233 File remoteFile = new File( REPOPATH_PROXIED1, path );
235 setManagedNewerThanRemote( expectedFile, remoteFile, 12000000 );
236 long expectedTimestamp = expectedFile.lastModified();
238 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
240 // Configure Connector (usually done within archiva.xml configuration)
241 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
243 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
245 assertNotDownloaded( downloadedFile );
246 assertNotModified( expectedFile, expectedTimestamp );
247 assertNoTempFiles( expectedFile );
251 public void testTimestampDrivenSnapshotNotPresentAlreadyExpiredCacheFailure()
254 String path = "org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar";
255 setupTestableManagedRepository( path );
257 File expectedFile = new File( managedDefaultDir, path );
258 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
260 expectedFile.delete();
261 assertFalse( expectedFile.exists() );
263 // Configure Connector (usually done within archiva.xml configuration)
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);
269 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
271 File proxiedFile = new File( REPOPATH_PROXIED1, path );
272 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
273 assertNoTempFiles( expectedFile );
277 public void testMetadataDrivenSnapshotNotPresentAlready()
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 );
283 File expectedFile = new File( managedDefaultDir, path );
284 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
286 expectedFile.delete();
287 assertFalse( expectedFile.exists() );
289 // Configure Connector (usually done within archiva.xml configuration)
290 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
292 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
294 File proxiedFile = new File( REPOPATH_PROXIED1, path );
295 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
296 assertNoTempFiles( expectedFile );
300 public void testGetMetadataDrivenSnapshotRemoteUpdate()
303 // Metadata driven snapshots (using a full timestamp) are treated like a release. It is the timing of the
304 // updates to the metadata files that triggers which will be downloaded
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 );
309 File expectedFile = new File( managedDefaultDir, path );
310 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
312 assertTrue( expectedFile.exists() );
314 expectedFile.setLastModified( getPastDate().getTime() );
316 // Configure Connector (usually done within archiva.xml configuration)
317 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
319 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
321 File proxiedFile = new File( REPOPATH_PROXIED1, path );
322 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
323 assertNoTempFiles( expectedFile );