import org.apache.maven.archiva.configuration.NetworkProxyConfiguration;
import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
import org.apache.maven.archiva.model.ArtifactReference;
+import org.apache.maven.archiva.model.Keys;
import org.apache.maven.archiva.model.ProjectReference;
import org.apache.maven.archiva.model.RepositoryURL;
import org.apache.maven.archiva.model.VersionedReference;
RemoteRepositoryContent targetRepository = connector.getTargetRepository();
String targetPath = targetRepository.toPath( artifact );
- File downloadedFile = transferFile( connector, targetRepository, targetPath, localFile, requestProperties );
+ try
+ {
+ File downloadedFile = transferFile( connector, targetRepository, targetPath, localFile,
+ requestProperties );
- if ( fileExists( downloadedFile ) )
+ if ( fileExists( downloadedFile ) )
+ {
+ getLogger().debug( "Successfully transferred: " + downloadedFile.getAbsolutePath() );
+ return downloadedFile;
+ }
+ }
+ catch ( NotFoundException e )
{
- getLogger().debug( "Successfully transfered: " + downloadedFile.getAbsolutePath() );
- return downloadedFile;
+ getLogger().debug( "Artifact " + Keys.toKey( artifact ) + " not found on repository \""
+ + targetRepository.getRepository().getId() + "\"." );
+ }
+ catch ( NotModifiedException e )
+ {
+ getLogger().debug( "Artifact " + Keys.toKey( artifact ) + " not updated on repository \""
+ + targetRepository.getRepository().getId() + "\"." );
}
}
+ getLogger().debug( "Exhausted all target repositories, artifact " + Keys.toKey( artifact ) + " not found." );
return null;
}
File localRepoFile = toLocalRepoFile( repository, targetRepository, targetPath );
long originalMetadataTimestamp = getLastModified( localRepoFile );
- transferFile( connector, targetRepository, targetPath, localRepoFile, requestProperties );
+
+ try
+ {
+ transferFile( connector, targetRepository, targetPath, localRepoFile, requestProperties );
- if ( hasBeenUpdated( localRepoFile, originalMetadataTimestamp ) )
+ if ( hasBeenUpdated( localRepoFile, originalMetadataTimestamp ) )
+ {
+ metadataNeedsUpdating = true;
+ }
+ }
+ catch ( NotFoundException e )
+ {
+ getLogger().debug( "Versioned Metadata " + Keys.toKey( metadata )
+ + " not found on remote repository \""
+ + targetRepository.getRepository().getId() + "\"." );
+ }
+ catch ( NotModifiedException e )
{
- metadataNeedsUpdating = true;
+ getLogger().debug( "Versioned Metadata " + Keys.toKey( metadata )
+ + " not updated on remote repository \""
+ + targetRepository.getRepository().getId() + "\"." );
}
}
* Fetch from the proxies a metadata.xml file for the groupId:artifactId metadata contents.
*
* @return the (local) metadata file that was fetched/merged/updated, or null if no metadata file exists.
+ * @throws ProxyException if there was a problem fetching the metadata file.
*/
public File fetchFromProxies( ManagedRepositoryContent repository, ProjectReference metadata )
- throws ProxyException
+ throws NotFoundException, NotModifiedException, ProxyException
{
File localFile = toLocalFile( repository, metadata );
File localRepoFile = toLocalRepoFile( repository, targetRepository, targetPath );
long originalMetadataTimestamp = getLastModified( localRepoFile );
- transferFile( connector, targetRepository, targetPath, localRepoFile, requestProperties );
-
- if ( hasBeenUpdated( localRepoFile, originalMetadataTimestamp ) )
+ try
+ {
+ transferFile( connector, targetRepository, targetPath, localRepoFile, requestProperties );
+
+ if ( hasBeenUpdated( localRepoFile, originalMetadataTimestamp ) )
+ {
+ metadataNeedsUpdating = true;
+ }
+ }
+ catch ( NotFoundException e )
+ {
+ getLogger().debug( "Project Metadata " + Keys.toKey( metadata ) + " not found on remote repository \""
+ + targetRepository.getRepository().getId() + "\"." );
+ }
+ catch ( NotModifiedException e )
{
- metadataNeedsUpdating = true;
+ getLogger().debug( "Project Metadata " + Keys.toKey( metadata )
+ + " not updated on remote repository \""
+ + targetRepository.getRepository().getId() + "\"." );
}
+
}
if ( hasBeenUpdated( localFile, originalTimestamp ) )
* @param localFile the local file to place the downloaded resource into
* @param requestProperties the request properties to utilize for policy handling.
* @return the local file that was downloaded, or null if not downloaded.
+ * @throws NotFoundException if the file was not found on the remote repository.
+ * @throws NotModifiedException if the localFile was present, and the resource was present on remote repository,
+ * but the remote resource is not newer than the local File.
* @throws ProxyException if transfer was unsuccessful.
*/
private File transferFile( ProxyConnector connector, RemoteRepositoryContent remoteRepository, String remotePath,
File localFile, Properties requestProperties )
- throws ProxyException
+ throws NotFoundException, NotModifiedException, ProxyException
{
String url = remoteRepository.getURL().getUrl() + remotePath;
requestProperties.setProperty( "url", url );
transferChecksum( wagon, remoteRepository, remotePath, localFile, ".md5" );
}
}
- catch ( ResourceDoesNotExistException e )
+ catch ( NotFoundException e )
{
// Do not cache url here.
- return null;
+ throw e;
}
- catch ( WagonException e )
+ catch ( NotModifiedException e )
+ {
+ // Do not cache url here.
+ throw e;
+ }
+ catch ( ProxyException e )
{
urlFailureCache.cacheFailure( url );
- return null;
+ throw e;
}
finally
{
}
/**
+ * <p>
* Quietly transfer the checksum file from the remote repository to the local file.
- * <p/>
- * NOTE: This will not throw a WagonException if the checksum is unable to be downloaded.
+ * </p>
*
* @param wagon the wagon instance (should already be connected) to use.
* @param remoteRepository the remote repository to transfer from.
transferSimpleFile( wagon, remoteRepository, remotePath + type, hashFile );
getLogger().debug( "Checksum" + type + " Downloaded: " + hashFile );
}
- catch ( ResourceDoesNotExistException e )
+ catch ( NotFoundException e )
{
- getLogger().debug( "Checksum" + type + " Not Download: " + e.getMessage() );
+ getLogger().debug( "Transfer failed, checksum not found: " + url );
+ // Consume it, do not pass this on.
}
- catch ( WagonException e )
+ catch ( NotModifiedException e )
+ {
+ getLogger().debug( "Transfer skipped, checksum not modified: " + url );
+ // Consume it, do not pass this on.
+ }
+ catch ( ProxyException e )
{
urlFailureCache.cacheFailure( url + type );
getLogger().warn( "Transfer failed on checksum: " + url + " : " + e.getMessage(), e );
+ // Critical issue, pass it on.
+ throw e;
}
}
*/
private File transferSimpleFile( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath,
File localFile )
- throws ProxyException, WagonException
+ throws NotFoundException, NotModifiedException, ProxyException
{
assert ( remotePath != null );
boolean success = false;
- if ( localFile.exists() )
+ if ( !localFile.exists() )
{
getLogger().debug( "Retrieving " + remotePath + " from " + remoteRepository.getRepository().getName() );
wagon.get( remotePath, temp );
success = wagon.getIfNewer( remotePath, temp, localFile.lastModified() );
if ( !success )
{
- getLogger().debug(
- "Not downloaded, as local file is newer than remote side: "
- + localFile.getAbsolutePath() );
+ throw new NotModifiedException( "Not downloaded, as local file is newer than remote side: "
+ + localFile.getAbsolutePath() );
}
- else if ( temp.exists() )
+
+ if ( temp.exists() )
{
getLogger().debug( "Downloaded successfully." );
moveTempToTarget( temp, localFile );
}
catch ( ResourceDoesNotExistException e )
{
- getLogger().debug( "Resource [" + remoteRepository.getURL() + "/" + remotePath + "] does not exist: "
- + e.getMessage() );
- throw e;
+ throw new NotFoundException( "Resource [" + remoteRepository.getURL() + "/" + remotePath
+ + "] does not exist: " + e.getMessage(), e );
}
catch ( WagonException e )
{
- getLogger().warn( "Download failure on resource [" + remoteRepository.getURL() + "/" + remotePath + "]:"
+ throw new ProxyException( "Download failure on resource [" + remoteRepository.getURL() + "/" + remotePath + "]:"
+ e.getMessage(), e );
- throw e;
}
finally
{
--- /dev/null
+package org.apache.maven.archiva.proxy;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * NotFoundException - thrown when the resource requested was not found on the remote repository.
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class NotFoundException
+ extends ProxyException
+{
+ public NotFoundException( String message, Throwable t )
+ {
+ super( message, t );
+ }
+
+ public NotFoundException( String message )
+ {
+ super( message );
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.proxy;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * <p>
+ * NotModifiedException - thrown when the resource requested was found on the remote repository, but
+ * the remote repository reported that the copy we have in our managed repository is newer than
+ * the one present on the remote repository.
+ * </p>
+ * <p>
+ * Similar in scope to the <code>HTTP 304 Not Modified</code> response code.
+ * </p>
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class NotModifiedException
+ extends ProxyException
+{
+
+ public NotModifiedException( String message )
+ {
+ super( message );
+ }
+
+ public NotModifiedException( String message, Throwable t )
+ {
+ super( message, t );
+ }
+}
* under the License.
*/
-import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.model.ProjectReference;
import org.apache.maven.archiva.model.VersionedReference;
assertNotNull( "Expected File should not be null.", expectedFile );
assertNotNull( "Actual File should not be null.", actualFile );
- assertTrue( "Check file exists.", actualFile.exists() );
+ assertTrue( "Check actual file exists.", actualFile.exists() );
+ assertEquals( "Check filename path is appropriate.", expectedFile.getCanonicalPath(), actualFile.getCanonicalPath() );
assertEquals( "Check file path matches.", expectedFile.getAbsolutePath(), actualFile.getAbsolutePath() );
String expectedContents = FileUtils.readFileToString( sourceFile, null );
copyDirectoryStructure( sourceDir, destDir );
}
+ protected void setManagedNewerThanRemote( File managedFile, File remoteFile )
+ {
+ assertTrue( "Managed File should exist: ", managedFile.exists() );
+ assertTrue( "Remote File should exist: ", remoteFile.exists() );
+
+ managedFile.setLastModified( remoteFile.lastModified() + 55000 );
+ }
+
+ protected void setManagedOlderThanRemote( File managedFile, File remoteFile )
+ {
+ assertTrue( "Managed File should exist: ", managedFile.exists() );
+ assertTrue( "Remote File should exist: ", remoteFile.exists() );
+
+ managedFile.setLastModified( remoteFile.lastModified() - 55000 );
+ }
+
+ protected void assertNotModified( File file, long expectedModificationTime )
+ {
+ assertEquals( "File <" + file.getAbsolutePath() + "> not have been modified.",
+ expectedModificationTime, file.lastModified() );
+ }
+
+ protected void assertNotExistsInManagedLegacyRepo( File file )
+ throws Exception
+ {
+ String managedLegacyPath = managedLegacyDir.getCanonicalPath();
+ String testFile = file.getCanonicalPath();
+
+ assertTrue( "Unit Test Failure: File <" + testFile
+ + "> should be have been defined within the legacy managed path of <" + managedLegacyPath + ">", testFile
+ .startsWith( managedLegacyPath ) );
+
+ assertFalse( "File < " + testFile + "> should not exist in managed legacy repository.", file.exists() );
+ }
+
+ protected void assertNotExistsInManagedDefaultRepo( File file )
+ throws Exception
+ {
+ String managedDefaultPath = managedDefaultDir.getCanonicalPath();
+ String testFile = file.getCanonicalPath();
+
+ assertTrue( "Unit Test Failure: File <" + testFile
+ + "> should be have been defined within the managed default path of <" + managedDefaultPath + ">", testFile
+ .startsWith( managedDefaultPath ) );
+
+ assertFalse( "File < " + testFile + "> should not exist in managed default repository.", file.exists() );
+ }
+
protected static Date getFutureDate()
throws ParseException
{
import org.apache.maven.archiva.policies.ReleasesPolicy;
import org.apache.maven.archiva.policies.SnapshotsPolicy;
import org.apache.maven.archiva.policies.urlcache.UrlFailureCache;
-import org.apache.maven.wagon.TransferFailedException;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
import java.io.File;
{
String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar";
File expectedFile = new File( managedDefaultDir.getAbsoluteFile(), path );
+ setupTestableManagedRepository( path );
+
+ assertNotExistsInManagedDefaultRepo( expectedFile );
+
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
- expectedFile.delete();
- assertFalse( expectedFile.exists() );
-
// Configure Repository (usually done within archiva.xml configuration)
saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" );
saveRemoteRepositoryConfig( "badproxied2", "Bad Proxied 2", "test://bad.machine.com/repo/", "default" );
saveConnector( ID_DEFAULT_MANAGED, "badproxied2", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
SnapshotsPolicy.IGNORED, CachedFailuresPolicy.CACHED );
- wagonMock.getIfNewer( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ), 0 );
- TransferFailedException failedException = new TransferFailedException( "transfer failed" );
- wagonMockControl.setThrowable( failedException );
+ wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) );
+ wagonMockControl.setThrowable( new ResourceDoesNotExistException( "resource does not exist." ), 2 );
wagonMockControl.replay();
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
- assertNotDownloaded( downloadedFile );
-
wagonMockControl.verify();
+
+ assertNotDownloaded( downloadedFile );
assertNoTempFiles( expectedFile );
}
{
String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar";
File expectedFile = new File( managedDefaultDir.getAbsoluteFile(), path );
- ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
+
+ setupTestableManagedRepository( path );
- expectedFile.delete();
- assertFalse( expectedFile.exists() );
+ assertNotExistsInManagedDefaultRepo( expectedFile );
+
+ ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
// Configure Repository (usually done within archiva.xml configuration)
saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" );
saveConnector( ID_DEFAULT_MANAGED, "badproxied2", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
- wagonMock.getIfNewer( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ), 0 );
- TransferFailedException failedException = new TransferFailedException( "transfer failed" );
- wagonMockControl.setThrowable( failedException );
+ wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) );
+ wagonMockControl.setThrowable( new ResourceDoesNotExistException( "resource does not exist." ), 2 );
wagonMockControl.replay();
import org.apache.maven.archiva.policies.ChecksumPolicy;
import org.apache.maven.archiva.policies.ReleasesPolicy;
import org.apache.maven.archiva.policies.SnapshotsPolicy;
-import org.apache.maven.wagon.TransferFailedException;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
import java.io.File;
"3f7341545f21226b6f49a3c2704cb9be get-default-layout-1.0.jar" );
}
- public void testGetChecksumTransferFailed()
+ public void testGetChecksumNotFoundOnRemote()
throws Exception
{
String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar";
saveConnector( ID_DEFAULT_MANAGED, "badproxied", ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
- wagonMock.getIfNewer( path, new File( expectedFile.getAbsolutePath() + ".tmp" ), 0 );
- wagonMockControl.setReturnValue( true );
- wagonMock.getIfNewer( path + ".sha1", new File( expectedFile.getAbsolutePath() + ".sha1.tmp" ), 0 );
- wagonMockControl.setReturnValue( true );
- wagonMock.getIfNewer( path + ".md5", new File( expectedFile.getAbsolutePath() + ".md5.tmp" ), 0 );
- wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) );
+ wagonMock.get( path, new File( expectedFile.getAbsolutePath() + ".tmp" ) );
+ wagonMockControl.setVoidCallable();
+ wagonMock.get( path + ".sha1", new File( expectedFile.getAbsolutePath() + ".sha1.tmp" ) );
+ wagonMockControl.setVoidCallable();
+ wagonMock.get( path + ".md5", new File( expectedFile.getAbsolutePath() + ".md5.tmp" ) );
+ wagonMockControl.setThrowable( new ResourceDoesNotExistException( "Resource does not exist." ) );
wagonMockControl.replay();
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path );
- ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
+ File remoteFile = new File( REPOPATH_PROXIED1, path );
+
+ setManagedOlderThanRemote( expectedFile, remoteFile );
- assertTrue( expectedFile.exists() );
+ ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path );
- ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
+ File remoteFile = new File( REPOPATH_PROXIED1, path );
- assertTrue( expectedFile.exists() );
+ setManagedOlderThanRemote( expectedFile, remoteFile );
+
+ ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
// Configure Connector (usually done within archiva.xml configuration)
- saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.IGNORED,
+ saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FAIL, ReleasesPolicy.IGNORED,
SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path );
- ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
+ File remoteFile = new File( REPOPATH_PROXIED1, path );
+
+ setManagedOlderThanRemote( expectedFile, remoteFile );
- assertTrue( expectedFile.exists() );
+ ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
import org.apache.maven.archiva.policies.ChecksumPolicy;
import org.apache.maven.archiva.policies.ReleasesPolicy;
import org.apache.maven.archiva.policies.SnapshotsPolicy;
-import org.apache.maven.wagon.TransferFailedException;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
import java.io.File;
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
// Ensure file isn't present first.
- expectedFile.delete();
- assertFalse( expectedFile.exists() );
+ assertNotExistsInManagedDefaultRepo( expectedFile );
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ONCE, SnapshotsPolicy.ONCE,
}
/**
- * The attempt here should result in file being transferred.
- * <p/>
- * The file exists locally, and the policy is IGNORE.
+ * <p>
+ * Request a file, that exists locally, and remotely.
+ * </p>
+ * <p>
+ * All policies are set to IGNORE.
+ * </p>
+ * <p>
+ * Managed file is newer than remote file.
+ * </p>
+ * <p>
+ * Transfer should not have occured, as managed file is newer.
+ * </p>
*
* @throws Exception
*/
- public void testGetDefaultLayoutAlreadyPresentPolicyIgnored()
+ public void testGetDefaultLayoutAlreadyPresentNewerThanRemotePolicyIgnored()
throws Exception
{
String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path );
+ File remoteFile = new File( REPOPATH_PROXIED1, path );
+
+ // Set the managed File to be newer than local.
+ setManagedNewerThanRemote( expectedFile, remoteFile );
long originalModificationTime = expectedFile.lastModified();
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
// Attempt the proxy fetch.
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+ assertNotDownloaded( downloadedFile );
+ assertNotModified( expectedFile, originalModificationTime );
+ assertNoTempFiles( expectedFile );
+ }
+
+ /**
+ * <p>
+ * Request a file, that exists locally, and remotely.
+ * </p>
+ * <p>
+ * All policies are set to IGNORE.
+ * </p>
+ * <p>
+ * Managed file is older than Remote file.
+ * </p>
+ * <p>
+ * Transfer should have occured, as managed file is older than remote.
+ * </p>
+ *
+ * @throws Exception
+ */
+ public void testGetDefaultLayoutAlreadyPresentOlderThanRemotePolicyIgnored()
+ throws Exception
+ {
+ String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
+ setupTestableManagedRepository( path );
+
+ File expectedFile = new File( managedDefaultDir, path );
+ File remoteFile = new File( REPOPATH_PROXIED1, path );
+
+ // Set the managed file to be newer than remote file.
+ setManagedOlderThanRemote( expectedFile, remoteFile );
+
+ ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
+
+ assertTrue( expectedFile.exists() );
+
+ // Configure Connector (usually done within archiva.xml configuration)
+ saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
+ SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+
+ // Attempt the proxy fetch.
+ File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+
File proxiedFile = new File( REPOPATH_PROXIED1, path );
assertFileEquals( expectedFile, downloadedFile, proxiedFile );
-
- long proxiedLastModified = proxiedFile.lastModified();
- long downloadedLastModified = downloadedFile.lastModified();
- assertFalse( "Check file timestamp is not that of proxy:", proxiedLastModified == downloadedLastModified );
-
- if ( originalModificationTime != downloadedLastModified )
- {
- /* On some systems the timestamp functions are not accurate enough.
- * This delta is the amount of milliseconds of 'fudge factor' we allow for
- * the unit test to still be considered 'passed'.
- */
- int delta = 20000;
-
- long hirange = originalModificationTime + ( delta / 2 );
- long lorange = originalModificationTime - ( delta / 2 );
-
- if ( ( downloadedLastModified < lorange ) || ( downloadedLastModified > hirange ) )
- {
- fail( "Check file timestamp is that of original managed file: expected within range lo:<" + lorange +
- "> hi:<" + hirange + "> but was:<" + downloadedLastModified + ">" );
- }
- }
assertNoTempFiles( expectedFile );
}
File expectedFile = new File( managedDefaultDir, path );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
- expectedFile.delete();
- assertFalse( expectedFile.exists() );
+ assertNotExistsInManagedDefaultRepo( expectedFile );
// Configure Connector (usually done within archiva.xml configuration)
- saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
- SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
- saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
- SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+ saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1 );
+ saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2 );
// Attempt the proxy fetch.
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File expectedFile = new File( managedDefaultDir, path );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
- expectedFile.delete();
- assertFalse( expectedFile.exists() );
+ assertNotExistsInManagedDefaultRepo( expectedFile );
// Configure Connector (usually done within archiva.xml configuration)
- saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
- SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
- saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
- SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+ saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1 );
+ saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2 );
// Attempt the proxy fetch.
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File expectedFile = new File( managedDefaultDir, path );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
- assertFalse( expectedFile.exists() );
+ assertNotExistsInManagedDefaultRepo( expectedFile );
// Configure Connector (usually done within archiva.xml configuration)
- saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
- SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
- saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
- SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
- saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
- SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+ saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1 );
+ saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2 );
+ saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED );
// Attempt the proxy fetch.
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File expectedFile = new File( managedDefaultDir, path );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
- expectedFile.delete();
- assertFalse( expectedFile.exists() );
+ assertNotExistsInManagedDefaultRepo( expectedFile );
// Configure Repository (usually done within archiva.xml configuration)
saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "test://bad.machine.com/repo/", "default" );
- wagonMock.getIfNewer( path, new File( expectedFile.getAbsolutePath() + ".tmp" ), 0 );
- wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) );
+ wagonMock.get( path, new File( expectedFile.getAbsolutePath() + ".tmp" ) );
+ wagonMockControl.setThrowable( new ResourceDoesNotExistException( "transfer failed" ) );
wagonMockControl.replay();
// Configure Connector (usually done within archiva.xml configuration)
File expectedFile = new File( managedDefaultDir.getAbsoluteFile(), path );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
- expectedFile.delete();
- assertFalse( expectedFile.exists() );
+ assertNotExistsInManagedDefaultRepo( expectedFile );
// Configure Repository (usually done within archiva.xml configuration)
saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" );
saveConnector( ID_DEFAULT_MANAGED, "badproxied2" );
File tmpFile = new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" );
- wagonMock.getIfNewer( path, tmpFile, 0 );
- wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) );
+ wagonMock.get( path, tmpFile );
+ wagonMockControl.setThrowable( new ResourceDoesNotExistException( "Can't find resource." ) );
- wagonMock.getIfNewer( path, tmpFile, 0 );
- wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) );
+ wagonMock.get( path, tmpFile );
+ wagonMockControl.setThrowable( new ResourceDoesNotExistException( "Can't find resource." ) );
wagonMockControl.replay();
// TODO: How much information on each failure should we pass back to the user vs. logging in the proxy?
}
- public void testLegacyProxyRepoGetAlreadyPresent()
+ public void testGetFromLegacyProxyAlreadyPresentInManaged_NewerThanRemote()
throws Exception
{
+ String legacyPath = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar";
String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path );
+ File remoteFile = new File( REPOPATH_PROXIED_LEGACY, legacyPath );
+
+ // Set the managed file to be newer than remote.
+ setManagedNewerThanRemote( expectedFile, remoteFile );
+ long expectedTimestamp = expectedFile.lastModified();
+
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
-
+
assertTrue( expectedFile.exists() );
// Configure Connector (usually done within archiva.xml configuration)
- saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
- SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+ saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
- File proxiedFile =
- new File( REPOPATH_PROXIED_LEGACY, "org.apache.maven.test/jars/get-default-layout-present-1.0.jar" );
- assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+ assertNotDownloaded( downloadedFile );
+ assertNotModified( expectedFile, expectedTimestamp );
assertNoTempFiles( expectedFile );
}
-
- public void testLegacyRequestConvertedToDefaultPathInManagedRepo()
+
+ public void testGetFromLegacyProxyAlreadyPresentInManaged_OlderThanRemote()
throws Exception
{
- // Check that a Maven1 legacy request is translated to a maven2 path in
- // the managed repository.
-
String legacyPath = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar";
String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path );
+ File remoteFile = new File( REPOPATH_PROXIED_LEGACY, legacyPath );
+
+ // Set the managed file to be older than remote.
+ setManagedOlderThanRemote( expectedFile, remoteFile );
+
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
- expectedFile.delete();
- assertFalse( expectedFile.exists() );
+ assertTrue( expectedFile.exists() );
// Configure Connector (usually done within archiva.xml configuration)
- saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
- SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+ saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
assertNoTempFiles( expectedFile );
}
- /* FIXME
- public void testLegacyRequestPluginConvertedToDefaultPathInManagedRepo()
+ public void testGetFromLegacyProxyNotPresentInManaged()
throws Exception
{
- // Check that a Maven1 legacy request is translated to a maven2 path in
- // the managed repository.
-
- String legacyPath = "org.apache.maven.test/plugins/get-legacy-plugin-1.0.jar";
- String path = "org/apache/maven/test/get-legacy-plugin/1.0/get-legacy-plugin-1.0.jar";
+ String legacyPath = "org.apache.maven.test/jars/example-lib-2.2.jar";
+ String path = "org/apache/maven/test/example-lib/2.2/example-lib-2.2.jar";
setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
- expectedFile.delete();
- assertFalse( expectedFile.exists() );
+ assertNotExistsInManagedDefaultRepo( expectedFile );
// Configure Connector (usually done within archiva.xml configuration)
- saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
- SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+ saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
assertFileEquals( expectedFile, downloadedFile, proxiedFile );
assertNoTempFiles( expectedFile );
}
- */
- public void testLegacyProxyRepoGetNotPresent()
+ public void testGetFromLegacyProxyPluginNotPresentInManaged()
throws Exception
{
- String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
+ String legacyPath = "org.apache.maven.test/plugins/example-maven-plugin-0.42.jar";
+ String path = "org/apache/maven/test/example-maven-plugin/0.42/example-maven-plugin-0.42.jar";
setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
- expectedFile.delete();
- assertFalse( expectedFile.exists() );
+ assertNotExistsInManagedDefaultRepo( expectedFile );
// Configure Connector (usually done within archiva.xml configuration)
- saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
- SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+ saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
- File proxiedFile = new File( REPOPATH_PROXIED_LEGACY, "org.apache.maven.test/jars/get-default-layout-1.0.jar" );
+ File proxiedFile = new File( REPOPATH_PROXIED_LEGACY, legacyPath );
assertFileEquals( expectedFile, downloadedFile, proxiedFile );
assertNoTempFiles( expectedFile );
-
- // TODO: timestamp preservation requires support for that in wagon
- // assertEquals( "Check file timestamp", proxiedFile.lastModified(), file.lastModified() );
}
}
public class ManagedLegacyTransferTest
extends AbstractProxyTestCase
{
- public void testLegacyManagedRepoGetNotPresent()
+ /**
+ * Incoming request on a Managed Legacy repository, for content that does not
+ * exist in the managed legacy repository, but does exist on a remote default layout repository.
+ */
+ public void testManagedLegacyNotPresentRemoteDefaultPresent()
throws Exception
{
String path = "org.apache.maven.test/jars/get-default-layout-1.0.jar";
File expectedFile = new File( managedLegacyDir, path );
ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path );
-
- expectedFile.delete();
- assertFalse( expectedFile.exists() );
-
+
+ assertNotExistsInManagedLegacyRepo( expectedFile );
+
// Configure Connector (usually done within archiva.xml configuration)
- saveConnector( ID_LEGACY_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
- SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
-
+ saveConnector( ID_LEGACY_MANAGED, ID_PROXIED1 );
+
File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
-
+
File proxied2File = new File( REPOPATH_PROXIED1,
"org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar" );
assertFileEquals( expectedFile, downloadedFile, proxied2File );
assertNoTempFiles( expectedFile );
-
- // TODO: timestamp preservation requires support for that in wagon
- // assertEquals( "Check file timestamp", proxiedFile.lastModified(), file.lastModified() );
}
- public void testLegacyManagedRepoGetAlreadyPresent()
+ /**
+ * Incoming request on a Managed Legacy repository, for content that already
+ * exist in the managed legacy repository, and also exist on a remote default layout repository.
+ */
+ public void testManagedLegacyPresentRemoteDefaultPresent()
throws Exception
{
String path = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar";
+ String remotePath = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
+
File expectedFile = new File( managedLegacyDir, path );
- ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path );
+ File remoteFile = new File( REPOPATH_PROXIED1, remotePath );
- assertTrue( expectedFile.exists() );
+ setManagedOlderThanRemote( expectedFile, remoteFile );
+
+ ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path );
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_LEGACY_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
- File proxied2File = new File( REPOPATH_PROXIED1,
- "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar" );
- assertFileEquals( expectedFile, downloadedFile, proxied2File );
+ assertFileEquals( expectedFile, downloadedFile, remoteFile );
assertNoTempFiles( expectedFile );
}
- public void testLegacyManagedAndProxyRepoGetNotPresent()
+ /**
+ * Incoming request on a Managed Legacy repository, for content that does not
+ * exist in the managed legacy repository, and does not exist on a remote legacy layout repository.
+ */
+ public void testManagedLegacyNotPresentRemoteLegacyPresent()
throws Exception
{
- String path = "org.apache.maven.test/jars/get-default-layout-1.0.jar";
+ String path = "org.apache.maven.test/plugins/get-legacy-plugin-1.0.jar";
File expectedFile = new File( managedLegacyDir, path );
ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path );
- assertFalse( expectedFile.exists() );
+ assertNotExistsInManagedLegacyRepo( expectedFile );
// Configure Connector (usually done within archiva.xml configuration)
- saveConnector( ID_LEGACY_MANAGED, ID_LEGACY_PROXIED, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
- SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+ saveConnector( ID_LEGACY_MANAGED, ID_LEGACY_PROXIED );
File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
File proxiedFile = new File( REPOPATH_PROXIED_LEGACY, path );
assertFileEquals( expectedFile, downloadedFile, proxiedFile );
assertNoTempFiles( expectedFile );
-
- // TODO: timestamp preservation requires support for that in wagon
- // assertEquals( "Check file timestamp", proxiedFile.lastModified(), file.lastModified() );
}
- public void testLegacyManagedAndProxyRepoGetAlreadyPresent()
+ /**
+ * Incoming request on a Managed Legacy repository, for content that does exist in the
+ * managed legacy repository, and also exists on a remote legacy layout repository.
+ */
+ public void testManagedLegacyPresentRemoteLegacyPresent()
throws Exception
{
String path = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar";
File expectedFile = new File( managedLegacyDir, path );
+ File remoteFile = new File( REPOPATH_PROXIED_LEGACY, path );
+
+ setManagedOlderThanRemote( expectedFile, remoteFile );
+
+ ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path );
+
+ // Configure Connector (usually done within archiva.xml configuration)
+ saveConnector( ID_LEGACY_MANAGED, ID_LEGACY_PROXIED );
+
+ File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
+
+ assertFileEquals( expectedFile, downloadedFile, remoteFile );
+ assertNoTempFiles( expectedFile );
+ }
+
+ /**
+ * Incoming request on a Managed Legacy repository, for content that does exist in the
+ * managed legacy repository, and does not exist on a remote legacy layout repository.
+ */
+ public void testManagedLegacyPresentRemoteLegacyNotPresent()
+ throws Exception
+ {
+ String path = "org.apache.maven.test/jars/managed-only-lib-2.1.jar";
+ File expectedFile = new File( managedLegacyDir, path );
ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path );
assertTrue( expectedFile.exists() );
// Configure Connector (usually done within archiva.xml configuration)
- saveConnector( ID_LEGACY_MANAGED, ID_LEGACY_PROXIED, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
- SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+ saveConnector( ID_LEGACY_MANAGED, ID_LEGACY_PROXIED );
File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
- File proxiedFile = new File( REPOPATH_PROXIED_LEGACY, path );
- assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+ assertNotDownloaded( downloadedFile );
assertNoTempFiles( expectedFile );
}
- /* FIXME
- public void testDefaultRequestConvertedToLegacyPathInManagedRepo()
+ /**
+ * Incoming request on a Managed Legacy repository, for content that does exist in the
+ * managed legacy repository, and does not exists on a remote default layout repository.
+ */
+ public void testManagedLegacyPresentRemoteDefaultNotPresent()
throws Exception
{
- // Check that a Maven2 default request is translated to a legacy path in
- // the managed repository.
+ String path = "org.apache.maven.test/jars/managed-only-lib-2.1.jar";
+ File expectedFile = new File( managedLegacyDir, path );
+ ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path );
+
+ assertTrue( expectedFile.exists() );
+
+ // Configure Connector (usually done within archiva.xml configuration)
+ saveConnector( ID_LEGACY_MANAGED, ID_PROXIED1 );
+
+ File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
- String legacyPath = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar";
- String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
- File expectedFile = new File( managedLegacyDir, legacyPath );
+ assertNotDownloaded( downloadedFile );
+ assertNoTempFiles( expectedFile );
+ }
+
+ /**
+ * Incoming request on a Managed Legacy repository, for content that does not exist in the
+ * managed legacy repository, and does not exists on a remote legacy layout repository.
+ */
+ public void testManagedLegacyNotPresentRemoteLegacyNotPresent()
+ throws Exception
+ {
+ String path = "org.apache.archiva.test/jars/mystery-lib-1.0.jar";
+ File expectedFile = new File( managedLegacyDir, path );
ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path );
- expectedFile.delete();
- assertFalse( expectedFile.exists() );
+ assertNotExistsInManagedLegacyRepo( expectedFile );
// Configure Connector (usually done within archiva.xml configuration)
- saveConnector( ID_LEGACY_MANAGED, ID_PROXIED1, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
- SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+ saveConnector( ID_LEGACY_MANAGED, ID_LEGACY_PROXIED );
File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
- File proxiedFile = new File( REPOPATH_PROXIED1, path );
- assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+ assertNotDownloaded( downloadedFile );
+ assertNoTempFiles( expectedFile );
+ }
+
+ /**
+ * Incoming request on a Managed Legacy repository, for content that does not exist in the
+ * managed legacy repository, and does not exists on a remote default layout repository.
+ */
+ public void testManagedLegacyNotPresentRemoteDefaultNotPresent()
+ throws Exception
+ {
+ String path = "org.apache.archiva.test/jars/mystery-lib-2.1.jar";
+ File expectedFile = new File( managedLegacyDir, path );
+ ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path );
+
+ assertNotExistsInManagedLegacyRepo( expectedFile );
+
+ // Configure Connector (usually done within archiva.xml configuration)
+ saveConnector( ID_LEGACY_MANAGED, ID_PROXIED1 );
+
+ File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
+
+ assertNotDownloaded( downloadedFile );
assertNoTempFiles( expectedFile );
}
- */
}
String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
setupTestableManagedRepository( requestedResource );
- setupTestableManagedRepository( requestedResource );
-
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
String requestedResource = "org/apache/maven/test/get-bogus-artifact/maven-metadata.xml";
setupTestableManagedRepository( requestedResource );
- setupTestableManagedRepository( requestedResource );
-
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+++ /dev/null
-package org.apache.maven.archiva.proxy;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * RelocateTransferTest
- *
- * @author Brett Porter
- * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
- * @version $Id$
- */
-public class RelocateTransferTest
- extends AbstractProxyTestCase
-{
-
- public void testRelocateMaven1Request()
- throws Exception
- {
- fail( "Implemented " + getName() );
-
- // String path = "org.apache.maven.test/jars/get-relocated-artefact-1.0.jar";
- // String relocatedPath = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
- // File expectedFile = new File( defaultManagedRepository.getBasedir(), relocatedPath );
- //
- // assertTrue( expectedFile.exists() );
- //
- // File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
- //
- // assertEquals( "Check file matches", expectedFile, file );
- }
-
- public void testDoublyRelocateMaven1Request()
- throws Exception
- {
- fail( "Implemented " + getName() );
-
- // String path = "org.apache.maven.test/jars/get-doubly-relocated-artefact-1.0.jar";
- // String relocatedPath = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
- // File expectedFile = new File( defaultManagedRepository.getBasedir(), relocatedPath );
- //
- // assertTrue( expectedFile.exists() );
- //
- // File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
- //
- // assertEquals( "Check file matches", expectedFile, file );
- }
-
- public void testRelocateMaven1PomRequest()
- throws Exception
- {
- fail( "Implemented " + getName() );
-
- // String path = "org.apache.maven.test/poms/get-relocated-artefact-with-pom-1.0.pom";
- // String relocatedPath = "org/apache/maven/test/get-default-layout-present-with-pom/1.0/get-default-layout-present-with-pom-1.0.pom";
- // File expectedFile = new File( defaultManagedRepository.getBasedir(), relocatedPath );
- //
- // assertTrue( expectedFile.exists() );
- //
- // File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
- //
- // assertEquals( "Check file matches", expectedFile, file );
- //
- // assertTrue( expectedFile.exists() );
- }
-
- public void testRelocateMaven1PomRequestMissingTarget()
- throws Exception
- {
- fail( "Implemented " + getName() );
-
- // String path = "org.apache.maven.test/poms/get-relocated-artefact-1.0.pom";
- // String relocatedPath = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.pom";
- // File expectedFile = new File( defaultManagedRepository.getBasedir(), relocatedPath );
- //
- // assertFalse( expectedFile.exists() );
- //
- // try
- // {
- // requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
- // fail( "Should have failed to find target POM" );
- // }
- // catch ( ResourceDoesNotExistException e )
- // {
- // assertTrue( true );
- // }
- }
-
- public void testRelocateMaven1ChecksumRequest()
- throws Exception
- {
- fail( "Implemented " + getName() );
-
- // String path = "org.apache.maven.test/jars/get-relocated-artefact-1.0.jar.md5";
- // String relocatedPath = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar.md5";
- // File expectedFile = new File( defaultManagedRepository.getBasedir(), relocatedPath );
- //
- // assertTrue( expectedFile.exists() );
- //
- // File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
- //
- // assertEquals( "Check file matches", expectedFile, file );
- //
- // assertTrue( expectedFile.exists() );
- //
- // path = "org.apache.maven.test/jars/get-relocated-artefact-1.0.jar.sha1";
- // relocatedPath = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar.sha1";
- // expectedFile = new File( defaultManagedRepository.getBasedir(), relocatedPath );
- //
- // assertFalse( expectedFile.exists() );
- //
- // try
- // {
- // requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
- // fail( "Checksum was not present, should not be found" );
- // }
- // catch ( ResourceDoesNotExistException e )
- // {
- // assertTrue( true );
- // }
- }
-
- public void testRelocateMaven2Request()
- throws Exception
- {
- fail( "Implemented " + getName() );
-
- // String path = "org/apache/maven/test/get-relocated-artefact/1.0/get-relocated-artefact-1.0.jar";
- // String relocatedPath = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
- // File expectedFile = new File( defaultManagedRepository.getBasedir(), relocatedPath );
- //
- // assertTrue( expectedFile.exists() );
- //
- // File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
- //
- // assertEquals( "Check file matches", expectedFile, file );
- }
-
- public void testRelocateMaven2RequestInLegacyManagedRepo()
- throws Exception
- {
- fail( "Implemented " + getName() );
-
- // String path = "org/apache/maven/test/get-relocated-artefact/1.0/get-relocated-artefact-1.0.jar";
- // String relocatedPath = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar";
- // File expectedFile = new File( legacyManagedRepository.getBasedir(), relocatedPath );
- //
- // assertTrue( expectedFile.exists() );
- //
- // File file = requestHandler.get( path, proxiedRepositories, legacyManagedRepository );
- //
- // assertEquals( "Check file matches", expectedFile, file );
- }
-
-}
setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path );
+ File remoteFile = new File( REPOPATH_PROXIED1, path );
+
+ setManagedNewerThanRemote( expectedFile, remoteFile );
+
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
- assertTrue( expectedFile.exists() );
- expectedFile.setLastModified( getFutureDate().getTime() );
-
// Configure Connector (usually done within archiva.xml configuration)
- saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
- SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+ saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1 );
+ // Attempt to download.
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
- File proxiedFile = new File( REPOPATH_PROXIED1, path );
- assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+ // Should not have downloaded as managed is newer than remote.
+ assertNotDownloaded( downloadedFile );
assertNoTempFiles( expectedFile );
}
setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path );
- ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
-
- assertTrue( expectedFile.exists() );
+ File remoteFile = new File( REPOPATH_PROXIED1, path );
- File proxiedFile = new File( REPOPATH_PROXIED1, path );
- expectedFile.setLastModified( proxiedFile.lastModified() );
+ setManagedNewerThanRemote( expectedFile, remoteFile );
+ long expectedTimestamp = expectedFile.lastModified();
+
+ ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
- assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+ assertNotDownloaded( downloadedFile );
+ assertNotModified( expectedFile, expectedTimestamp );
assertNoTempFiles( expectedFile );
}
--- /dev/null
+(example jar found only in legacy proxy)
--- /dev/null
+(example maven plugin v0.42 found only in legacy proxy)