[MRM-563] Proxy connector logic for getIfModified is backwards.

Fixing backwards logic in DefaultRepositoryProxyConnectors.
Updating test cases to honor correct .get() vs .getIfModified() logic wrt/mocks.
Updating ManagedLegacyTransferTest for all varients of Managed to Remote, Legacy vs Default, Present and Not Present.
Introducing NotModifiedException to cope with proper .getIfModified() logic.
Introducing NotFoundException to cope with operational exception vs serious connectivity exception.



git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@587318 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Joakim Erdfelt 2007-10-23 00:18:20 +00:00
parent b4c36626c5
commit 322c16f688
15 changed files with 534 additions and 413 deletions

View File

@ -27,6 +27,7 @@ import org.apache.maven.archiva.configuration.ConfigurationNames;
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;
@ -147,14 +148,29 @@ public class DefaultRepositoryProxyConnectors
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 ) )
{
getLogger().debug( "Successfully transfered: " + downloadedFile.getAbsolutePath() );
getLogger().debug( "Successfully transferred: " + downloadedFile.getAbsolutePath() );
return downloadedFile;
}
}
catch ( NotFoundException e )
{
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;
}
@ -181,6 +197,9 @@ public class DefaultRepositoryProxyConnectors
File localRepoFile = toLocalRepoFile( repository, targetRepository, targetPath );
long originalMetadataTimestamp = getLastModified( localRepoFile );
try
{
transferFile( connector, targetRepository, targetPath, localRepoFile, requestProperties );
if ( hasBeenUpdated( localRepoFile, originalMetadataTimestamp ) )
@ -188,6 +207,19 @@ public class DefaultRepositoryProxyConnectors
metadataNeedsUpdating = true;
}
}
catch ( NotFoundException e )
{
getLogger().debug( "Versioned Metadata " + Keys.toKey( metadata )
+ " not found on remote repository \""
+ targetRepository.getRepository().getId() + "\"." );
}
catch ( NotModifiedException e )
{
getLogger().debug( "Versioned Metadata " + Keys.toKey( metadata )
+ " not updated on remote repository \""
+ targetRepository.getRepository().getId() + "\"." );
}
}
if ( hasBeenUpdated( localFile, originalTimestamp ) )
{
@ -258,9 +290,10 @@ public class DefaultRepositoryProxyConnectors
* 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 );
@ -276,6 +309,8 @@ public class DefaultRepositoryProxyConnectors
File localRepoFile = toLocalRepoFile( repository, targetRepository, targetPath );
long originalMetadataTimestamp = getLastModified( localRepoFile );
try
{
transferFile( connector, targetRepository, targetPath, localRepoFile, requestProperties );
if ( hasBeenUpdated( localRepoFile, originalMetadataTimestamp ) )
@ -283,6 +318,19 @@ public class DefaultRepositoryProxyConnectors
metadataNeedsUpdating = true;
}
}
catch ( NotFoundException e )
{
getLogger().debug( "Project Metadata " + Keys.toKey( metadata ) + " not found on remote repository \""
+ targetRepository.getRepository().getId() + "\"." );
}
catch ( NotModifiedException e )
{
getLogger().debug( "Project Metadata " + Keys.toKey( metadata )
+ " not updated on remote repository \""
+ targetRepository.getRepository().getId() + "\"." );
}
}
if ( hasBeenUpdated( localFile, originalTimestamp ) )
{
@ -401,11 +449,14 @@ public class DefaultRepositoryProxyConnectors
* @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 );
@ -461,15 +512,20 @@ public class DefaultRepositoryProxyConnectors
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
{
@ -507,9 +563,9 @@ public class DefaultRepositoryProxyConnectors
}
/**
* <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.
@ -536,14 +592,22 @@ public class DefaultRepositoryProxyConnectors
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;
}
}
@ -560,7 +624,7 @@ public class DefaultRepositoryProxyConnectors
*/
private File transferSimpleFile( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath,
File localFile )
throws ProxyException, WagonException
throws NotFoundException, NotModifiedException, ProxyException
{
assert ( remotePath != null );
@ -573,7 +637,7 @@ public class DefaultRepositoryProxyConnectors
boolean success = false;
if ( localFile.exists() )
if ( !localFile.exists() )
{
getLogger().debug( "Retrieving " + remotePath + " from " + remoteRepository.getRepository().getName() );
wagon.get( remotePath, temp );
@ -594,11 +658,11 @@ public class DefaultRepositoryProxyConnectors
success = wagon.getIfNewer( remotePath, temp, localFile.lastModified() );
if ( !success )
{
getLogger().debug(
"Not downloaded, as local file is newer than remote side: "
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 );
@ -609,15 +673,13 @@ public class DefaultRepositoryProxyConnectors
}
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
{

View File

@ -0,0 +1,40 @@
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 );
}
}

View File

@ -0,0 +1,48 @@
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 );
}
}

View File

@ -19,7 +19,6 @@ package org.apache.maven.archiva.proxy;
* 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;

View File

