]> source.dussan.org Git - archiva.git/commitdiff
* Furthor test case improvement.
authorJoakim Erdfelt <joakime@apache.org>
Tue, 17 Apr 2007 14:12:36 +0000 (14:12 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Tue, 17 Apr 2007 14:12:36 +0000 (14:12 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches/archiva-jpox-database-refactor@529617 13f79535-47bb-0310-9956-ffa450edef68

archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java
archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java
archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AllTests.java [new file with mode: 0644]
archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java
archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.java
archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MetadataTransferTest.java
archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/SnapshotTransferTest.java
archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/RelocateTransferTest.xml [new file with mode: 0644]

index b8612a4215174db6722f70675a82b04fadfb2558..ed85005a8842a9bafba84e9bed22111712288005 100644 (file)
@@ -144,6 +144,10 @@ public class DefaultRepositoryProxyConnectors
                 BidirectionalRepositoryLayout targetLayout = layoutFactory.getLayout( targetRepository.getLayoutType() );
                 String targetPath = targetLayout.toPath( artifact );
 
+                getLogger().debug(
+                                   "Using target repository: " + targetRepository.getId() + " - layout: "
+                                       + targetRepository.getLayoutType() + " - targetPath: " + targetPath );
+
                 File downloadedFile = transferFile( connector, targetRepository, targetPath, localFile,
                                                     requestProperties );
 
@@ -680,6 +684,7 @@ public class DefaultRepositoryProxyConnectors
         }
 
         ArchivaRepository repo = new ArchivaRepository( repoConfig.getId(), repoConfig.getName(), repoConfig.getUrl() );
+        repo.getModel().setLayoutName( repoConfig.getLayout() );
         return repo;
     }
 
index c87ac1dacd1c18685b7ad51816552ec3844187da..0886104248d075c7cc65da7b4a2e188da7ea6ee7 100644 (file)
@@ -31,7 +31,6 @@ import org.apache.maven.archiva.model.ProjectReference;
 import org.apache.maven.archiva.policies.urlcache.UrlFailureCache;
 import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout;
 import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory;
-import org.apache.maven.archiva.repository.layout.LayoutException;
 import org.apache.maven.wagon.Wagon;
 import org.codehaus.plexus.PlexusTestCase;
 import org.easymock.MockControl;
@@ -42,6 +41,7 @@ import java.io.FileReader;
 import java.io.IOException;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.Calendar;
 import java.util.Collection;
 import java.util.Date;
 import java.util.Iterator;
@@ -59,8 +59,12 @@ public class AbstractProxyTestCase
     protected static final String ID_LEGACY_PROXIED = "legacy-proxied";
 
     protected static final String ID_PROXIED1 = "proxied1";
+    
+    protected static final String ID_PROXIED1_TARGET = "proxied1-target";
 
     protected static final String ID_PROXIED2 = "proxied2";
+    
+    protected static final String ID_PROXIED2_TARGET = "proxied2-target";
 
     protected static final String ID_DEFAULT_MANAGED = "default-managed-repository";
 
@@ -69,8 +73,12 @@ public class AbstractProxyTestCase
     protected static final String REPOPATH_PROXIED_LEGACY = "src/test/repositories/legacy-proxied";
 
     protected static final String REPOPATH_PROXIED1 = "src/test/repositories/proxied1";
+    
+    protected static final String REPOPATH_PROXIED1_TARGET = "target/test-repository/proxied1";
 
     protected static final String REPOPATH_PROXIED2 = "src/test/repositories/proxied2";
+    
+    protected static final String REPOPATH_PROXIED2_TARGET = "target/test-repository/proxied2";
 
     protected static final String REPOPATH_DEFAULT_MANAGED = "src/test/repositories/managed";
 
@@ -93,93 +101,40 @@ public class AbstractProxyTestCase
     protected ArchivaRepository managedLegacyRepository;
 
     protected File managedLegacyDir;
-    
+
     protected BidirectionalRepositoryLayoutFactory layoutFactory;
 
     protected MockConfiguration config;
 
-    protected void setUp()
+    protected void assertChecksums( File expectedFile, String expectedSha1Contents, String expectedMd5Contents )
         throws Exception
     {
-        super.setUp();
-
-        layoutFactory = (BidirectionalRepositoryLayoutFactory) lookup( BidirectionalRepositoryLayoutFactory.class
-                                                                       .getName() );
-        
-        config = (MockConfiguration) lookup( ArchivaConfiguration.class.getName(), "mock" );
-        RepositoryConfiguration repoConfig;
-
-        // Setup source repository (using default layout)
-        File repoLocation = getTestFile( REPOPATH_DEFAULT_MANAGED_TARGET );
-        // faster only to delete this one before copying, the others are done case by case
-        FileUtils.deleteDirectory( new File( repoLocation, "org/apache/maven/test/get-merged-metadata" ) );
-        copyDirectoryStructure( getTestFile( REPOPATH_DEFAULT_MANAGED ), repoLocation );
-
-        managedDefaultRepository = createRepository( ID_DEFAULT_MANAGED, "Default Managed Repository",
-                                                     REPOPATH_DEFAULT_MANAGED_TARGET, "default" );
-
-        managedDefaultDir = new File( managedDefaultRepository.getUrl().getPath() );
-
-        repoConfig = createRepoConfig( managedDefaultRepository );
-
-        config.getConfiguration().addRepository( repoConfig );
-
-        // Setup source repository (using legacy layout)
-        repoLocation = getTestFile( REPOPATH_LEGACY_MANAGED_TARGET );
-        FileUtils.deleteDirectory( repoLocation );
-        copyDirectoryStructure( getTestFile( REPOPATH_LEGACY_MANAGED ), repoLocation );
-
-        managedLegacyRepository = createRepository( ID_LEGACY_MANAGED, "Legacy Managed Repository",
-                                                    REPOPATH_LEGACY_MANAGED_TARGET, "legacy" );
-
-        managedLegacyDir = new File( managedLegacyRepository.getUrl().getPath() );
-
-        repoConfig = createRepoConfig( managedLegacyRepository );
-
-        config.getConfiguration().addRepository( repoConfig );
-
-        // Setup target (proxied to) repository.
-        saveRepositoryConfig( ID_PROXIED1, "Proxied Repository 1", REPOPATH_PROXIED1, "default" );
-
-        // Setup target (proxied to) repository.
-        saveRepositoryConfig( ID_PROXIED2, "Proxied Repository 2", REPOPATH_PROXIED2, "default" );
-
-        // Setup target (proxied to) repository using legacy layout.
-        saveRepositoryConfig( ID_LEGACY_PROXIED, "Proxied Legacy Repository", REPOPATH_PROXIED_LEGACY, "legacy" );
-
-        // Setup the proxy handler.
-        proxyHandler = (RepositoryProxyConnectors) lookup( RepositoryProxyConnectors.class.getName() );
-
-        // Setup the wagon mock.
-        wagonMockControl = MockControl.createNiceControl( Wagon.class );
-        wagonMock = (Wagon) wagonMockControl.getMock();
-        WagonDelegate delegate = (WagonDelegate) lookup( Wagon.ROLE, "test" );
-        delegate.setDelegate( wagonMock );
-
-        System.out.println( "\n.\\ " + getName() + "() \\._________________________________________\n" );
-    }
-    
-    protected void saveRepositoryConfig( String id, String name, String path, String layout )
-    {
-        RepositoryConfiguration repoConfig = new RepositoryConfiguration();
-
-        repoConfig.setId( id );
-        repoConfig.setName( name );
+        File sha1File = new File( expectedFile.getAbsolutePath() + ".sha1" );
+        File md5File = new File( expectedFile.getAbsolutePath() + ".md5" );
 
-        if ( path.indexOf( "://" ) > 0 )
+        if ( expectedSha1Contents == null )
         {
-            repoConfig.setUrl( path );
+            assertFalse( "SHA1 File should NOT exist: " + sha1File.getPath(), sha1File.exists() );
         }
         else
         {
-            repoConfig.setUrl( PathUtil.toUrl( path ) );
+            assertTrue( "SHA1 File should exist: " + sha1File.getPath(), sha1File.exists() );
+            String actualSha1Contents = readChecksumFile( sha1File );
+            assertEquals( "SHA1 File contents: " + sha1File.getPath(), expectedSha1Contents, actualSha1Contents );
         }
-        repoConfig.setLayout( layout );
 
-        config.getConfiguration().addRepository( repoConfig );
-        config.triggerChange( "repository", "" );
+        if ( expectedMd5Contents == null )
+        {
+            assertFalse( "MD5 File should NOT exist: " + md5File.getPath(), md5File.exists() );
+        }
+        else
+        {
+            assertTrue( "MD5 File should exist: " + md5File.getPath(), md5File.exists() );
+            String actualMd5Contents = readChecksumFile( md5File );
+            assertEquals( "MD5 File contents: " + md5File.getPath(), expectedMd5Contents, actualMd5Contents );
+        }
     }
