1 package org.apache.maven.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.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 import org.junit.Test;
32 * SnapshotTransferTest
36 public class SnapshotTransferTest
37 extends AbstractProxyTestCase
40 public void testSnapshotNonExistant()
43 String path = "org/apache/maven/test/does-not-exist/1.0-SNAPSHOT/does-not-exist-1.0-SNAPSHOT.jar";
44 setupTestableManagedRepository( path );
46 File expectedFile = new File( managedDefaultDir, path );
47 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
49 expectedFile.delete();
50 assertFalse( expectedFile.exists() );
52 // Configure Connector (usually done within archiva.xml configuration)
53 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
55 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
56 assertNotDownloaded( downloadedFile );
57 assertNoTempFiles( expectedFile );
61 public void testTimestampDrivenSnapshotNotPresentAlready()
64 String path = "org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar";
65 setupTestableManagedRepository( path );
67 File expectedFile = new File( managedDefaultDir, path );
68 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
70 expectedFile.delete();
71 assertFalse( expectedFile.exists() );
73 // Configure Connector (usually done within archiva.xml configuration)
74 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
76 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
78 File proxiedFile = new File( REPOPATH_PROXIED1, path );
79 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
80 assertNoTempFiles( expectedFile );
84 public void testNewerTimestampDrivenSnapshotOnFirstRepo()
87 String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
88 setupTestableManagedRepository( path );
90 File expectedFile = new File( managedDefaultDir, path );
91 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
93 assertTrue( expectedFile.exists() );
94 expectedFile.setLastModified( getPastDate().getTime() );
96 // Configure Connector (usually done within archiva.xml configuration)
97 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
99 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
101 File proxiedFile = new File( REPOPATH_PROXIED1, path );
102 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
103 assertNoTempFiles( expectedFile );
107 public void testOlderTimestampDrivenSnapshotOnFirstRepo()
110 String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
111 setupTestableManagedRepository( path );
113 File expectedFile = new File( managedDefaultDir, path );
114 File remoteFile = new File( REPOPATH_PROXIED1, path );
116 setManagedNewerThanRemote( expectedFile, remoteFile );
118 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
120 // Configure Connector (usually done within archiva.xml configuration)
121 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
123 // Attempt to download.
124 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
126 // Should not have downloaded as managed is newer than remote.
127 assertNotDownloaded( downloadedFile );
128 assertNoTempFiles( expectedFile );
132 * TODO: Has problems with wagon implementation not preserving timestamp.
135 public void testNewerTimestampDrivenSnapshotOnSecondRepoThanFirstNotPresentAlready()
138 String path = "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar";
139 setupTestableManagedRepository( path );
141 File expectedFile = new File( managedDefaultDir, path );
142 ArtifactReference artifact = createArtifactReference( "default", path );
144 expectedFile.delete();
145 assertFalse( expectedFile.exists() );
147 // Create customized proxy / target repository
148 File targetProxyDir = saveTargetedRepositoryConfig( ID_PROXIED1_TARGET, REPOPATH_PROXIED1,
149 REPOPATH_PROXIED1_TARGET, "default" );
151 new File( targetProxyDir, path ).setLastModified( getPastDate().getTime() );
153 // Configure Connector (usually done within archiva.xml configuration)
154 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1_TARGET, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
155 SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
156 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
157 SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
159 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
161 // Should have downloaded the content from proxy2, as proxy1 has an old (by file.lastModified check) version.
162 File proxiedFile = new File( REPOPATH_PROXIED2, path );
163 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
164 assertNoTempFiles( expectedFile );
167 public void testOlderTimestampDrivenSnapshotOnSecondRepoThanFirstNotPresentAlready()
170 String path = "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar";
171 setupTestableManagedRepository( path );
173 File expectedFile = new File( managedDefaultDir, path );
174 ArtifactReference artifact = createArtifactReference( "default", path );
176 expectedFile.delete();
177 assertFalse( expectedFile.exists() );
179 // Create customized proxy / target repository
180 File targetProxyDir = saveTargetedRepositoryConfig( ID_PROXIED2_TARGET, REPOPATH_PROXIED2,
181 REPOPATH_PROXIED2_TARGET, "default" );
183 new File( targetProxyDir, path ).setLastModified( getPastDate().getTime() );
185 // Configure Connector (usually done within archiva.xml configuration)
186 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
187 SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
188 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2_TARGET, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
189 SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
191 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
193 File proxiedFile = new File( REPOPATH_PROXIED1_TARGET, path );
194 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
195 assertNoTempFiles( expectedFile );
199 public void testTimestampDrivenSnapshotNotExpired()
202 String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
203 setupTestableManagedRepository( path );
205 File expectedFile = new File( managedDefaultDir, path );
206 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
208 assertTrue( expectedFile.exists() );
210 File proxiedFile = new File( REPOPATH_PROXIED1, path );
211 proxiedFile.setLastModified( getFutureDate().getTime() );
213 // Configure Connector (usually done within archiva.xml configuration)
214 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
216 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
218 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
219 assertNoTempFiles( expectedFile );
223 public void testTimestampDrivenSnapshotNotUpdated()
226 String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
227 setupTestableManagedRepository( path );
229 File expectedFile = new File( managedDefaultDir, path );
230 File remoteFile = new File( REPOPATH_PROXIED1, path );
232 setManagedNewerThanRemote( expectedFile, remoteFile, 12000000 );
233 long expectedTimestamp = expectedFile.lastModified();
235 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
237 // Configure Connector (usually done within archiva.xml configuration)
238 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
240 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
242 assertNotDownloaded( downloadedFile );
243 assertNotModified( expectedFile, expectedTimestamp );
244 assertNoTempFiles( expectedFile );
248 public void testTimestampDrivenSnapshotNotPresentAlreadyExpiredCacheFailure()
251 String path = "org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar";
252 setupTestableManagedRepository( path );
254 File expectedFile = new File( managedDefaultDir, path );
255 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
257 expectedFile.delete();
258 assertFalse( expectedFile.exists() );
260 // Configure Connector (usually done within archiva.xml configuration)
261 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
262 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES , false);
263 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
264 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES , false);
266 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
268 File proxiedFile = new File( REPOPATH_PROXIED1, path );
269 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
270 assertNoTempFiles( expectedFile );
274 public void testMetadataDrivenSnapshotNotPresentAlready()
277 String path = "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/get-metadata-snapshot-1.0-20050831.101112-1.jar";
278 setupTestableManagedRepository( path );
280 File expectedFile = new File( managedDefaultDir, path );
281 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
283 expectedFile.delete();
284 assertFalse( expectedFile.exists() );
286 // Configure Connector (usually done within archiva.xml configuration)
287 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
289 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
291 File proxiedFile = new File( REPOPATH_PROXIED1, path );
292 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
293 assertNoTempFiles( expectedFile );
297 public void testGetMetadataDrivenSnapshotRemoteUpdate()
300 // Metadata driven snapshots (using a full timestamp) are treated like a release. It is the timing of the
301 // updates to the metadata files that triggers which will be downloaded
303 String path = "org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar";
304 setupTestableManagedRepository( path );
306 File expectedFile = new File( managedDefaultDir, path );
307 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
309 assertTrue( expectedFile.exists() );
311 expectedFile.setLastModified( getPastDate().getTime() );
313 // Configure Connector (usually done within archiva.xml configuration)
314 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
316 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
318 File proxiedFile = new File( REPOPATH_PROXIED1, path );
319 assertFileEquals( expectedFile, downloadedFile, proxiedFile );
320 assertNoTempFiles( expectedFile );