@ -137,7 +137,8 @@ public abstract class AbstractProxyTestCase
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 );
@ -488,6 +489,54 @@ public abstract class AbstractProxyTestCase
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
{

View File

@ -26,7 +26,7 @@ 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.archiva.policies.urlcache.UrlFailureCache;
import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import java.io.File;
@ -45,10 +45,11 @@ public class CacheFailuresTransferTest
{
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" );
@ -60,17 +61,16 @@ public class CacheFailuresTransferTest
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 );
}
@ -79,10 +79,12 @@ public class CacheFailuresTransferTest
{
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 );
expectedFile.delete();
assertFalse( expectedFile.exists() );
setupTestableManagedRepository( path );
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" );
@ -94,9 +96,8 @@ public class CacheFailuresTransferTest
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();

View File

@ -25,7 +25,7 @@ import org.apache.maven.archiva.policies.CachedFailuresPolicy;
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;
@ -377,7 +377,7 @@ public class ChecksumTransferTest
"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";
@ -396,12 +396,12 @@ public class ChecksumTransferTest
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 );
@ -429,9 +429,11 @@ public class ChecksumTransferTest
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.IGNORED, ReleasesPolicy.IGNORED,
@ -453,12 +455,14 @@ public class ChecksumTransferTest
setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path );
File remoteFile = new File( REPOPATH_PROXIED1, path );
setManagedOlderThanRemote( expectedFile, remoteFile );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
assertTrue( expectedFile.exists() );
// 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 );
@ -477,9 +481,11 @@ public class ChecksumTransferTest
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.FIX, ReleasesPolicy.IGNORED,

View File

@ -26,7 +26,7 @@ import org.apache.maven.archiva.policies.CachedFailuresPolicy;
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;
@ -50,8 +50,7 @@ public class ManagedDefaultTransferTest
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,
@ -96,19 +95,32 @@ public class ManagedDefaultTransferTest
}
/**
* 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 );
@ -122,30 +134,52 @@ public class ManagedDefaultTransferTest
// 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 );
}
@ -189,14 +223,11 @@ public class ManagedDefaultTransferTest
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 );
@ -222,14 +253,11 @@ public class ManagedDefaultTransferTest
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 );
@ -248,15 +276,12 @@ public class ManagedDefaultTransferTest
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 );
@ -275,14 +300,13 @@ public class ManagedDefaultTransferTest
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)
@ -308,8 +332,7 @@ public class ManagedDefaultTransferTest
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" );
@ -320,11 +343,11 @@ public class ManagedDefaultTransferTest
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();
@ -339,48 +362,53 @@ public class ManagedDefaultTransferTest
// 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 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 );
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 );
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 );
assertNoTempFiles( expectedFile );
}
public void testLegacyRequestConvertedToDefaultPathInManagedRepo()
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 newer than remote.
setManagedNewerThanRemote( expectedFile, remoteFile );
long expectedTimestamp = expectedFile.lastModified();
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 );
assertNotDownloaded( downloadedFile );
assertNotModified( expectedFile, expectedTimestamp );
assertNoTempFiles( expectedFile );
}
public void testGetFromLegacyProxyAlreadyPresentInManaged_OlderThanRemote()
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 older than remote.
setManagedOlderThanRemote( expectedFile, remoteFile );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
assertTrue( expectedFile.exists() );
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
@ -389,26 +417,20 @@ public class ManagedDefaultTransferTest
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 );
@ -416,31 +438,26 @@ public class ManagedDefaultTransferTest
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() );
}
}

View File

@ -37,19 +37,21 @@ import java.io.File;
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 );
@ -57,19 +59,24 @@ public class ManagedLegacyTransferTest
"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";
File expectedFile = new File( managedLegacyDir, path );
ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path );
String remotePath = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
assertTrue( expectedFile.exists() );
File expectedFile = new File( managedLegacyDir, path );
File remoteFile = new File( REPOPATH_PROXIED1, remotePath );
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,
@ -77,79 +84,142 @@ public class ManagedLegacyTransferTest
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 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 );
String path = "org.apache.maven.test/jars/managed-only-lib-2.1.jar";
File expectedFile = new File( managedLegacyDir, path );
ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path );
expectedFile.delete();
assertFalse( expectedFile.exists() );
assertTrue( expectedFile.exists() );
// 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_PROXIED1 );
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 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 );
assertNotExistsInManagedLegacyRepo( expectedFile );
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_LEGACY_MANAGED, ID_LEGACY_PROXIED );
File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
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 );
}
}

View File

@ -141,8 +141,6 @@ public class MetadataTransferTest
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 );
@ -169,8 +167,6 @@ public class MetadataTransferTest
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 );

View File

@ -1,171 +0,0 @@
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 );
}
}

View File

@ -111,19 +111,20 @@ public class SnapshotTransferTest
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 );
}
@ -225,20 +226,21 @@ public class SnapshotTransferTest
setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path );
File remoteFile = new File( REPOPATH_PROXIED1, path );
setManagedNewerThanRemote( expectedFile, remoteFile );
long expectedTimestamp = expectedFile.lastModified();
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
assertTrue( expectedFile.exists() );
File proxiedFile = new File( REPOPATH_PROXIED1, path );
expectedFile.setLastModified( proxiedFile.lastModified() );
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
assertFileEquals( expectedFile, downloadedFile, proxiedFile );
assertNotDownloaded( downloadedFile );
assertNotModified( expectedFile, expectedTimestamp );
assertNoTempFiles( expectedFile );
}

View File

@ -0,0 +1 @@
(example jar found only in legacy proxy)

View File

@ -0,0 +1 @@
(example maven plugin v0.42 found only in legacy proxy)