-
+    
     protected void assertFileEquals( File expectedFile, File actualFile, File sourceFile )
         throws Exception
     {
@@ -194,6 +149,34 @@ public class AbstractProxyTestCase
         assertEquals( "Check file contents.", expectedContents, actualContents );
     }
 
+    protected void assertNotDownloaded( File downloadedFile )
+    {
+        assertNull( "Found file: " + downloadedFile + "; but was expecting a failure", downloadedFile );
+    }
+
+    protected void assertNoTempFiles( File expectedFile )
+    {
+        File workingDir = expectedFile.getParentFile();
+        if ( ( workingDir == null ) || !workingDir.isDirectory() )
+        {
+            return;
+        }
+
+        Collection tmpFiles = FileUtils.listFiles( workingDir, new String[] { "tmp" }, false );
+        if ( !tmpFiles.isEmpty() )
+        {
+            StringBuffer emsg = new StringBuffer();
+            emsg.append( "Found Temp Files in dir: " ).append( workingDir.getPath() );
+            Iterator it = tmpFiles.iterator();
+            while ( it.hasNext() )
+            {
+                File tfile = (File) it.next();
+                emsg.append( "\n   " ).append( tfile.getName() );
+            }
+            fail( emsg.toString() );
+        }
+    }
+
     /**
      * A faster recursive copy that omits .svn directories.
      *
@@ -266,6 +249,12 @@ public class AbstractProxyTestCase
         return ref;
     }
 
+    protected ArchivaRepository createManagedLegacyRepository()
+    {
+        return createRepository( "src/test/repositories/legacy-managed", "testManagedLegacyRepo",
+                                 "Test Managed (Legacy) Repository", "legacy" );
+    }
+
     protected ProjectReference createMetadataReference( String layoutType, String path )
         throws Exception
     {
@@ -274,12 +263,6 @@ public class AbstractProxyTestCase
         return metadata;
     }
 
-    protected ArchivaRepository createManagedLegacyRepository()
-    {
-        return createRepository( "src/test/repositories/legacy-managed", "testManagedLegacyRepo",
-                                 "Test Managed (Legacy) Repository", "legacy" );
-    }
-
     protected ArchivaRepository createProxiedLegacyRepository()
     {
         return createRepository( "src/test/repositories/legacy-proxied", "testProxiedLegacyRepo",
@@ -312,21 +295,6 @@ public class AbstractProxyTestCase
         return repo;
     }
 
-    protected void saveConnector( String sourceRepoId, String targetRepoId, String checksumPolicy,
-                                  String releasePolicy, String snapshotPolicy, String cacheFailuresPolicy )
-    {
-        ProxyConnectorConfiguration connectorConfig = new ProxyConnectorConfiguration();
-        connectorConfig.setSourceRepoId( sourceRepoId );
-        connectorConfig.setTargetRepoId( targetRepoId );
-        connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_CHECKSUM, checksumPolicy );
-        connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_RELEASES, releasePolicy );
-        connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_SNAPSHOTS, snapshotPolicy );
-        connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_CACHE_FAILURES, cacheFailuresPolicy );
-
-        config.getConfiguration().addProxyConnector( connectorConfig );
-        config.triggerChange( "proxyConnector", "" );
-    }
-
     protected UrlFailureCache lookupUrlFailureCache()
         throws Exception
     {
@@ -335,29 +303,6 @@ public class AbstractProxyTestCase
         return failurlCache;
     }
 
-    protected void assertNoTempFiles( File expectedFile )
-    {
-        File workingDir = expectedFile.getParentFile();
-        if ( ( workingDir == null ) || !workingDir.isDirectory() )
-        {
-            return;
-        }
-
-        Collection tmpFiles = FileUtils.listFiles( workingDir, new String[] { "tmp" }, false );
-        if ( !tmpFiles.isEmpty() )
-        {
-            StringBuffer emsg = new StringBuffer();
-            emsg.append( "Found Temp Files in dir: " ).append( workingDir.getPath() );
-            Iterator it = tmpFiles.iterator();
-            while ( it.hasNext() )
-            {
-                File tfile = (File) it.next();
-                emsg.append( "\n   " ).append( tfile.getName() );
-            }
-            fail( emsg.toString() );
-        }
-    }
-
     /**
      * Read the first line from the checksum file, and return it (trimmed).
      */
@@ -387,38 +332,120 @@ public class AbstractProxyTestCase
         }
     }
 
-    protected void assertChecksums( File expectedFile, String expectedSha1Contents, String expectedMd5Contents )
-        throws Exception
+    protected void saveConnector( String sourceRepoId, String targetRepoId, String checksumPolicy,
+                                  String releasePolicy, String snapshotPolicy, String cacheFailuresPolicy )
     {
-        File sha1File = new File( expectedFile.getAbsolutePath() + ".sha1" );
-        File md5File = new File( expectedFile.getAbsolutePath() + ".md5" );
+        ProxyConnectorConfiguration connectorConfig = new ProxyConnectorConfiguration();
+        connectorConfig.setSourceRepoId( sourceRepoId );
+        connectorConfig.setTargetRepoId( targetRepoId );
+        connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_CHECKSUM, checksumPolicy );
+        connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_RELEASES, releasePolicy );
+        connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_SNAPSHOTS, snapshotPolicy );
+        connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_CACHE_FAILURES, cacheFailuresPolicy );
 
-        if ( expectedSha1Contents == null )
-        {
-            assertFalse( "SHA1 File should NOT exist: " + sha1File.getPath(), sha1File.exists() );
-        }
-        else
-        {
-            assertTrue( "SHA1 File should exist: " + sha1File.getPath(), sha1File.exists() );
-            String actualSha1Contents = readChecksumFile( sha1File );
-            assertEquals( "SHA1 File contents: " + sha1File.getPath(), expectedSha1Contents, actualSha1Contents );
-        }
+        config.getConfiguration().addProxyConnector( connectorConfig );
+        config.triggerChange( "proxyConnector", "" );
+    }
 
-        if ( expectedMd5Contents == null )
+    protected void saveRepositoryConfig( String id, String name, String path, String layout )
+    {
+        RepositoryConfiguration repoConfig = new RepositoryConfiguration();
+
+        repoConfig.setId( id );
+        repoConfig.setName( name );
+
+        if ( path.startsWith( "test://" ) )
         {
-            assertFalse( "MD5 File should NOT exist: " + md5File.getPath(), md5File.exists() );
+            repoConfig.setUrl( path );
         }
         else
         {
-            assertTrue( "MD5 File should exist: " + md5File.getPath(), md5File.exists() );
-            String actualMd5Contents = readChecksumFile( md5File );
-            assertEquals( "MD5 File contents: " + md5File.getPath(), expectedMd5Contents, actualMd5Contents );
+            repoConfig.setUrl( PathUtil.toUrl( path ) );
         }
+        repoConfig.setLayout( layout );
+
+        config.getConfiguration().addRepository( repoConfig );
+        config.triggerChange( "repository", "" );
     }
 
