From 322c16f688a286da1b96884ea613dd69da864eb4 Mon Sep 17 00:00:00 2001
From: Joakim Erdfelt
* Quietly transfer the checksum file from the remote repository to the local file.
- *
+ * NotModifiedException - thrown when the resource requested was found on the remote repository, but + * the remote repository reported that the copy we have in our managed repository is newer than + * the one present on the remote repository. + *
+ *
+ * Similar in scope to the HTTP 304 Not Modified
response code.
+ *
+ * Request a file, that exists locally, and remotely. + *
+ *+ * All policies are set to IGNORE. + *
+ *+ * Managed file is newer than remote file. + *
+ *+ * Transfer should not have occured, as managed file is newer. + *
* * @throws Exception */ - public void testGetDefaultLayoutAlreadyPresentPolicyIgnored() + public void testGetDefaultLayoutAlreadyPresentNewerThanRemotePolicyIgnored() throws Exception { String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; setupTestableManagedRepository( path ); File expectedFile = new File( managedDefaultDir, path ); + File remoteFile = new File( REPOPATH_PROXIED1, path ); + + // Set the managed File to be newer than local. + setManagedNewerThanRemote( expectedFile, remoteFile ); long originalModificationTime = expectedFile.lastModified(); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); @@ -122,30 +134,52 @@ public class ManagedDefaultTransferTest // Attempt the proxy fetch. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + assertNotDownloaded( downloadedFile ); + assertNotModified( expectedFile, originalModificationTime ); + assertNoTempFiles( expectedFile ); + } + + /** + *+ * Request a file, that exists locally, and remotely. + *
+ *+ * All policies are set to IGNORE. + *
+ *+ * Managed file is older than Remote file. + *
+ *+ * Transfer should have occured, as managed file is older than remote. + *
+ * + * @throws Exception + */ + public void testGetDefaultLayoutAlreadyPresentOlderThanRemotePolicyIgnored() + throws Exception + { + String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; + setupTestableManagedRepository( path ); + + File expectedFile = new File( managedDefaultDir, path ); + File remoteFile = new File( REPOPATH_PROXIED1, path ); + + // Set the managed file to be newer than remote file. + setManagedOlderThanRemote( expectedFile, remoteFile ); + + ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); + + assertTrue( expectedFile.exists() ); + + // Configure Connector (usually done within archiva.xml configuration) + saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED, + SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED ); + + // Attempt the proxy fetch. + File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + File proxiedFile = new File( REPOPATH_PROXIED1, path ); assertFileEquals( expectedFile, downloadedFile, proxiedFile ); - - long proxiedLastModified = proxiedFile.lastModified(); - long downloadedLastModified = downloadedFile.lastModified(); - assertFalse( "Check file timestamp is not that of proxy:", proxiedLastModified == downloadedLastModified ); - - if ( originalModificationTime != downloadedLastModified ) - { - /* On some systems the timestamp functions are not accurate enough. - * This delta is the amount of milliseconds of 'fudge factor' we allow for - * the unit test to still be considered 'passed'. - */ - int delta = 20000; - - long hirange = originalModificationTime + ( delta / 2 ); - long lorange = originalModificationTime - ( delta / 2 ); - - if ( ( downloadedLastModified < lorange ) || ( downloadedLastModified > hirange ) ) - { - fail( "Check file timestamp is that of original managed file: expected within range lo:<" + lorange + - "> hi:<" + hirange + "> but was:<" + downloadedLastModified + ">" ); - } - } assertNoTempFiles( expectedFile ); } @@ -189,14 +223,11 @@ public class ManagedDefaultTransferTest File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - expectedFile.delete(); - assertFalse( expectedFile.exists() ); + assertNotExistsInManagedDefaultRepo( expectedFile ); // Configure Connector (usually done within archiva.xml configuration) - saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED, - SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED ); - saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED, - SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED ); + saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1 ); + saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2 ); // Attempt the proxy fetch. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); @@ -222,14 +253,11 @@ public class ManagedDefaultTransferTest File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - expectedFile.delete(); - assertFalse( expectedFile.exists() ); + assertNotExistsInManagedDefaultRepo( expectedFile ); // Configure Connector (usually done within archiva.xml configuration) - saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED, - SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED ); - saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED, - SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED ); + saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1 ); + saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2 ); // Attempt the proxy fetch. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); @@ -248,15 +276,12 @@ public class ManagedDefaultTransferTest File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - assertFalse( expectedFile.exists() ); + assertNotExistsInManagedDefaultRepo( expectedFile ); // Configure Connector (usually done within archiva.xml configuration) - saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED, - SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED ); - saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED, - SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED ); - saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED, - SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED ); + saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1 ); + saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2 ); + saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED ); // Attempt the proxy fetch. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); @@ -275,14 +300,13 @@ public class ManagedDefaultTransferTest File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - expectedFile.delete(); - assertFalse( expectedFile.exists() ); + assertNotExistsInManagedDefaultRepo( expectedFile ); // Configure Repository (usually done within archiva.xml configuration) saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "test://bad.machine.com/repo/", "default" ); - wagonMock.getIfNewer( path, new File( expectedFile.getAbsolutePath() + ".tmp" ), 0 ); - wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); + wagonMock.get( path, new File( expectedFile.getAbsolutePath() + ".tmp" ) ); + wagonMockControl.setThrowable( new ResourceDoesNotExistException( "transfer failed" ) ); wagonMockControl.replay(); // Configure Connector (usually done within archiva.xml configuration) @@ -308,8 +332,7 @@ public class ManagedDefaultTransferTest File expectedFile = new File( managedDefaultDir.getAbsoluteFile(), path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - expectedFile.delete(); - assertFalse( expectedFile.exists() ); + assertNotExistsInManagedDefaultRepo( expectedFile ); // Configure Repository (usually done within archiva.xml configuration) saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" ); @@ -320,11 +343,11 @@ public class ManagedDefaultTransferTest saveConnector( ID_DEFAULT_MANAGED, "badproxied2" ); File tmpFile = new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ); - wagonMock.getIfNewer( path, tmpFile, 0 ); - wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); + wagonMock.get( path, tmpFile ); + wagonMockControl.setThrowable( new ResourceDoesNotExistException( "Can't find resource." ) ); - wagonMock.getIfNewer( path, tmpFile, 0 ); - wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); + wagonMock.get( path, tmpFile ); + wagonMockControl.setThrowable( new ResourceDoesNotExistException( "Can't find resource." ) ); wagonMockControl.replay(); @@ -339,48 +362,53 @@ public class ManagedDefaultTransferTest // TODO: How much information on each failure should we pass back to the user vs. logging in the proxy? } - public void testLegacyProxyRepoGetAlreadyPresent() + public void testGetFromLegacyProxyAlreadyPresentInManaged_NewerThanRemote() throws Exception { + String legacyPath = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar"; String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; setupTestableManagedRepository( path ); File expectedFile = new File( managedDefaultDir, path ); + File remoteFile = new File( REPOPATH_PROXIED_LEGACY, legacyPath ); + + // Set the managed file to be newer than remote. + setManagedNewerThanRemote( expectedFile, remoteFile ); + long expectedTimestamp = expectedFile.lastModified(); + ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - + assertTrue( expectedFile.exists() ); // Configure Connector (usually done within archiva.xml configuration) - saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED, - SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED ); + saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED ); File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); - File proxiedFile = - new File( REPOPATH_PROXIED_LEGACY, "org.apache.maven.test/jars/get-default-layout-present-1.0.jar" ); - assertFileEquals( expectedFile, downloadedFile, proxiedFile ); + assertNotDownloaded( downloadedFile ); + assertNotModified( expectedFile, expectedTimestamp ); assertNoTempFiles( expectedFile ); } - - public void testLegacyRequestConvertedToDefaultPathInManagedRepo() + + public void testGetFromLegacyProxyAlreadyPresentInManaged_OlderThanRemote() throws Exception { - // Check that a Maven1 legacy request is translated to a maven2 path in - // the managed repository. - String legacyPath = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar"; String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; setupTestableManagedRepository( path ); File expectedFile = new File( managedDefaultDir, path ); + File remoteFile = new File( REPOPATH_PROXIED_LEGACY, legacyPath ); + + // Set the managed file to be older than remote. + setManagedOlderThanRemote( expectedFile, remoteFile ); + ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - expectedFile.delete(); - assertFalse( expectedFile.exists() ); + assertTrue( expectedFile.exists() ); // Configure Connector (usually done within archiva.xml configuration) - saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED, - SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED ); + saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED ); File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); @@ -389,26 +417,20 @@ public class ManagedDefaultTransferTest assertNoTempFiles( expectedFile ); } - /* FIXME - public void testLegacyRequestPluginConvertedToDefaultPathInManagedRepo() + public void testGetFromLegacyProxyNotPresentInManaged() throws Exception { - // Check that a Maven1 legacy request is translated to a maven2 path in - // the managed repository. - - String legacyPath = "org.apache.maven.test/plugins/get-legacy-plugin-1.0.jar"; - String path = "org/apache/maven/test/get-legacy-plugin/1.0/get-legacy-plugin-1.0.jar"; + String legacyPath = "org.apache.maven.test/jars/example-lib-2.2.jar"; + String path = "org/apache/maven/test/example-lib/2.2/example-lib-2.2.jar"; setupTestableManagedRepository( path ); File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - expectedFile.delete(); - assertFalse( expectedFile.exists() ); + assertNotExistsInManagedDefaultRepo( expectedFile ); // Configure Connector (usually done within archiva.xml configuration) - saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED, - SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED ); + saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED ); File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); @@ -416,31 +438,26 @@ public class ManagedDefaultTransferTest assertFileEquals( expectedFile, downloadedFile, proxiedFile ); assertNoTempFiles( expectedFile ); } - */ - public void testLegacyProxyRepoGetNotPresent() + public void testGetFromLegacyProxyPluginNotPresentInManaged() throws Exception { - String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; + String legacyPath = "org.apache.maven.test/plugins/example-maven-plugin-0.42.jar"; + String path = "org/apache/maven/test/example-maven-plugin/0.42/example-maven-plugin-0.42.jar"; setupTestableManagedRepository( path ); File expectedFile = new File( managedDefaultDir, path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - expectedFile.delete(); - assertFalse( expectedFile.exists() ); + assertNotExistsInManagedDefaultRepo( expectedFile ); // Configure Connector (usually done within archiva.xml configuration) - saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED, - SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED ); + saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED ); File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); - File proxiedFile = new File( REPOPATH_PROXIED_LEGACY, "org.apache.maven.test/jars/get-default-layout-1.0.jar" ); + File proxiedFile = new File( REPOPATH_PROXIED_LEGACY, legacyPath ); assertFileEquals( expectedFile, downloadedFile, proxiedFile ); assertNoTempFiles( expectedFile ); - - // TODO: timestamp preservation requires support for that in wagon - // assertEquals( "Check file timestamp", proxiedFile.lastModified(), file.lastModified() ); } } diff --git a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.java b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.java index 43cffac86..b7a9301a9 100644 --- a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.java +++ b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.java @@ -37,39 +37,46 @@ import java.io.File; public class ManagedLegacyTransferTest extends AbstractProxyTestCase { - public void testLegacyManagedRepoGetNotPresent() + /** + * Incoming request on a Managed Legacy repository, for content that does not + * exist in the managed legacy repository, but does exist on a remote default layout repository. + */ + public void testManagedLegacyNotPresentRemoteDefaultPresent() throws Exception { String path = "org.apache.maven.test/jars/get-default-layout-1.0.jar"; File expectedFile = new File( managedLegacyDir, path ); ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path ); - - expectedFile.delete(); - assertFalse( expectedFile.exists() ); - + + assertNotExistsInManagedLegacyRepo( expectedFile ); + // Configure Connector (usually done within archiva.xml configuration) - saveConnector( ID_LEGACY_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED, - SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED ); - + saveConnector( ID_LEGACY_MANAGED, ID_PROXIED1 ); + File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact ); - + File proxied2File = new File( REPOPATH_PROXIED1, "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar" ); assertFileEquals( expectedFile, downloadedFile, proxied2File ); assertNoTempFiles( expectedFile ); - - // TODO: timestamp preservation requires support for that in wagon - // assertEquals( "Check file timestamp", proxiedFile.lastModified(), file.lastModified() ); } - public void testLegacyManagedRepoGetAlreadyPresent() + /** + * Incoming request on a Managed Legacy repository, for content that already + * exist in the managed legacy repository, and also exist on a remote default layout repository. + */ + public void testManagedLegacyPresentRemoteDefaultPresent() throws Exception { String path = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar"; + String remotePath = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; + File expectedFile = new File( managedLegacyDir, path ); - ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path ); + File remoteFile = new File( REPOPATH_PROXIED1, remotePath ); - assertTrue( expectedFile.exists() ); + setManagedOlderThanRemote( expectedFile, remoteFile ); + + ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_LEGACY_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED, @@ -77,79 +84,142 @@ public class ManagedLegacyTransferTest File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact ); - File proxied2File = new File( REPOPATH_PROXIED1, - "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar" ); - assertFileEquals( expectedFile, downloadedFile, proxied2File ); + assertFileEquals( expectedFile, downloadedFile, remoteFile ); assertNoTempFiles( expectedFile ); } - public void testLegacyManagedAndProxyRepoGetNotPresent() + /** + * Incoming request on a Managed Legacy repository, for content that does not + * exist in the managed legacy repository, and does not exist on a remote legacy layout repository. + */ + public void testManagedLegacyNotPresentRemoteLegacyPresent() throws Exception { - String path = "org.apache.maven.test/jars/get-default-layout-1.0.jar"; + String path = "org.apache.maven.test/plugins/get-legacy-plugin-1.0.jar"; File expectedFile = new File( managedLegacyDir, path ); ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path ); - assertFalse( expectedFile.exists() ); + assertNotExistsInManagedLegacyRepo( expectedFile ); // Configure Connector (usually done within archiva.xml configuration) - saveConnector( ID_LEGACY_MANAGED, ID_LEGACY_PROXIED, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED, - SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED ); + saveConnector( ID_LEGACY_MANAGED, ID_LEGACY_PROXIED ); File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact ); File proxiedFile = new File( REPOPATH_PROXIED_LEGACY, path ); assertFileEquals( expectedFile, downloadedFile, proxiedFile ); assertNoTempFiles( expectedFile ); - - // TODO: timestamp preservation requires support for that in wagon - // assertEquals( "Check file timestamp", proxiedFile.lastModified(), file.lastModified() ); } - public void testLegacyManagedAndProxyRepoGetAlreadyPresent() + /** + * Incoming request on a Managed Legacy repository, for content that does exist in the + * managed legacy repository, and also exists on a remote legacy layout repository. + */ + public void testManagedLegacyPresentRemoteLegacyPresent() throws Exception { String path = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar"; File expectedFile = new File( managedLegacyDir, path ); + File remoteFile = new File( REPOPATH_PROXIED_LEGACY, path ); + + setManagedOlderThanRemote( expectedFile, remoteFile ); + + ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path ); + + // Configure Connector (usually done within archiva.xml configuration) + saveConnector( ID_LEGACY_MANAGED, ID_LEGACY_PROXIED ); + + File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact ); + + assertFileEquals( expectedFile, downloadedFile, remoteFile ); + assertNoTempFiles( expectedFile ); + } + + /** + * Incoming request on a Managed Legacy repository, for content that does exist in the + * managed legacy repository, and does not exist on a remote legacy layout repository. + */ + public void testManagedLegacyPresentRemoteLegacyNotPresent() + throws Exception + { + String path = "org.apache.maven.test/jars/managed-only-lib-2.1.jar"; + File expectedFile = new File( managedLegacyDir, path ); ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path ); assertTrue( expectedFile.exists() ); // Configure Connector (usually done within archiva.xml configuration) - saveConnector( ID_LEGACY_MANAGED, ID_LEGACY_PROXIED, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED, - SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED ); + saveConnector( ID_LEGACY_MANAGED, ID_LEGACY_PROXIED ); File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact ); - File proxiedFile = new File( REPOPATH_PROXIED_LEGACY, path ); - assertFileEquals( expectedFile, downloadedFile, proxiedFile ); + assertNotDownloaded( downloadedFile ); assertNoTempFiles( expectedFile ); } - /* FIXME - public void testDefaultRequestConvertedToLegacyPathInManagedRepo() + /** + * Incoming request on a Managed Legacy repository, for content that does exist in the + * managed legacy repository, and does not exists on a remote default layout repository. + */ + public void testManagedLegacyPresentRemoteDefaultNotPresent() throws Exception { - // Check that a Maven2 default request is translated to a legacy path in - // the managed repository. + String path = "org.apache.maven.test/jars/managed-only-lib-2.1.jar"; + File expectedFile = new File( managedLegacyDir, path ); + ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path ); + + assertTrue( expectedFile.exists() ); + + // Configure Connector (usually done within archiva.xml configuration) + saveConnector( ID_LEGACY_MANAGED, ID_PROXIED1 ); + + File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact ); - String legacyPath = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar"; - String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; - File expectedFile = new File( managedLegacyDir, legacyPath ); + assertNotDownloaded( downloadedFile ); + assertNoTempFiles( expectedFile ); + } + + /** + * Incoming request on a Managed Legacy repository, for content that does not exist in the + * managed legacy repository, and does not exists on a remote legacy layout repository. + */ + public void testManagedLegacyNotPresentRemoteLegacyNotPresent() + throws Exception + { + String path = "org.apache.archiva.test/jars/mystery-lib-1.0.jar"; + File expectedFile = new File( managedLegacyDir, path ); ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path ); - expectedFile.delete(); - assertFalse( expectedFile.exists() ); + assertNotExistsInManagedLegacyRepo( expectedFile ); // Configure Connector (usually done within archiva.xml configuration) - saveConnector( ID_LEGACY_MANAGED, ID_PROXIED1, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED, - SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED ); + saveConnector( ID_LEGACY_MANAGED, ID_LEGACY_PROXIED ); File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact ); - File proxiedFile = new File( REPOPATH_PROXIED1, path ); - assertFileEquals( expectedFile, downloadedFile, proxiedFile ); + assertNotDownloaded( downloadedFile ); + assertNoTempFiles( expectedFile ); + } + + /** + * Incoming request on a Managed Legacy repository, for content that does not exist in the + * managed legacy repository, and does not exists on a remote default layout repository. + */ + public void testManagedLegacyNotPresentRemoteDefaultNotPresent() + throws Exception + { + String path = "org.apache.archiva.test/jars/mystery-lib-2.1.jar"; + File expectedFile = new File( managedLegacyDir, path ); + ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path ); + + assertNotExistsInManagedLegacyRepo( expectedFile ); + + // Configure Connector (usually done within archiva.xml configuration) + saveConnector( ID_LEGACY_MANAGED, ID_PROXIED1 ); + + File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact ); + + assertNotDownloaded( downloadedFile ); assertNoTempFiles( expectedFile ); } - */ } diff --git a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MetadataTransferTest.java b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MetadataTransferTest.java index 117fb7551..e224b79c9 100644 --- a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MetadataTransferTest.java +++ b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MetadataTransferTest.java @@ -141,8 +141,6 @@ public class MetadataTransferTest String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml"; setupTestableManagedRepository( requestedResource ); - setupTestableManagedRepository( requestedResource ); - // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED, SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED ); @@ -169,8 +167,6 @@ public class MetadataTransferTest String requestedResource = "org/apache/maven/test/get-bogus-artifact/maven-metadata.xml"; setupTestableManagedRepository( requestedResource ); - setupTestableManagedRepository( requestedResource ); - // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.IGNORED, SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED ); diff --git a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/RelocateTransferTest.java b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/RelocateTransferTest.java deleted file mode 100644 index a23ace51d..000000000 --- a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/RelocateTransferTest.java +++ /dev/null @@ -1,171 +0,0 @@ -package org.apache.maven.archiva.proxy; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** - * RelocateTransferTest - * - * @author Brett Porter - * @author Joakim Erdfelt - * @version $Id$ - */ -public class RelocateTransferTest - extends AbstractProxyTestCase -{ - - public void testRelocateMaven1Request() - throws Exception - { - fail( "Implemented " + getName() ); - - // String path = "org.apache.maven.test/jars/get-relocated-artefact-1.0.jar"; - // String relocatedPath = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; - // File expectedFile = new File( defaultManagedRepository.getBasedir(), relocatedPath ); - // - // assertTrue( expectedFile.exists() ); - // - // File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - // - // assertEquals( "Check file matches", expectedFile, file ); - } - - public void testDoublyRelocateMaven1Request() - throws Exception - { - fail( "Implemented " + getName() ); - - // String path = "org.apache.maven.test/jars/get-doubly-relocated-artefact-1.0.jar"; - // String relocatedPath = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; - // File expectedFile = new File( defaultManagedRepository.getBasedir(), relocatedPath ); - // - // assertTrue( expectedFile.exists() ); - // - // File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - // - // assertEquals( "Check file matches", expectedFile, file ); - } - - public void testRelocateMaven1PomRequest() - throws Exception - { - fail( "Implemented " + getName() ); - - // String path = "org.apache.maven.test/poms/get-relocated-artefact-with-pom-1.0.pom"; - // String relocatedPath = "org/apache/maven/test/get-default-layout-present-with-pom/1.0/get-default-layout-present-with-pom-1.0.pom"; - // File expectedFile = new File( defaultManagedRepository.getBasedir(), relocatedPath ); - // - // assertTrue( expectedFile.exists() ); - // - // File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - // - // assertEquals( "Check file matches", expectedFile, file ); - // - // assertTrue( expectedFile.exists() ); - } - - public void testRelocateMaven1PomRequestMissingTarget() - throws Exception - { - fail( "Implemented " + getName() ); - - // String path = "org.apache.maven.test/poms/get-relocated-artefact-1.0.pom"; - // String relocatedPath = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.pom"; - // File expectedFile = new File( defaultManagedRepository.getBasedir(), relocatedPath ); - // - // assertFalse( expectedFile.exists() ); - // - // try - // { - // requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - // fail( "Should have failed to find target POM" ); - // } - // catch ( ResourceDoesNotExistException e ) - // { - // assertTrue( true ); - // } - } - - public void testRelocateMaven1ChecksumRequest() - throws Exception - { - fail( "Implemented " + getName() ); - - // String path = "org.apache.maven.test/jars/get-relocated-artefact-1.0.jar.md5"; - // String relocatedPath = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar.md5"; - // File expectedFile = new File( defaultManagedRepository.getBasedir(), relocatedPath ); - // - // assertTrue( expectedFile.exists() ); - // - // File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - // - // assertEquals( "Check file matches", expectedFile, file ); - // - // assertTrue( expectedFile.exists() ); - // - // path = "org.apache.maven.test/jars/get-relocated-artefact-1.0.jar.sha1"; - // relocatedPath = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar.sha1"; - // expectedFile = new File( defaultManagedRepository.getBasedir(), relocatedPath ); - // - // assertFalse( expectedFile.exists() ); - // - // try - // { - // requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - // fail( "Checksum was not present, should not be found" ); - // } - // catch ( ResourceDoesNotExistException e ) - // { - // assertTrue( true ); - // } - } - - public void testRelocateMaven2Request() - throws Exception - { - fail( "Implemented " + getName() ); - - // String path = "org/apache/maven/test/get-relocated-artefact/1.0/get-relocated-artefact-1.0.jar"; - // String relocatedPath = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; - // File expectedFile = new File( defaultManagedRepository.getBasedir(), relocatedPath ); - // - // assertTrue( expectedFile.exists() ); - // - // File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - // - // assertEquals( "Check file matches", expectedFile, file ); - } - - public void testRelocateMaven2RequestInLegacyManagedRepo() - throws Exception - { - fail( "Implemented " + getName() ); - - // String path = "org/apache/maven/test/get-relocated-artefact/1.0/get-relocated-artefact-1.0.jar"; - // String relocatedPath = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar"; - // File expectedFile = new File( legacyManagedRepository.getBasedir(), relocatedPath ); - // - // assertTrue( expectedFile.exists() ); - // - // File file = requestHandler.get( path, proxiedRepositories, legacyManagedRepository ); - // - // assertEquals( "Check file matches", expectedFile, file ); - } - -} diff --git a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/SnapshotTransferTest.java b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/SnapshotTransferTest.java index 0fc02a891..d182e1089 100644 --- a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/SnapshotTransferTest.java +++ b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/SnapshotTransferTest.java @@ -111,19 +111,20 @@ public class SnapshotTransferTest setupTestableManagedRepository( path ); File expectedFile = new File( managedDefaultDir, path ); + File remoteFile = new File( REPOPATH_PROXIED1, path ); + + setManagedNewerThanRemote( expectedFile, remoteFile ); + ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - assertTrue( expectedFile.exists() ); - expectedFile.setLastModified( getFutureDate().getTime() ); - // Configure Connector (usually done within archiva.xml configuration) - saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED, - SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED ); + saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1 ); + // Attempt to download. File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); - File proxiedFile = new File( REPOPATH_PROXIED1, path ); - assertFileEquals( expectedFile, downloadedFile, proxiedFile ); + // Should not have downloaded as managed is newer than remote. + assertNotDownloaded( downloadedFile ); assertNoTempFiles( expectedFile ); } @@ -225,12 +226,12 @@ public class SnapshotTransferTest setupTestableManagedRepository( path ); File expectedFile = new File( managedDefaultDir, path ); - ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - - assertTrue( expectedFile.exists() ); + File remoteFile = new File( REPOPATH_PROXIED1, path ); - File proxiedFile = new File( REPOPATH_PROXIED1, path ); - expectedFile.setLastModified( proxiedFile.lastModified() ); + setManagedNewerThanRemote( expectedFile, remoteFile ); + long expectedTimestamp = expectedFile.lastModified(); + + ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED, @@ -238,7 +239,8 @@ public class SnapshotTransferTest File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); - assertFileEquals( expectedFile, downloadedFile, proxiedFile ); + assertNotDownloaded( downloadedFile ); + assertNotModified( expectedFile, expectedTimestamp ); assertNoTempFiles( expectedFile ); } diff --git a/archiva-base/archiva-proxy/src/test/repositories/legacy-managed/org.apache.maven.test/jars/managed-only-lib-2.1.jar b/archiva-base/archiva-proxy/src/test/repositories/legacy-managed/org.apache.maven.test/jars/managed-only-lib-2.1.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-base/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/example-lib-2.2.jar b/archiva-base/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/example-lib-2.2.jar new file mode 100644 index 000000000..059fd2a70 --- /dev/null +++ b/archiva-base/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/example-lib-2.2.jar @@ -0,0 +1 @@ +(example jar found only in legacy proxy) diff --git a/archiva-base/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/plugins/example-maven-plugin-0.42.jar b/archiva-base/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/plugins/example-maven-plugin-0.42.jar new file mode 100644 index 000000000..2b7e3c5a0 --- /dev/null +++ b/archiva-base/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/plugins/example-maven-plugin-0.42.jar @@ -0,0 +1 @@ +(example maven plugin v0.42 found only in legacy proxy) -- 2.39.5