You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by jo...@apache.org on 2007/10/23 02:18:36 UTC

svn commit: r587318 - in /maven/archiva/trunk/archiva-base/archiva-proxy/src: main/java/org/apache/maven/archiva/proxy/ test/java/org/apache/maven/archiva/proxy/ test/repositories/legacy-managed/org.apache.maven.test/jars/ test/repositories/legacy-prox...

Author: joakime
Date: Mon Oct 22 17:18:20 2007
New Revision: 587318

URL: http://svn.apache.org/viewvc?rev=587318&view=rev
Log:
[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.


Added:
    maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/NotFoundException.java   (with props)
    maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/NotModifiedException.java   (with props)
    maven/archiva/trunk/archiva-base/archiva-proxy/src/test/repositories/legacy-managed/org.apache.maven.test/jars/managed-only-lib-2.1.jar   (with props)
    maven/archiva/trunk/archiva-base/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/example-lib-2.2.jar   (with props)
    maven/archiva/trunk/archiva-base/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/plugins/example-maven-plugin-0.42.jar   (with props)
Removed:
    maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/RelocateTransferTest.java
Modified:
    maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java
    maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/RepositoryProxyConnectors.java
    maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java
    maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java
    maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ChecksumTransferTest.java
    maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java
    maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.java
    maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MetadataTransferTest.java
    maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/SnapshotTransferTest.java

Modified: maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java?rev=587318&r1=587317&r2=587318&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java Mon Oct 22 17:18:20 2007
@@ -27,6 +27,7 @@
 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 @@
             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;
     }
@@ -181,11 +197,27 @@
 
             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() + "\"." );
             }
         }
 
@@ -258,9 +290,10 @@
      * 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,12 +309,27 @@
 
             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 ) )
@@ -401,11 +449,14 @@
      * @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 @@
                 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 @@
     }
 
     /**
+     * <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 @@
             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 @@
      */
     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 @@
 
             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 @@
                 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 );
@@ -609,15 +673,13 @@
         }
         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
         {

Added: maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/NotFoundException.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/NotFoundException.java?rev=587318&view=auto
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/NotFoundException.java (added)
+++ maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/NotFoundException.java Mon Oct 22 17:18:20 2007
@@ -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 );
+    }
+}

Propchange: maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/NotFoundException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/NotFoundException.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Propchange: maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/NotFoundException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/NotModifiedException.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/NotModifiedException.java?rev=587318&view=auto
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/NotModifiedException.java (added)
+++ maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/NotModifiedException.java Mon Oct 22 17:18:20 2007
@@ -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 );
+    }
+}

Propchange: maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/NotModifiedException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/NotModifiedException.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Propchange: maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/NotModifiedException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/RepositoryProxyConnectors.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/RepositoryProxyConnectors.java?rev=587318&r1=587317&r2=587318&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/RepositoryProxyConnectors.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/RepositoryProxyConnectors.java Mon Oct 22 17:18:20 2007
@@ -19,7 +19,6 @@
  * 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;

Modified: maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java?rev=587318&r1=587317&r2=587318&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java Mon Oct 22 17:18:20 2007
@@ -137,7 +137,8 @@
         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 );
@@ -486,6 +487,54 @@
 
         // Copy directory structure.
         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()

Modified: maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java?rev=587318&r1=587317&r2=587318&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java Mon Oct 22 17:18:20 2007
@@ -26,7 +26,7 @@
 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,11 +45,12 @@
     {
         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" );
@@ -60,17 +61,16 @@
         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 @@
     {
         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" );
@@ -94,9 +96,8 @@
         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();
 

Modified: maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ChecksumTransferTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ChecksumTransferTest.java?rev=587318&r1=587317&r2=587318&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ChecksumTransferTest.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ChecksumTransferTest.java Mon Oct 22 17:18:20 2007
@@ -25,7 +25,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.wagon.TransferFailedException;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
 
 import java.io.File;
 
@@ -377,7 +377,7 @@
                          "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 @@
         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 @@
         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,
@@ -453,12 +455,14 @@
         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 );
@@ -477,9 +481,11 @@
         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,

Modified: maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java?rev=587318&r1=587317&r2=587318&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java Mon Oct 22 17:18:20 2007
@@ -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.wagon.TransferFailedException;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
 
 import java.io.File;
 
@@ -50,8 +50,7 @@
         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 @@
     }
 
     /**
-     * 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 @@
         // 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 @@
         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 @@
         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 @@
         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 @@
         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 @@
         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 @@
         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 @@
         // 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 );
 
@@ -389,26 +417,20 @@
         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 @@
         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() );
     }
 }

Modified: maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.java?rev=587318&r1=587317&r2=587318&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.java Mon Oct 22 17:18:20 2007
@@ -37,39 +37,46 @@
 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,
@@ -77,79 +84,142 @@
 
         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 );
     }
-    */
 }

Modified: maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MetadataTransferTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MetadataTransferTest.java?rev=587318&r1=587317&r2=587318&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MetadataTransferTest.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MetadataTransferTest.java Mon Oct 22 17:18:20 2007
@@ -141,8 +141,6 @@
         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 );
@@ -167,8 +165,6 @@
     {
         // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
         String requestedResource = "org/apache/maven/test/get-bogus-artifact/maven-metadata.xml";
-        setupTestableManagedRepository( requestedResource );
-
         setupTestableManagedRepository( requestedResource );
 
         // Configure Connector (usually done within archiva.xml configuration)

Modified: maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/SnapshotTransferTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/SnapshotTransferTest.java?rev=587318&r1=587317&r2=587318&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/SnapshotTransferTest.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/SnapshotTransferTest.java Mon Oct 22 17:18:20 2007
@@ -111,19 +111,20 @@
         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,12 +226,12 @@
         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,
@@ -238,7 +239,8 @@
 
         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
 
-        assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+        assertNotDownloaded( downloadedFile );
+        assertNotModified( expectedFile, expectedTimestamp );
         assertNoTempFiles( expectedFile );
     }
 

Added: maven/archiva/trunk/archiva-base/archiva-proxy/src/test/repositories/legacy-managed/org.apache.maven.test/jars/managed-only-lib-2.1.jar
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-proxy/src/test/repositories/legacy-managed/org.apache.maven.test/jars/managed-only-lib-2.1.jar?rev=587318&view=auto
==============================================================================
Binary file - no diff available.

Propchange: maven/archiva/trunk/archiva-base/archiva-proxy/src/test/repositories/legacy-managed/org.apache.maven.test/jars/managed-only-lib-2.1.jar
------------------------------------------------------------------------------
    svn:mime-type = application/java-archive

Added: maven/archiva/trunk/archiva-base/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/example-lib-2.2.jar
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/example-lib-2.2.jar?rev=587318&view=auto
==============================================================================
Binary file - no diff available.

Propchange: maven/archiva/trunk/archiva-base/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/example-lib-2.2.jar
------------------------------------------------------------------------------
    svn:mime-type = application/java-archive

Added: maven/archiva/trunk/archiva-base/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/plugins/example-maven-plugin-0.42.jar
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/plugins/example-maven-plugin-0.42.jar?rev=587318&view=auto
==============================================================================
Binary file - no diff available.

Propchange: maven/archiva/trunk/archiva-base/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/plugins/example-maven-plugin-0.42.jar
------------------------------------------------------------------------------
    svn:mime-type = application/java-archive