-    protected void assertNotDownloaded( File downloadedFile )
+    protected File saveTargetedRepositoryConfig( String id, String originalPath, String targetPath, String layout ) throws IOException
     {
-        assertNull( "Found file: " + downloadedFile + "; but was expecting a failure", downloadedFile );
+        File repoLocation = getTestFile( targetPath );
+        FileUtils.deleteDirectory( repoLocation );
+        copyDirectoryStructure( getTestFile( originalPath ), repoLocation );
+
+        saveRepositoryConfig( id, "Target Repo-" + id, targetPath, layout );
+        
+        return repoLocation;
+    }
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        layoutFactory = (BidirectionalRepositoryLayoutFactory) lookup( BidirectionalRepositoryLayoutFactory.class
+            .getName() );
+
+        config = (MockConfiguration) lookup( ArchivaConfiguration.class.getName(), "mock" );
+        RepositoryConfiguration repoConfig;
+
+        // Setup source repository (using default layout)
+        File repoLocation = getTestFile( REPOPATH_DEFAULT_MANAGED_TARGET );
+        // faster only to delete this one before copying, the others are done case by case
+        FileUtils.deleteDirectory( new File( repoLocation, "org/apache/maven/test/get-merged-metadata" ) );
+        copyDirectoryStructure( getTestFile( REPOPATH_DEFAULT_MANAGED ), repoLocation );
+
+        managedDefaultRepository = createRepository( ID_DEFAULT_MANAGED, "Default Managed Repository",
+                                                     REPOPATH_DEFAULT_MANAGED_TARGET, "default" );
+
+        managedDefaultDir = new File( managedDefaultRepository.getUrl().getPath() );
+
+        repoConfig = createRepoConfig( managedDefaultRepository );
+
+        config.getConfiguration().addRepository( repoConfig );
+
+        // Setup source repository (using legacy layout)
+        repoLocation = getTestFile( REPOPATH_LEGACY_MANAGED_TARGET );
+        FileUtils.deleteDirectory( repoLocation );
+        copyDirectoryStructure( getTestFile( REPOPATH_LEGACY_MANAGED ), repoLocation );
+
+        managedLegacyRepository = createRepository( ID_LEGACY_MANAGED, "Legacy Managed Repository",
+                                                    REPOPATH_LEGACY_MANAGED_TARGET, "legacy" );
+
+        managedLegacyDir = new File( managedLegacyRepository.getUrl().getPath() );
+
+        repoConfig = createRepoConfig( managedLegacyRepository );
+
+        config.getConfiguration().addRepository( repoConfig );
+
+        // Setup target (proxied to) repository.
+        saveRepositoryConfig( ID_PROXIED1, "Proxied Repository 1", REPOPATH_PROXIED1, "default" );
+
+        // Setup target (proxied to) repository.
+        saveRepositoryConfig( ID_PROXIED2, "Proxied Repository 2", REPOPATH_PROXIED2, "default" );
+
+        // Setup target (proxied to) repository using legacy layout.
+        saveRepositoryConfig( ID_LEGACY_PROXIED, "Proxied Legacy Repository", REPOPATH_PROXIED_LEGACY, "legacy" );
+
+        // Setup the proxy handler.
+        proxyHandler = (RepositoryProxyConnectors) lookup( RepositoryProxyConnectors.class.getName() );
+
+        // Setup the wagon mock.
+        wagonMockControl = MockControl.createNiceControl( Wagon.class );
+        wagonMock = (Wagon) wagonMockControl.getMock();
+        WagonDelegate delegate = (WagonDelegate) lookup( Wagon.ROLE, "test" );
+        delegate.setDelegate( wagonMock );
+
+        System.out.println( "\n.\\ " + getName() + "() \\._________________________________________\n" );
+    }
+
+    protected static Date getFutureDate()
+        throws ParseException
+    {
+        Calendar cal = Calendar.getInstance();
+        cal.add( Calendar.YEAR, 1 );
+        return cal.getTime();
     }
 
     protected static Date getPastDate()
