@Inject
protected ApplicationContext applicationContext;
- 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_DEFAULT_MANAGED = "default-managed-repository";
- protected static final String ID_LEGACY_MANAGED = "legacy-managed-repository";
-
- 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_DEFAULT_MANAGED_TARGET = "target/test-repository/managed";
- protected static final String REPOPATH_LEGACY_MANAGED = "src/test/repositories/legacy-managed";
-
- protected static final String REPOPATH_LEGACY_MANAGED_TARGET = "target/test-repository/legacy-managed";
-
protected IMocksControl wagonMockControl;
protected Wagon wagonMock;
protected File managedDefaultDir;
- protected ManagedRepositoryContent managedLegacyRepository;
-
- protected File managedLegacyDir;
-
protected MockConfiguration config;
protected Logger log = LoggerFactory.getLogger( getClass() );
// to prevent windauze file leaking
removeMavenIndexes();
- // Setup source repository (using legacy layout)
- repoLocation = new File( REPOPATH_LEGACY_MANAGED_TARGET );
- if ( repoLocation.exists() )
- {
- FileUtils.deleteDirectory( repoLocation );
- }
- copyDirectoryStructure( new File( REPOPATH_LEGACY_MANAGED ), repoLocation );
-
- managedLegacyRepository =
- createRepository( ID_LEGACY_MANAGED, "Legacy Managed Repository", REPOPATH_LEGACY_MANAGED_TARGET,
- "legacy" );
-
- managedLegacyDir = new File( managedLegacyRepository.getRepoRoot() );
-
- repoConfig = managedLegacyRepository.getRepository();
-
applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository( repoConfig, false, null );
// Setup target (proxied to) repository.
saveRemoteRepositoryConfig( ID_PROXIED2, "Proxied Repository 2",
new File( REPOPATH_PROXIED2 ).toURL().toExternalForm(), "default" );
- // Setup target (proxied to) repository using legacy layout.
- saveRemoteRepositoryConfig( ID_LEGACY_PROXIED, "Proxied Legacy Repository",
- new File( REPOPATH_PROXIED_LEGACY ).toURL().toExternalForm(), "legacy" );
-
// Setup the proxy handler.
//proxyHandler = applicationContext.getBean (RepositoryProxyConnectors) lookup( RepositoryProxyConnectors.class.getName() );
}
}
- protected ManagedRepositoryContent createManagedLegacyRepository()
- throws Exception
- {
- return createRepository( "testManagedLegacyRepo", "Test Managed (Legacy) Repository",
- "src/test/repositories/legacy-managed", "legacy" );
- }
-
- protected ManagedRepositoryContent createProxiedLegacyRepository()
- throws Exception
- {
- return createRepository( "testProxiedLegacyRepo", "Test Proxied (Legacy) Repository",
- "src/test/repositories/legacy-proxied", "legacy" );
- }
protected ManagedRepositoryContent createRepository( String id, String name, String path, String layout )
throws Exception
file.lastModified() );
}
- protected void assertNotExistsInManagedLegacyRepo( File file )
- throws Exception
- {
- String managedLegacyPath = managedLegacyDir.getCanonicalPath();
- String testFile = file.getCanonicalPath();
-
- assertTrue(
- "Unit Test Failure: File <" + testFile + "> should be have been defined within the legacy managed path of <"
- + managedLegacyPath + ">", testFile.startsWith( managedLegacyPath ) );
- assertFalse( "File < " + testFile + "> should not exist in managed legacy repository.", file.exists() );
- }
protected void assertNotExistsInManagedDefaultRepo( File file )
throws Exception
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
- saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED, false );
// Attempt the proxy fetch.
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
// TODO: How much information on each failure should we pass back to the user vs. logging in the proxy?
}
- @Test
- 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, false );
-
- File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
-
- assertNotDownloaded( downloadedFile );
- assertNotModified( expectedFile, expectedTimestamp );
- assertNoTempFiles( expectedFile );
- }
-
- @Test
- public void testGetFromLegacyProxyAlreadyPresentInManaged_OlderThanRemote()
- throws Exception
- {
- String legacyPath = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar";
- String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
- setupTestableManagedRepository( path );
-
- File expectedFile = new File( managedDefaultDir, path );
- File remoteFile = new File( REPOPATH_PROXIED_LEGACY, legacyPath );
-
- // Set the managed file to be older than remote.
- setManagedOlderThanRemote( expectedFile, remoteFile );
-
- ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
-
- assertTrue( expectedFile.exists() );
-
- // Configure Connector (usually done within archiva.xml configuration)
- saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED, false );
-
- File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
- File proxiedFile = new File( REPOPATH_PROXIED_LEGACY, legacyPath );
- assertFileEquals( expectedFile, downloadedFile, proxiedFile );
- assertNoTempFiles( expectedFile );
- }
-
- @Test
- public void testGetFromLegacyProxyNotPresentInManaged()
- throws Exception
- {
- 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 );
-
- assertNotExistsInManagedDefaultRepo( expectedFile );
-
- // Configure Connector (usually done within archiva.xml configuration)
- saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED, false );
-
- File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
-
- File proxiedFile = new File( REPOPATH_PROXIED_LEGACY, legacyPath );
- assertFileEquals( expectedFile, downloadedFile, proxiedFile );
- assertNoTempFiles( expectedFile );
- }
-
- @Test
- public void testGetFromLegacyProxyPluginNotPresentInManaged()
- throws Exception
- {
- String legacyPath = "org.apache.maven.test/maven-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 );
-
- assertNotExistsInManagedDefaultRepo( expectedFile );
-
- // Configure Connector (usually done within archiva.xml configuration)
- saveConnector( ID_DEFAULT_MANAGED, ID_LEGACY_PROXIED, false );
-
- File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
-
- File proxiedFile = new File( REPOPATH_PROXIED_LEGACY, legacyPath );
- assertFileEquals( expectedFile, downloadedFile, proxiedFile );
- assertNoTempFiles( expectedFile );
- }
}
+++ /dev/null
-package org.apache.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 org.apache.archiva.model.ArtifactReference;
-import org.apache.archiva.policies.CachedFailuresPolicy;
-import org.apache.archiva.policies.ChecksumPolicy;
-import org.apache.archiva.policies.ReleasesPolicy;
-import org.apache.archiva.policies.SnapshotsPolicy;
-import org.junit.Test;
-
-import java.io.File;
-
-import static org.junit.Assert.assertTrue;
-
-/**
- * ManagedLegacyTransferTest
- *
- *
- */
-public class ManagedLegacyTransferTest
- extends AbstractProxyTestCase
-{
- /**
- * 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.
- */
- @Test
- 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 );
-
- assertNotExistsInManagedLegacyRepo( expectedFile );
-
- // Configure Connector (usually done within archiva.xml configuration)
- saveConnector( ID_LEGACY_MANAGED, ID_PROXIED1, false );
-
- 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 );
- }
-
- /**
- * 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.
- */
- @Test
- 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 );
- File remoteFile = new File( REPOPATH_PROXIED1, remotePath );
-
- setManagedOlderThanRemote( expectedFile, remoteFile );
-
- ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path );
-
- // Configure Connector (usually done within archiva.xml configuration)
- saveConnector( ID_LEGACY_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
- SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
-
- File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
-
- assertFileEquals( expectedFile, downloadedFile, remoteFile );
- assertNoTempFiles( expectedFile );
- }
-
- /**
- * 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.
- */
- @Test
- public void testManagedLegacyNotPresentRemoteLegacyPresent()
- throws Exception
- {
- String path = "org.apache.maven.test/plugins/get-legacy-plugin-1.0.jar";
- File expectedFile = new File( managedLegacyDir, path );
- ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path );
-
- assertNotExistsInManagedLegacyRepo( expectedFile );
-
- // Configure Connector (usually done within archiva.xml configuration)
- saveConnector( ID_LEGACY_MANAGED, ID_LEGACY_PROXIED, false );
-
- File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
-
- File proxiedFile = new File( REPOPATH_PROXIED_LEGACY, path );
- assertFileEquals( expectedFile, downloadedFile, proxiedFile );
- assertNoTempFiles( expectedFile );
- }
-
- /**
- * 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.
- */
- @Test
- 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, false );
-
- 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.
- */
- @Test
- 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, false );
-
- File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
-
- assertNotDownloaded( downloadedFile );
- assertNoTempFiles( expectedFile );
- }
-
- /**
- * 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.
- */
- @Test
- public void testManagedLegacyPresentRemoteDefaultNotPresent()
- 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_PROXIED1, false );
-
- File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
-
- assertNotDownloaded( downloadedFile );
- assertNoTempFiles( expectedFile );
- }
-
- /**
- * Incoming request on a Managed Legacy repository, for content that does not exist in the
- * managed legacy repository, and does not exists on a remote legacy layout repository.
- */
- @Test
- public void testManagedLegacyNotPresentRemoteLegacyNotPresent()
- throws Exception
- {
- String path = "org.apache.archiva.test/jars/mystery-lib-1.0.jar";
- File expectedFile = new File( managedLegacyDir, path );
- ArtifactReference artifact = managedLegacyRepository.toArtifactReference( path );
-
- assertNotExistsInManagedLegacyRepo( expectedFile );
-
- // Configure Connector (usually done within archiva.xml configuration)
- saveConnector( ID_LEGACY_MANAGED, ID_LEGACY_PROXIED, false );
-
- File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
-
- assertNotDownloaded( downloadedFile );
- assertNoTempFiles( expectedFile );
- }
-
- /**
- * Incoming request on a Managed Legacy repository, for content that does not exist in the
- * managed legacy repository, and does not exists on a remote default layout repository.
- */
- @Test
- 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, false );
-
- File downloadedFile = proxyHandler.fetchFromProxies( managedLegacyRepository, artifact );
-
- assertNotDownloaded( downloadedFile );
- assertNoTempFiles( expectedFile );
- }
-}