diff --git a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AllTests.java b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AllTests.java
new file mode 100644 (file)
index 0000000..f2de337
--- /dev/null
@@ -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.
+ */
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * IDE Provided Utility Class for all tests. 
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class AllTests
+{
+
+    public static Test suite()
+    {
+        TestSuite suite = new TestSuite( "Test for org.apache.maven.archiva.proxy" );
+        //$JUnit-BEGIN$
+        suite.addTestSuite( ChecksumTransferTest.class );
+        suite.addTestSuite( MetadataTransferTest.class );
+        suite.addTestSuite( CacheFailuresTransferTest.class );
+        suite.addTestSuite( ManagedDefaultTransferTest.class );
+        suite.addTestSuite( SnapshotTransferTest.class );
+        suite.addTestSuite( ManagedLegacyTransferTest.class );
+        suite.addTestSuite( RelocateTransferTest.class );
+        //$JUnit-END$
+        return suite;
+    }
+}
index ba4fe1bc46feaba65dc02153401ec19a4bee16e4..17ce40dacb05d03efc940b79d94da4c24756aa79 100644 (file)
@@ -307,4 +307,73 @@ 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()
+        throws Exception
+    {
+        String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
+        File expectedFile = new File( managedDefaultDir, path );
+        ArtifactReference artifact = createArtifactReference( "default", 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";
+        File expectedFile = new File( managedDefaultDir, path );
+        ArtifactReference artifact = createArtifactReference( "default", path );
+
+        expectedFile.delete();
+        assertFalse( 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, legacyPath );
+        assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+        assertNoTempFiles( expectedFile );
+    }
+
+    public void testLegacyProxyRepoGetNotPresent()
+        throws Exception
+    {
+        String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
+        File expectedFile = new File( managedDefaultDir, path );
+        ArtifactReference artifact = createArtifactReference( "default", path );
+
+        expectedFile.delete();
+        assertFalse( 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-1.0.jar" );
+        assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+        assertNoTempFiles( expectedFile );
+
+        // TODO: timestamp preservation requires support for that in wagon
+        //    assertEquals( "Check file timestamp", proxiedFile.lastModified(), file.lastModified() );
+    }
 }
index 19607f9e82a1ec7dab9994001aed5fbf5443a385..ee3cee1ca9676e2c79fcce21b46deaf39bf5805b 100644 (file)
@@ -51,9 +51,9 @@ public class ManagedLegacyTransferTest
         saveConnector( ID_LEGACY_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
                        SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
 
-        File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+        File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
 
-        File proxied2File = new File( REPOPATH_PROXIED2,
+        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 );
@@ -65,95 +65,43 @@ public class ManagedLegacyTransferTest
     public void testLegacyManagedRepoGetAlreadyPresent()
         throws Exception
     {
-        fail( "Implemented " + getName() );
-
-        //        String path = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar";
-        //        File expectedFile = new File( legacyManagedRepository.getBasedir(), path );
-        //        String expectedContents = FileUtils.readFileToString( expectedFile, null );
-        //        long originalModificationTime = expectedFile.lastModified();
-        //
-        //        assertTrue( expectedFile.exists() );
-        //
-        //        File file = requestHandler.get( path, proxiedRepositories, legacyManagedRepository );
-        //
-        //        assertEquals( "Check file matches", expectedFile, file );
-        //        assertTrue( "Check file created", file.exists() );
-        //        assertEquals( "Check file contents", expectedContents, FileUtils.readFileToString( file, null ) );
-        //        File proxiedFile = new File( proxiedRepository1.getBasedir(),
-        //                                     "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar" );
-        //        String unexpectedContents = FileUtils.readFileToString( proxiedFile, null );
-        //        assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.readFileToString( file, null ) ) );
-        //        assertFalse( "Check file timestamp is not that of proxy", proxiedFile.lastModified() == file.lastModified() );
-        //        assertEquals( "Check file timestamp is that of original managed file", originalModificationTime, file
-        //            .lastModified() );
-    }
+        String path = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar";
+        File expectedFile = new File( managedLegacyDir, path );
+        ArtifactReference artifact = createArtifactReference( "legacy", path );
 
-    public void testLegacyProxyRepoGetNotPresent()
-        throws Exception
-    {
-        fail( "Implemented " + getName() );
-
-        //        String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
-        //        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
-        //
-        //        expectedFile.delete();
-        //        assertFalse( expectedFile.exists() );
-        //
-        //        File file = requestHandler.get( path, legacyProxiedRepositories, defaultManagedRepository );
-        //
-        //        assertEquals( "Check file matches", expectedFile, file );
-        //        assertTrue( "Check file created", file.exists() );
-        //        File proxiedFile = new File( legacyProxiedRepository.getBasedir(),
-        //                                     "org.apache.maven.test/jars/get-default-layout-1.0.jar" );
-        //        String expectedContents = FileUtils.readFileToString( proxiedFile, null );
-        //        assertEquals( "Check file contents", expectedContents, FileUtils.readFileToString( file, null ) );
-        // TODO: timestamp preservation requires support for that in wagon
-        //    assertEquals( "Check file timestamp", proxiedFile.lastModified(), file.lastModified() );
-    }
+        assertTrue( expectedFile.exists() );
 
-    public void testLegacyProxyRepoGetAlreadyPresent()
-        throws Exception
-    {
-        fail( "Implemented " + getName() );
-
-        //        String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
-        //        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
-        //        String expectedContents = FileUtils.readFileToString( expectedFile, null );
-        //        long originalModificationTime = expectedFile.lastModified();
-        //
-        //        assertTrue( expectedFile.exists() );
-        //
-        //        File file = requestHandler.get( path, legacyProxiedRepositories, defaultManagedRepository );
-        //
-        //        assertEquals( "Check file matches", expectedFile, file );
-        //        assertTrue( "Check file created", file.exists() );
-        //        assertEquals( "Check file contents", expectedContents, FileUtils.readFileToString( file, null ) );
-        //        File proxiedFile = new File( legacyProxiedRepository.getBasedir(),
-        //                                     "org.apache.maven.test/jars/get-default-layout-present-1.0.jar" );
-        //        String unexpectedContents = FileUtils.readFileToString( proxiedFile, null );
-        //        assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.readFileToString( file, null ) ) );
-        //        assertFalse( "Check file timestamp is not that of proxy", proxiedFile.lastModified() == file.lastModified() );
-        //        assertEquals( "Check file timestamp is that of original managed file", originalModificationTime, file
-        //            .lastModified() );
+        // Configure Connector (usually done within archiva.xml configuration)
+        saveConnector( ID_LEGACY_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
+                       SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+
+        File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
+
+        File proxied2File = new File( REPOPATH_PROXIED1,
+                                      "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar" );
+        assertFileEquals( expectedFile, downloadedFile, proxied2File );
+        assertNoTempFiles( expectedFile );
     }
 
     public void testLegacyManagedAndProxyRepoGetNotPresent()
         throws Exception
     {
-        fail( "Implemented " + getName() );
-
-        //        String path = "org.apache.maven.test/jars/get-default-layout-1.0.jar";
-        //        File expectedFile = new File( legacyManagedRepository.getBasedir(), path );
-        //
-        //        assertFalse( expectedFile.exists() );
-        //
-        //        File file = requestHandler.get( path, legacyProxiedRepositories, legacyManagedRepository );
-        //
-        //        assertEquals( "Check file matches", expectedFile, file );
-        //        assertTrue( "Check file created", file.exists() );
-        //        File proxiedFile = new File( legacyProxiedRepository.getBasedir(), path );
-        //        String expectedContents = FileUtils.readFileToString( proxiedFile, null );
-        //        assertEquals( "Check file contents", expectedContents, FileUtils.readFileToString( file, null ) );
+        String path = "org.apache.maven.test/jars/get-default-layout-1.0.jar";
+        File expectedFile = new File( managedLegacyDir, path );
+        ArtifactReference artifact = createArtifactReference( "legacy", path );
+
+        assertFalse( 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 );
+
+        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() );
     }
@@ -161,61 +109,45 @@ public class ManagedLegacyTransferTest
     public void testLegacyManagedAndProxyRepoGetAlreadyPresent()
         throws Exception
     {
-        fail( "Implemented " + getName() );
-
-        //        String path = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar";
-        //        File expectedFile = new File( legacyManagedRepository.getBasedir(), path );
-        //        String expectedContents = FileUtils.readFileToString( expectedFile, null );
-        //        long originalModificationTime = expectedFile.lastModified();
-        //
-        //        assertTrue( expectedFile.exists() );
-        //
-        //        File file = requestHandler.get( path, legacyProxiedRepositories, legacyManagedRepository );
-        //
-        //        assertEquals( "Check file matches", expectedFile, file );
-        //        assertTrue( "Check file created", file.exists() );
-        //        assertEquals( "Check file contents", expectedContents, FileUtils.readFileToString( file, null ) );
-        //        File proxiedFile = new File( legacyProxiedRepository.getBasedir(), path );
-        //        String unexpectedContents = FileUtils.readFileToString( proxiedFile, null );
-        //        assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.readFileToString( file, null ) ) );
-        //        assertFalse( "Check file timestamp is not that of proxy", proxiedFile.lastModified() == file.lastModified() );
-        //        assertEquals( "Check file timestamp is that of original managed file", originalModificationTime, file
-        //            .lastModified() );
-    }
+        String path = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar";
+        File expectedFile = new File( managedLegacyDir, path );
+        ArtifactReference artifact = createArtifactReference( "legacy", path );
 
-    public void testLegacyRequestConvertedToDefaultPathInManagedRepo()
-        throws Exception
-    {
-        fail( "Implemented " + getName() );
+        assertTrue( expectedFile.exists() );
 
-        // Check that a Maven1 legacy request is translated to a maven2 path in
-        // the managed repository.
+        // Configure Connector (usually done within archiva.xml configuration)
+        saveConnector( ID_LEGACY_MANAGED, ID_LEGACY_PROXIED, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
+                       SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
 
-        //        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( defaultManagedRepository.getBasedir(), path );
-        //        assertTrue( expectedFile.exists() );
-        //
-        //        File file = requestHandler.get( legacyPath, legacyProxiedRepositories, defaultManagedRepository );
-        //
-        //        assertEquals( "Check file matches", expectedFile, file );
+        File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
+
+        File proxiedFile = new File( REPOPATH_PROXIED_LEGACY, path );
+        assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+        assertNoTempFiles( expectedFile );
     }
 
     public void testDefaultRequestConvertedToLegacyPathInManagedRepo()
         throws Exception
     {
-        fail( "Implemented " + getName() );
-
         // 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( legacyManagedRepository.getBasedir(), legacyPath );
-        //        assertTrue( expectedFile.exists() );
-        //
-        //        File file = requestHandler.get( path, proxiedRepositories, legacyManagedRepository );
-        //
-        //        assertEquals( "Check file matches", expectedFile, file );
+        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 );
+        ArtifactReference artifact = createArtifactReference( "legacy", legacyPath );
+
+        expectedFile.delete();
+        assertFalse( expectedFile.exists() );
+
+        // Configure Connector (usually done within archiva.xml configuration)
+        saveConnector( ID_LEGACY_MANAGED, ID_PROXIED1, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
+                       SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+
+        File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
+
+        File proxiedFile = new File( REPOPATH_PROXIED1, path );
+        assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+        assertNoTempFiles( expectedFile );
     }
 }
index 0a271fcb9593c5189215fc3df01d148acb90db96..40d98f44690318662ca29bd5fd9812a4cb793d4b 100644 (file)
@@ -19,13 +19,26 @@ package org.apache.maven.archiva.proxy;
  * under the License.
  */
 
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.archiva.model.ArchivaRepositoryMetadata;
 import org.apache.maven.archiva.model.ProjectReference;
+import org.apache.maven.archiva.model.SnapshotVersion;
 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.archiva.repository.metadata.RepositoryMetadataException;
+import org.apache.maven.archiva.repository.metadata.RepositoryMetadataReader;
+import org.apache.maven.archiva.repository.metadata.RepositoryMetadataWriter;
 
 import java.io.File;
+import java.io.StringWriter;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
 
 /**
  * MetadataTransferTest 
@@ -45,248 +58,305 @@ public class MetadataTransferTest
         ProjectReference metadata = createMetadataReference( "default", path );
 
         // Configure Connector (usually done within archiva.xml configuration)
-        saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
+        saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
                        SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
 
         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, metadata );
 
         assertNotDownloaded( downloadedFile );
+        assertNoTempFiles( expectedFile );
+    }
 
-        //        String path = "org/apache/maven/test/dummy-artifact/1.0/maven-metadata.xml";
-        //        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
-        //
-        //        assertFalse( expectedFile.exists() );
-        //
-        //        try
-        //        {
-        //            File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
-        //            fail( "Found file: " + file + "; but was expecting a failure" );
-        //        }
-        //        catch ( ResourceDoesNotExistException e )
-        //        {
-        //            // expected
-        //
-        //            assertFalse( expectedFile.exists() );
-        //        }
+    private String getExpectedMetadata( String artifactId, String version )
+        throws RepositoryMetadataException
+    {
+        return getExpectedMetadata( artifactId, version, (SnapshotVersion) null, null );
+    }
+
+    private static final TimeZone UTC_TIMEZONE = TimeZone.getTimeZone( "UTC" );
+
+    private static String getLastUpdatedTimestamp( File file )
+    {
+        DateFormat fmt = new SimpleDateFormat( "yyyyMMddHHmmss", Locale.US );
+        fmt.setTimeZone( UTC_TIMEZONE );
+        return fmt.format( new Date( file.lastModified() ) );
+    }
+
+    private String getExpectedMetadata( String artifactId, String[] availableVersions, File file )
+        throws RepositoryMetadataException
+    {
+        return getExpectedMetadata( artifactId, null, availableVersions, file );
+    }
+
+    private SnapshotVersion getSnapshotVersion( String timestamp, int buildNumber )
+    {
+        SnapshotVersion snapshot = new SnapshotVersion();
+
+        snapshot.setTimestamp( timestamp );
+        snapshot.setBuildNumber( buildNumber );
+
+        return snapshot;
+    }
+
+    private String getExpectedMetadata( String artifactId, String version, SnapshotVersion snapshot, File file )
+        throws RepositoryMetadataException
+    {
+        StringWriter expectedContents = new StringWriter();
+
+        ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
+        m.setGroupId( "org.apache.maven.test" );
+        m.setArtifactId( artifactId );
+        m.setVersion( version );
+        m.setSnapshotVersion( snapshot );
+        if ( file != null )
+        {
+            m.setLastUpdated( getLastUpdatedTimestamp( file ) );
+        }
+        m.setModelEncoding( null );
+
+        RepositoryMetadataWriter.write( m, expectedContents );
+        return expectedContents.toString();
+    }
+
+    private String getExpectedMetadata( String artifactId, String version, String[] availableVersions, File file )
+        throws RepositoryMetadataException
+    {
+        StringWriter expectedContents = new StringWriter();
+
+        ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
+        m.setGroupId( "org.apache.maven.test" );
+        m.setArtifactId( artifactId );
+        m.setVersion( version );
+        if ( file != null )
+        {
+            m.setLastUpdated( getLastUpdatedTimestamp( file ) );
+        }
+        if ( availableVersions != null )
+        {
+            m.getAvailableVersions().addAll( Arrays.asList( availableVersions ) );
+        }
+        m.setModelEncoding( null );
+
+        RepositoryMetadataWriter.write( m, expectedContents );
+        return expectedContents.toString();
+    }
+
+    private void assertMetadataEquals( File expectedFile, File downloadedFile, String expectedMetadata )
+        throws Exception
+    {
+        assertNotNull( "Expected File should not be null.", expectedFile );
+        assertNotNull( "Downloaded File should not be null.", downloadedFile );
+
+        assertTrue( "Check downloaded file exists.", downloadedFile.exists() );
+        assertEquals( "Check file path matches.", expectedFile.getAbsolutePath(), downloadedFile.getAbsolutePath() );
+
+        StringWriter actualContents = new StringWriter();
+        RepositoryMetadataReader metadataReader = new RepositoryMetadataReader();
+        ArchivaRepositoryMetadata metadata = metadataReader.read( downloadedFile );
+        RepositoryMetadataWriter.write( metadata, actualContents );
+        assertEquals( "Check file contents.", expectedMetadata, actualContents );
     }
 
     public void testGetMetadataProxied()
+        throws Exception
     {
         String path = "org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml";
-        fail( "Implemented " + getName() );
-
-        //        String path = "org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml";
-        //        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
-        //
-        //        FileUtils.deleteDirectory( expectedFile.getParentFile() );
-        //        assertFalse( expectedFile.exists() );
-        //
-        //        File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
-        //        assertEquals( "Check file matches", expectedFile, file );
-        //        assertTrue( "Check file created", file.exists() );
-        //        String expectedContents = getExpectedMetadata( "get-default-metadata", "1.0" );
-        //        assertEquals( "Check content matches", expectedContents, FileUtils.readFileToString( file, null ) );        
+        File expectedFile = new File( managedDefaultDir, path );
+        ProjectReference metadata = createMetadataReference( "default", path );
+
+        FileUtils.deleteDirectory( expectedFile.getParentFile() );
+        assertFalse( expectedFile.exists() );
+
+        // Configure Connector (usually done within archiva.xml configuration)
+        saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
+                       SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+
+        File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, metadata );
+
+        String expectedMetadata = getExpectedMetadata( "get-default-metadata", "1.0" );
+        assertMetadataEquals( expectedFile, downloadedFile, expectedMetadata );
+        assertNoTempFiles( expectedFile );
     }
 
     public void testGetMetadataMergeRepos()
+        throws Exception
     {
         String path = "org/apache/maven/test/get-merged-metadata/maven-metadata.xml";
-        fail( "Implemented " + getName() );
-
-        //        String path = "org/apache/maven/test/get-merged-metadata/maven-metadata.xml";
-        //        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
-        //
-        //        assertTrue( expectedFile.exists() );
-        //
-        //        File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
-        //        assertEquals( "Check file matches", expectedFile, file );
-        //        assertTrue( "Check file created", file.exists() );
-        //
-        //        String expectedContents = getExpectedMetadata( "get-merged-metadata", getVersioning(
-        //            Arrays.asList( new String[]{"0.9", "1.0", "2.0", "3.0", "5.0", "4.0"} ), file ) );
-        //
-        //        assertEquals( "Check content matches", expectedContents, FileUtils.readFileToString( file, null ) );
+        File expectedFile = new File( managedDefaultDir, path );
+        ProjectReference metadata = createMetadataReference( "default", 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 );
+
+        File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, metadata );
+
+        String expectedMetadata = getExpectedMetadata( "get-merged-metadata", new String[] {
+            "0.9",
+            "1.0",
+            "2.0",
+            "3.0",
+            "5.0",
+            "4.0" }, downloadedFile );
+        assertMetadataEquals( expectedFile, downloadedFile, expectedMetadata );
+        assertNoTempFiles( expectedFile );
     }
 
     public void testGetMetadataRemovedFromProxies()
+        throws Exception
     {
         String path = "org/apache/maven/test/get-removed-metadata/1.0/maven-metadata.xml";
-        fail( "Implemented " + getName() );
-
-        //        String path = "org/apache/maven/test/get-removed-metadata/1.0/maven-metadata.xml";
-        //        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
-        //        String expectedContents =
-        //            FileUtils.readFileToString( new File( defaultManagedRepository.getBasedir(), path ), null );
-        //
-        //        assertTrue( expectedFile.exists() );
-        //
-        //        File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
-        //        assertEquals( "Check file matches", expectedFile, file );
-        //        assertTrue( "Check file created", file.exists() );
-        //        assertEquals( "Check content matches", expectedContents, FileUtils.readFileToString( file, null ) );        
+        File expectedFile = new File( managedDefaultDir, path );
+        ProjectReference metadata = createMetadataReference( "default", path );
+
+        assertTrue( expectedFile.exists() );
+
+        // Configure Connector (usually done within archiva.xml configuration)
+        saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
+                       SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+
+        File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, metadata );
+
+        File proxiedFile = new File( REPOPATH_PROXIED1, path );
+        assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+        assertNoTempFiles( expectedFile );
     }
 
     public void testGetReleaseMetadataNotExpired()
+        throws Exception
     {
         String path = "org/apache/maven/test/get-updated-metadata/maven-metadata.xml";
-        fail( "Implemented " + getName() );
-
-        //        String path = "org/apache/maven/test/get-updated-metadata/maven-metadata.xml";
-        //        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
-        //        String expectedContents =
-        //            FileUtils.readFileToString( new File( defaultManagedRepository.getBasedir(), path ), null );
-        //
-        //        assertTrue( expectedFile.exists() );
-        //
-        //        new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() );
-        //
-        //        proxiedRepository1.getReleases().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER );
-        //        proxiedRepository1.getSnapshots().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS );
-        //        File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
-        //        assertEquals( "Check file matches", expectedFile, file );
-        //        assertTrue( "Check file created", file.exists() );
-        //        assertEquals( "Check content matches", expectedContents, FileUtils.readFileToString( file, null ) );
-        //
-        //        String unexpectedContents =
-        //            FileUtils.readFileToString( new File( proxiedRepository1.getBasedir(), path ), null );
-        //        assertFalse( "Check content doesn't match proxy version",
-        //                     unexpectedContents.equals( FileUtils.readFileToString( file, null ) ) );
+        File expectedFile = new File( managedDefaultDir, path );
+        ProjectReference metadata = createMetadataReference( "default", path );
+
+        assertTrue( expectedFile.exists() );
 
+        new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() );
+
+        // Configure Connector (usually done within archiva.xml configuration)
+        saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
+                       SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+
+        File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, metadata );
+
+        File proxiedFile = new File( REPOPATH_PROXIED1, path );
+        assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+        assertNoTempFiles( expectedFile );
     }
 
     public void testGetSnapshotMetadataNotExpired()
+        throws Exception
     {
         String path = "org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml";
-        fail( "Implemented " + getName() );
-
-        //        String path = "org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml";
-        //        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
-        //        String expectedContents =
-        //            FileUtils.readFileToString( new File( defaultManagedRepository.getBasedir(), path ), null );
-        //
-        //        assertTrue( expectedFile.exists() );
-        //
-        //        new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() );
-        //
-        //        proxiedRepository1.getReleases().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS );
-        //        proxiedRepository1.getSnapshots().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER );
-        //        File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
-        //        assertEquals( "Check file matches", expectedFile, file );
-        //        assertTrue( "Check file created", file.exists() );
-        //        assertEquals( "Check content matches", expectedContents, FileUtils.readFileToString( file, null ) );
-        //
-        //        String unexpectedContents =
-        //            FileUtils.readFileToString( new File( proxiedRepository1.getBasedir(), path ), null );
-        //        assertFalse( "Check content doesn't match proxy version",
-        //                     unexpectedContents.equals( FileUtils.readFileToString( file, null ) ) );        
+        File expectedFile = new File( managedDefaultDir, path );
+        ProjectReference metadata = createMetadataReference( "default", path );
+
+        assertTrue( expectedFile.exists() );
+
+        new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() );
+
+        // Configure Connector (usually done within archiva.xml configuration)
+        saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
+                       SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+
+        File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, metadata );
+
+        // Content should NOT match that from proxied 1. 
+        assertFileEquals( expectedFile, downloadedFile, expectedFile );
+        assertNoTempFiles( expectedFile );
     }
 
     public void testGetReleaseMetadataExpired()
+        throws Exception
     {
         String path = "org/apache/maven/test/get-updated-metadata/maven-metadata.xml";
-        fail( "Implemented " + getName() );
-
-        //        String path = "org/apache/maven/test/get-updated-metadata/maven-metadata.xml";
-        //        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
-        //        String unexpectedContents =
-        //            FileUtils.readFileToString( new File( defaultManagedRepository.getBasedir(), path ), null );
-        //
-        //        assertTrue( expectedFile.exists() );
-        //
-        //        new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() );
-        //
-        //        proxiedRepository1.getReleases().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS );
-        //        proxiedRepository1.getSnapshots().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER );
-        //        File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
-        //        assertEquals( "Check file matches", expectedFile, file );
-        //        assertTrue( "Check file created", file.exists() );
-        //
-        //        String expectedContents = getExpectedMetadata( "get-updated-metadata", getVersioning(
-        //            Arrays.asList( new String[]{"1.0", "2.0"} ), file ) );
-        //
-        //        assertEquals( "Check content matches", expectedContents, FileUtils.readFileToString( file, null ) );
-        //        assertFalse( "Check content doesn't match proxy version",
-        //                     unexpectedContents.equals( FileUtils.readFileToString( file, null ) ) );
+        File expectedFile = new File( managedDefaultDir, path );
+        ProjectReference metadata = createMetadataReference( "default", path );
+
+        assertTrue( expectedFile.exists() );
+
+        new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() );
+
+        // Configure Connector (usually done within archiva.xml configuration)
+        saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
+                       SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+
+        File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, metadata );
 
+        String expectedMetadata = getExpectedMetadata( "get-updated-metadata", new String[] { "1.0", "2.0", },
+                                                       downloadedFile );
+        assertMetadataEquals( expectedFile, downloadedFile, expectedMetadata );
+        assertNoTempFiles( expectedFile );
     }
 
     public void testGetSnapshotMetadataExpired()
+        throws Exception
     {
         String path = "org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml";
-        fail( "Implemented " + getName() );
-
-        //        String path = "org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml";
-        //        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
-        //        String unexpectedContents =
-        //            FileUtils.readFileToString( new File( defaultManagedRepository.getBasedir(), path ), null );
-        //
-        //        assertTrue( expectedFile.exists() );
-        //
-        //        new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() );
-        //
-        //        proxiedRepository1.getReleases().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER );
-        //        proxiedRepository1.getSnapshots().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS );
-        //        File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
-        //        assertEquals( "Check file matches", expectedFile, file );
-        //        assertTrue( "Check file created", file.exists() );
-        //
-        //        String expectedContents =
-        //            getExpectedMetadata( "get-updated-metadata", "1.0-SNAPSHOT", getVersioning( "20050831.111213", 2, file ) );
-        //
-        //        assertEquals( "Check content matches", expectedContents, FileUtils.readFileToString( file, null ) );
-        //        assertFalse( "Check content doesn't match proxy version",
-        //                     unexpectedContents.equals( FileUtils.readFileToString( file, null ) ) );
+        File expectedFile = new File( managedDefaultDir, path );
+        ProjectReference metadata = createMetadataReference( "default", path );
 
+        assertTrue( expectedFile.exists() );
+
+        new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() );
+
+        // Configure Connector (usually done within archiva.xml configuration)
+        saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
+                       SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+
+        File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, metadata );
+
+        String expectedMetadata = getExpectedMetadata( "get-updated-metadata", "1.0-SNAPSHOT",
+                                                       getSnapshotVersion( "20050831.111213", 2 ), downloadedFile );
+        assertMetadataEquals( expectedFile, downloadedFile, expectedMetadata );
+        assertNoTempFiles( expectedFile );
     }
 
     public void testGetMetadataNotUpdated()
+        throws Exception
     {
         String path = "org/apache/maven/test/get-updated-metadata/maven-metadata.xml";
-        fail( "Implemented " + getName() );
-
-        //        String path = "org/apache/maven/test/get-updated-metadata/maven-metadata.xml";
-        //        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
-        //        String expectedContents =
-        //            FileUtils.readFileToString( new File( defaultManagedRepository.getBasedir(), path ), null );
-        //
-        //        assertTrue( expectedFile.exists() );
-        //
-        //        File proxiedFile = new File( proxiedRepository1.getBasedir(), path );
-        //        new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( proxiedFile.lastModified() );
-        //
-        //        proxiedRepository1.getReleases().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS );
-        //        File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
-        //        assertEquals( "Check file matches", expectedFile, file );
-        //        assertTrue( "Check file created", file.exists() );
-        //        assertEquals( "Check content matches", expectedContents, FileUtils.readFileToString( file, null ) );
-        //
-        //        String unexpectedContents = FileUtils.readFileToString( proxiedFile, null );
-        //        assertFalse( "Check content doesn't match proxy version",
-        //                     unexpectedContents.equals( FileUtils.readFileToString( file, null ) ) );        
+        File expectedFile = new File( managedDefaultDir, path );
+        ProjectReference metadata = createMetadataReference( "default", path );
+
+        assertTrue( expectedFile.exists() );
+
+        File proxiedFile = new File( REPOPATH_PROXIED1, path );
+        new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( proxiedFile.lastModified() );
+
+        // Configure Connector (usually done within archiva.xml configuration)
+        saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
+                       SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+
+        File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, metadata );
+
+        assertFileEquals( expectedFile, downloadedFile, expectedFile );
+        assertNoTempFiles( expectedFile );
     }
 
     public void testGetMetadataUpdated()
+        throws Exception
     {
         String path = "org/apache/maven/test/get-updated-metadata/maven-metadata.xml";
-        fail( "Implemented " + getName() );
-
-        //        String path = "org/apache/maven/test/get-updated-metadata/maven-metadata.xml";
-        //        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
-        //        String unexpectedContents =
-        //            FileUtils.readFileToString( new File( defaultManagedRepository.getBasedir(), path ), null );
-        //
-        //        assertTrue( expectedFile.exists() );
-        //
-        //        new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() );
-        //
-        //        File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
-        //        assertEquals( "Check file matches", expectedFile, file );
-        //        assertTrue( "Check file created", file.exists() );
-        //
-        //        String expectedContents = getExpectedMetadata( "get-updated-metadata", getVersioning(
-        //            Arrays.asList( new String[]{"1.0", "2.0"} ), file ) );
-        //        assertEquals( "Check content matches", expectedContents, FileUtils.readFileToString( file, null ) );
-        //        assertFalse( "Check content doesn't match old version",
-        //                     unexpectedContents.equals( FileUtils.readFileToString( file, null ) ) );    
+        File expectedFile = new File( managedDefaultDir, path );
+        ProjectReference metadata = createMetadataReference( "default", path );
+
+        assertTrue( expectedFile.exists() );
+
+        new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() );
+
+        // Configure Connector (usually done within archiva.xml configuration)
+        saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.IGNORED,
+                       SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+
+        File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, metadata );
+
+        String expectedMetadata = getExpectedMetadata( "get-updated-metadata", new String[] { "1.0", "2.0" },
+                                                       downloadedFile );
+
+        assertMetadataEquals( expectedFile, downloadedFile, expectedMetadata );
+        assertNoTempFiles( expectedFile );
     }
 }
index e0ec84ead174d61464cbe6a5dd48dd88c01c1166..66d4b06e112e4b5933966d16b564e5e9a13da3f1 100644 (file)
@@ -19,8 +19,15 @@ package org.apache.maven.archiva.proxy;
  * under the License.
  */
 
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.archiva.model.ArtifactReference;
+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.ResourceDoesNotExistException;
 
+import java.io.File;
 import java.io.IOException;
 import java.text.ParseException;
 
@@ -35,286 +42,259 @@ public class SnapshotTransferTest
     extends AbstractProxyTestCase
 {
     public void testSnapshotNonExistant()
+        throws Exception
     {
         String path = "org/apache/maven/test/does-not-exist/1.0-SNAPSHOT/does-not-exist-1.0-SNAPSHOT.jar";
-        fail( "Implemented " + getName() );
-
-        //        String path = "org/apache/maven/test/does-not-exist/1.0-SNAPSHOT/does-not-exist-1.0-SNAPSHOT.jar";
-        //        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
-        //
-        //        assertFalse( expectedFile.exists() );
-        //
-        //        try
-        //        {
-        //            File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
-        //            fail( "File returned was: " + file + "; should have got a not found exception" );
-        //        }
-        //        catch ( ResourceDoesNotExistException e )
-        //        {
-        //            // expected, but check file was not created
-        //            assertFalse( expectedFile.exists() );
-        //        }        
+        File expectedFile = new File( managedDefaultDir, path );
+        ArtifactReference artifact = createArtifactReference( "default", path );
+
+        expectedFile.delete();
+        assertFalse( expectedFile.exists() );
+
+        // 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 );
+        assertNotDownloaded( downloadedFile );
+        assertNoTempFiles( expectedFile );
     }
 
     public void testTimestampDrivenSnapshotNotPresentAlready()
+        throws Exception
     {
-        String path = "org/apache/maven/test/does-not-exist/1.0-SNAPSHOT/does-not-exist-1.0-SNAPSHOT.jar";
-        fail( "Implemented " + getName() );
-
-        //        String path =
-        //            "org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar";
-        //        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
-        //
-        //        expectedFile.delete();
-        //        assertFalse( expectedFile.exists() );
-        //
-        //        File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
-        //
-        //        assertEquals( "Check file matches", expectedFile, file );
-        //        assertTrue( "Check file created", file.exists() );
-        //        File proxiedFile = new File( proxiedRepository1.getBasedir(), path );
-        //        String expectedContents = FileUtils.readFileToString( proxiedFile, null );
-        //        assertEquals( "Check file contents", expectedContents, FileUtils.readFileToString( file, null ) );
+        String path = "org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar";
+        File expectedFile = new File( managedDefaultDir, path );
+        ArtifactReference artifact = createArtifactReference( "default", path );
+
+        expectedFile.delete();
+        assertFalse( expectedFile.exists() );
+
+        // 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 );
+
+        File proxiedFile = new File( REPOPATH_PROXIED1, path );
+        assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+        assertNoTempFiles( expectedFile );
     }
 
     public void testNewerTimestampDrivenSnapshotOnFirstRepo()
-        throws ResourceDoesNotExistException, ProxyException, IOException, ParseException
+        throws Exception
     {
-        fail( "Implemented " + getName() );
-
-        //        String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
-        //        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
-        //
-        //        assertTrue( expectedFile.exists() );
-        //
-        //        expectedFile.setLastModified( getPastDate().getTime() );
-        //
-        //        File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
-        //
-        //        assertEquals( "Check file matches", expectedFile, file );
-        //        assertTrue( "Check file created", file.exists() );
-        //        File proxiedFile = new File( proxiedRepository1.getBasedir(), path );
-        //        String expectedContents = FileUtils.readFileToString( proxiedFile, null );
-        //        assertEquals( "Check file contents", expectedContents, FileUtils.readFileToString( file, null ) );
+        String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
+        File expectedFile = new File( managedDefaultDir, path );
+        ArtifactReference artifact = createArtifactReference( "default", path );
+
+        assertTrue( expectedFile.exists() );
+        expectedFile.setLastModified( getPastDate().getTime() );
+
+        // 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 );
+
+        File proxiedFile = new File( REPOPATH_PROXIED1, path );
+        assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+        assertNoTempFiles( expectedFile );
     }
 
     public void testOlderTimestampDrivenSnapshotOnFirstRepo()
-        throws ResourceDoesNotExistException, ProxyException, IOException
+        throws Exception
     {
-        fail( "Implemented " + getName() );
-
-        //        String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
-        //        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
-        //        String expectedContents = FileUtils.readFileToString( expectedFile, null );
-        //
-        //        assertTrue( expectedFile.exists() );
-        //
-        //        expectedFile.setLastModified( getFutureDate().getTime() );
-        //
-        //        proxiedRepository1.getSnapshots().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS );
-        //        File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
-        //
-        //        assertEquals( "Check file matches", expectedFile, file );
-        //        assertTrue( "Check file created", file.exists() );
-        //        assertEquals( "Check file contents", expectedContents, FileUtils.readFileToString( file, null ) );
-        //
-        //        File proxiedFile = new File( proxiedRepository1.getBasedir(), path );
-        //        String unexpectedContents = FileUtils.readFileToString( proxiedFile, null );
-        //        assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.readFileToString( file, null ) ) );
+        String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
+        File expectedFile = new File( managedDefaultDir, path );
+        ArtifactReference artifact = createArtifactReference( "default", 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 );
+
+        File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+
+        File proxiedFile = new File( REPOPATH_PROXIED1, path );
+        assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+        assertNoTempFiles( expectedFile );
     }
 
+    /**
+     * TODO: Has problems with wagon implementation not preserving timestamp.
+     */
     public void testNewerTimestampDrivenSnapshotOnSecondRepoThanFirstNotPresentAlready()
         throws Exception
     {
-        // TODO: wagon may not support timestamps (yet)
-        fail( "Implemented " + getName() );
-
-        //        String path = "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar";
-        //        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
-        //
-        //        assertFalse( expectedFile.exists() );
-        //
-        //        File repoLocation = getTestFile( "target/test-repository/proxied1" );
-        //        FileUtils.deleteDirectory( repoLocation );
-        //        copyDirectoryStructure( getTestFile( "src/test/repositories/proxied1" ), repoLocation );
-        //        proxiedRepository1 = createRepository( "proxied1", repoLocation );
-        //
-        //        new File( proxiedRepository1.getBasedir(), path ).setLastModified( getPastDate().getTime() );
-        //
-        //        proxiedRepositories.clear();
-        //        proxiedRepositories.add( createProxiedRepository( proxiedRepository1 ) );
-        //        proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) );
-        //
-        //        File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
-        //
-        //        assertEquals( "Check file matches", expectedFile, file );
-        //        assertTrue( "Check file created", file.exists() );
-        //
-        //        File proxiedFile = new File( proxiedRepository2.getBasedir(), path );
-        //        String expectedContents = FileUtils.readFileToString( proxiedFile, null );
-        //        assertEquals( "Check file contents", expectedContents, FileUtils.readFileToString( file, null ) );
-        //
-        //        proxiedFile = new File( proxiedRepository1.getBasedir(), path );
-        //        String unexpectedContents = FileUtils.readFileToString( proxiedFile, null );
-        //        assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.readFileToString( file, null ) ) );
+        String path = "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar";
+        File expectedFile = new File( managedDefaultDir, path );
+        ArtifactReference artifact = createArtifactReference( "default", path );
+
+        expectedFile.delete();
+        assertFalse( expectedFile.exists() );
+
+        // Create customized proxy / target repository
+        File targetProxyDir = saveTargetedRepositoryConfig( ID_PROXIED1_TARGET, REPOPATH_PROXIED1,
+                                                            REPOPATH_PROXIED1_TARGET, "default" );
+
+        new File( targetProxyDir, path ).setLastModified( getPastDate().getTime() );
+
+        // Configure Connector (usually done within archiva.xml configuration)
+        saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1_TARGET, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
+                       SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+        saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
+                       SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+
+        File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+
+        // Should have downloaded the content from proxy2, as proxy1 has an old (by file.lastModified check) version.
+        File proxiedFile = new File( REPOPATH_PROXIED2, path );
+        assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+        assertNoTempFiles( expectedFile );
     }
 
     public void testOlderTimestampDrivenSnapshotOnSecondRepoThanFirstNotPresentAlready()
         throws Exception
     {
-        fail( "Implemented " + getName() );
-
-        //        String path = "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar";
-        //        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
-        //
-        //        expectedFile.delete();
-        //        assertFalse( expectedFile.exists() );
-        //
-        //        File repoLocation = getTestFile( "target/test-repository/proxied2" );
-        //        FileUtils.deleteDirectory( repoLocation );
-        //        copyDirectoryStructure( getTestFile( "src/test/repositories/proxied2" ), repoLocation );
-        //        proxiedRepository2 = createRepository( "proxied2", repoLocation );
-        //
-        //        new File( proxiedRepository2.getBasedir(), path ).setLastModified( getPastDate().getTime() );
-        //
-        //        proxiedRepositories.clear();
-        //        proxiedRepositories.add( createProxiedRepository( proxiedRepository1 ) );
-        //        proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) );
-        //
-        //        File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
-        //
-        //        assertEquals( "Check file matches", expectedFile, file );
-        //        assertTrue( "Check file created", file.exists() );
-        //
-        //        File proxiedFile = new File( proxiedRepository1.getBasedir(), path );
-        //        String expectedContents = FileUtils.readFileToString( proxiedFile, null );
-        //        assertEquals( "Check file contents", expectedContents, FileUtils.readFileToString( file, null ) );
-        //
-        //        proxiedFile = new File( proxiedRepository2.getBasedir(), path );
-        //        String unexpectedContents = FileUtils.readFileToString( proxiedFile, null );
-        //        assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.readFileToString( file, null ) ) );
+        String path = "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar";
+        File expectedFile = new File( managedDefaultDir, path );
+        ArtifactReference artifact = createArtifactReference( "default", path );
+
+        expectedFile.delete();
+        assertFalse( expectedFile.exists() );
+
+        // Create customized proxy / target repository
+        File targetProxyDir = saveTargetedRepositoryConfig( ID_PROXIED2_TARGET, REPOPATH_PROXIED2,
+                                                            REPOPATH_PROXIED2_TARGET, "default" );
+
+        new File( targetProxyDir, path ).setLastModified( getPastDate().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_PROXIED2_TARGET, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
+                       SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
+
+        File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+
+        File proxiedFile = new File( REPOPATH_PROXIED1_TARGET, path );
+        assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+        assertNoTempFiles( expectedFile );
     }
 
     public void testTimestampDrivenSnapshotNotExpired()
         throws Exception
     {
-        fail( "Implemented " + getName() );
-
-        //        String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
-        //        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
-        //
-        //        assertTrue( expectedFile.exists() );
-        //
-        //        File proxiedFile = new File( proxiedRepository1.getBasedir(), path );
-        //        proxiedFile.setLastModified( getFutureDate().getTime() );
-        //
-        //        File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
-        //
-        //        assertEquals( "Check file matches", expectedFile, file );
-        //        assertTrue( "Check file created", file.exists() );
-        //        String expectedContents = FileUtils.readFileToString( expectedFile, null );
-        //        assertEquals( "Check file contents", expectedContents, FileUtils.readFileToString( file, null ) );
-        //
-        //        String unexpectedContents = FileUtils.readFileToString( proxiedFile, null );
-        //        assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.readFileToString( file, null ) ) );
+        String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
+        File expectedFile = new File( managedDefaultDir, path );
+        ArtifactReference artifact = createArtifactReference( "default", path );
+
+        assertTrue( expectedFile.exists() );
+
+        File proxiedFile = new File( REPOPATH_PROXIED1, path );
+        proxiedFile.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 );
+
+        File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+
+        assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+        assertNoTempFiles( expectedFile );
     }
 
     public void testTimestampDrivenSnapshotNotUpdated()
         throws Exception
     {
-        fail( "Implemented " + getName() );
-
-        //        String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
-        //        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
-        //        String expectedContents = FileUtils.readFileToString( expectedFile, null );
-        //
-        //        assertTrue( expectedFile.exists() );
-        //
-        //        File proxiedFile = new File( proxiedRepository1.getBasedir(), path );
-        //        expectedFile.setLastModified( proxiedFile.lastModified() );
-        //
-        //        proxiedRepository1.getSnapshots().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS );
-        //        File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
-        //
-        //        assertEquals( "Check file matches", expectedFile, file );
-        //        assertTrue( "Check file created", file.exists() );
-        //        assertEquals( "Check file contents", expectedContents, FileUtils.readFileToString( file, null ) );
-        //
-        //        String unexpectedContents = FileUtils.readFileToString( proxiedFile, null );
-        //        assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.readFileToString( file, null ) ) );
+        String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
+        File expectedFile = new File( managedDefaultDir, path );
+        ArtifactReference artifact = createArtifactReference( "default", 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 );
+        assertNoTempFiles( expectedFile );
     }
 
     public void testTimestampDrivenSnapshotNotPresentAlreadyExpiredCacheFailure()
-        throws ResourceDoesNotExistException, ProxyException, IOException
+        throws Exception
     {
-        fail( "Implemented " + getName() );
-
-        //        String path = "org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar";
-        //        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
-        //
-        //        expectedFile.delete();
-        //        assertFalse( expectedFile.exists() );
-        //
-        //        proxiedRepositories.clear();
-        //        ProxiedArtifactRepository proxiedArtifactRepository = createProxiedRepository( proxiedRepository1 );
-        //        proxiedArtifactRepository.addFailure( path, ALWAYS_UPDATE_POLICY );
-        //        proxiedRepositories.add( proxiedArtifactRepository );
-        //        proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) );
-        //        File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
-        //
-        //        assertEquals( "Check file matches", expectedFile, file );
-        //        assertTrue( "Check file created", file.exists() );
-        //
-        //        File proxiedFile = new File( proxiedRepository1.getBasedir(), path );
-        //        String expectedContents = FileUtils.readFileToString( proxiedFile, null );
-        //        assertEquals( "Check file contents", expectedContents, FileUtils.readFileToString( file, null ) );
-        //
-        //        assertFalse( "Check failure", proxiedArtifactRepository.isCachedFailure( path ) );
+        String path = "org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar";
+        File expectedFile = new File( managedDefaultDir, path );
+        ArtifactReference artifact = createArtifactReference( "default", path );
+
+        expectedFile.delete();
+        assertFalse( expectedFile.exists() );
+
+        // Configure Connector (usually done within archiva.xml configuration)
+        saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
+                       SnapshotsPolicy.IGNORED, CachedFailuresPolicy.CACHED );
+        saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
+                       SnapshotsPolicy.IGNORED, CachedFailuresPolicy.CACHED );
+
+        File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
+
+        File proxiedFile = new File( REPOPATH_PROXIED1, path );
+        assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+        assertNoTempFiles( expectedFile );
     }
 
     public void testMetadataDrivenSnapshotNotPresentAlready()
-        throws ResourceDoesNotExistException, ProxyException, IOException
+        throws Exception
     {
-        fail( "Implemented " + getName() );
-
-        //        String path = "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/get-metadata-snapshot-1.0-20050831.101112-1.jar";
-        //        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
-        //
-        //        expectedFile.delete();
-        //        assertFalse( expectedFile.exists() );
-        //
-        //        File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
-        //
-        //        assertEquals( "Check file matches", expectedFile, file );
-        //        assertTrue( "Check file created", file.exists() );
-        //        File proxiedFile = new File( proxiedRepository1.getBasedir(), path );
-        //        String expectedContents = FileUtils.readFileToString( proxiedFile, null );
-        //        assertEquals( "Check file contents", expectedContents, FileUtils.readFileToString( file, null ) );
+        String path = "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/get-metadata-snapshot-1.0-20050831.101112-1.jar";
+        File expectedFile = new File( managedDefaultDir, path );
+        ArtifactReference artifact = createArtifactReference( "default", path );
+
+        expectedFile.delete();
+        assertFalse( expectedFile.exists() );
+
+        // 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 );
+
+        File proxiedFile = new File( REPOPATH_PROXIED1, path );
+        assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+        assertNoTempFiles( expectedFile );
     }
 
     public void testGetMetadataDrivenSnapshotRemoteUpdate()
-        throws ResourceDoesNotExistException, ProxyException, IOException, ParseException
+        throws Exception
     {
-        fail( "Implemented " + getName() );
-
-        // Metadata driven snapshots (using a full timestamp) are treated like a release. It is the timing of the
+         // Metadata driven snapshots (using a full timestamp) are treated like a release. It is the timing of the
         // updates to the metadata files that triggers which will be downloaded
 
-        //        String path = "org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar";
-        //        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
-        //        String expectedContents = FileUtils.readFileToString( expectedFile, null );
-        //
-        //        assertTrue( expectedFile.exists() );
-        //
-        //        expectedFile.setLastModified( getPastDate().getTime() );
-        //
-        //        File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository );
-        //
-        //        assertEquals( "Check file matches", expectedFile, file );
-        //        assertTrue( "Check file created", file.exists() );
-        //        assertEquals( "Check file contents", expectedContents, FileUtils.readFileToString( file, null ) );
-        //        File proxiedFile = new File( proxiedRepository1.getBasedir(), path );
-        //        String unexpectedContents = FileUtils.readFileToString( proxiedFile, null );
-        //        assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.readFileToString( file, null ) ) );
+        String path = "org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar";
+        File expectedFile = new File( managedDefaultDir, path );
+        ArtifactReference artifact = createArtifactReference( "default", path );
+
+        assertTrue( expectedFile.exists() );
+
+        expectedFile.setLastModified( getPastDate().getTime() );
+
+        // 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 );
+
+        File proxiedFile = new File( REPOPATH_PROXIED1, path );
+        assertFileEquals( expectedFile, downloadedFile, proxiedFile );
+        assertNoTempFiles( expectedFile );
     }
 }
diff --git a/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/RelocateTransferTest.xml b/archiva-base/archiva-proxy/src/test/resources/org/apache/maven/archiva/proxy/RelocateTransferTest.xml
new file mode 100644 (file)
index 0000000..6daa370
--- /dev/null
@@ -0,0 +1,72 @@
+<!--
+  ~ 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.
+  -->
+
+<component-set>
+  <components>
+    <component>
+      <role>org.apache.maven.wagon.Wagon</role>
+      <role-hint>test</role-hint>
+      <implementation>org.apache.maven.archiva.proxy.WagonDelegate</implementation>
+    </component>
+    <component>
+      <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
+      <role-hint>mock</role-hint>
+      <implementation>org.apache.maven.archiva.proxy.MockConfiguration</implementation>
+    </component>
+    <component>
+      <role>org.apache.maven.archiva.proxy.RepositoryProxyConnectors</role>
+      <role-hint>default</role-hint>
+      <implementation>org.apache.maven.archiva.proxy.DefaultRepositoryProxyConnectors</implementation>
+      <description>DefaultRepositoryProxyConnectors</description>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
+          <role-hint>mock</role-hint>
+          <field-name>archivaConfiguration</field-name>
+        </requirement>
+        <requirement>
+          <role>org.apache.maven.wagon.Wagon</role>
+          <field-name>wagons</field-name>
+        </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory</role>
+          <field-name>layoutFactory</field-name>
+        </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.policies.PreDownloadPolicy</role>
+          <field-name>preDownloadPolicies</field-name>
+        </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.policies.PostDownloadPolicy</role>
+          <field-name>postDownloadPolicies</field-name>
+        </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.policies.urlcache.UrlFailureCache</role>
+          <role-hint>default</role-hint>
+          <field-name>urlFailureCache</field-name>
+        </requirement>
+      </requirements>
+    </component>
+    <component>
+      <role>org.codehaus.plexus.logging.LoggerManager</role>
+      <implementation>org.codehaus.plexus.logging.slf4j.Slf4jLoggerManager</implementation>
+      <lifecycle-handler>basic</lifecycle-handler>
+    </component>
+  </components>
+</component-set>
\ No newline at end of file