From: Joakim Erdfelt Date: Fri, 19 Oct 2007 22:47:43 +0000 (+0000) Subject: [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository. X-Git-Tag: archiva-1.0-beta-3~52 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8042e19982a736e90f81689182ec209b48d90c86;p=archiva.git [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository. Added ability of delete (managed|remote) repository action to clear out the associated proxy connector. Added tests. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@586635 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java index 17f707bf2..2ba2cb4aa 100644 --- a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java @@ -23,6 +23,7 @@ import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; import org.apache.maven.archiva.configuration.InvalidConfigurationException; +import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; import org.apache.maven.archiva.security.ArchivaRoleConstants; import org.codehaus.plexus.redback.rbac.Resource; import org.codehaus.plexus.redback.xwork.interceptor.SecureAction; @@ -32,6 +33,8 @@ import org.codehaus.plexus.registry.RegistryException; import org.codehaus.plexus.xwork.action.PlexusActionSupport; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; /** * Abstract AdminRepositories Action base. @@ -101,4 +104,14 @@ public abstract class AbstractRepositoriesAdminAction return SUCCESS; } + + /** + * Get the list of ProxyConnectors that are present in the configuration. + * + * @return a new list of ProxyConnectors present in the configuration. + */ + protected List getProxyConnectors() + { + return new ArrayList( archivaConfiguration.getConfiguration().getProxyConnectors() ); + } } diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java index ed8c14b46..c61eeb4ac 100644 --- a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java @@ -24,9 +24,11 @@ import com.opensymphony.xwork.Preparable; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; +import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; import org.codehaus.plexus.redback.role.RoleManagerException; import java.io.IOException; +import java.util.List; /** * DeleteManagedRepositoryAction @@ -123,7 +125,15 @@ public class DeleteManagedRepositoryAction // TODO: [MRM-265] After removing a managed repository - Browse/Search still see it - // TODO: [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository. + // [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository. + List proxyConnectors = getProxyConnectors(); + for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors ) + { + if ( StringUtils.equals( proxyConnector.getSourceRepoId(), cleanupRepository.getId() ) ) + { + archivaConfiguration.getConfiguration().removeProxyConnector( proxyConnector ); + } + } } public ManagedRepositoryConfiguration getRepository() diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryAction.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryAction.java index 0fdde1576..c63996b5f 100644 --- a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryAction.java +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryAction.java @@ -23,8 +23,11 @@ import com.opensymphony.xwork.Preparable; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.Configuration; +import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; +import java.util.List; + /** * DeleteRemoteRepositoryAction * @@ -81,7 +84,16 @@ public class DeleteRemoteRepositoryAction private void cleanupRepositoryData( RemoteRepositoryConfiguration existingRepository ) { - // TODO: [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository. + // [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository. + + List proxyConnectors = getProxyConnectors(); + for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors ) + { + if ( StringUtils.equals( proxyConnector.getTargetRepoId(), existingRepository.getId() ) ) + { + archivaConfiguration.getConfiguration().removeProxyConnector( proxyConnector ); + } + } } public RemoteRepositoryConfiguration getRepository() diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java index 6f26257be..a9b2e4424 100644 --- a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java +++ b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java @@ -25,6 +25,8 @@ import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; +import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; +import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; import org.apache.maven.archiva.security.ArchivaRoleConstants; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.redback.role.RoleManager; @@ -120,7 +122,7 @@ public class DeleteManagedRepositoryActionTest { prepareRoleManagerMock(); - Configuration configuration = prepDeletionTest( createRepository(), "delete-entry" ); + Configuration configuration = prepDeletionTest( createRepository(), 3 ); String status = action.deleteEntry(); assertEquals( Action.SUCCESS, status ); @@ -134,7 +136,7 @@ public class DeleteManagedRepositoryActionTest { prepareRoleManagerMock(); - Configuration configuration = prepDeletionTest( createRepository(), "delete-contents" ); + Configuration configuration = prepDeletionTest( createRepository(), 3 ); String status = action.deleteContents(); assertEquals( Action.SUCCESS, status ); @@ -142,12 +144,33 @@ public class DeleteManagedRepositoryActionTest assertFalse( location.exists() ); } + + public void testDeleteRepositoryAndAssociatedProxyConnectors() + throws Exception + { + Configuration configuration = prepDeletionTest( createRepository(), 4 ); + configuration.addRemoteRepository( createRemoteRepository( "codehaus", "http://repository.codehaus.org" ) ); + configuration.addRemoteRepository( createRemoteRepository( "java.net", "http://dev.java.net/maven2" ) ); + configuration.addProxyConnector( createProxyConnector( REPO_ID, "codehaus" ) ); + + prepareRoleManagerMock(); + + assertEquals( 1, configuration.getProxyConnectors().size() ); + + String status = action.deleteContents(); + assertEquals( Action.SUCCESS, status ); + + assertTrue( configuration.getManagedRepositories().isEmpty() ); + assertEquals( 0, configuration.getProxyConnectors().size() ); + assertFalse( location.exists() ); + } + public void testDeleteRepositoryCancelled() throws Exception { ManagedRepositoryConfiguration originalRepository = createRepository(); - Configuration configuration = prepDeletionTest( originalRepository, null ); + Configuration configuration = prepDeletionTest( originalRepository, 3 ); String status = action.execute(); assertEquals( Action.SUCCESS, status ); @@ -158,7 +181,7 @@ public class DeleteManagedRepositoryActionTest assertTrue( location.exists() ); } - private Configuration prepDeletionTest( ManagedRepositoryConfiguration originalRepository, String mode ) + private Configuration prepDeletionTest( ManagedRepositoryConfiguration originalRepository, int expectCountGetConfig ) throws RegistryException, IndeterminateConfigurationException { location.mkdirs(); @@ -166,9 +189,7 @@ public class DeleteManagedRepositoryActionTest Configuration configuration = createConfigurationForEditing( originalRepository ); archivaConfiguration.getConfiguration(); - archivaConfigurationControl.setReturnValue( configuration ); - archivaConfiguration.getConfiguration(); - archivaConfigurationControl.setReturnValue( configuration ); + archivaConfigurationControl.setReturnValue( configuration, expectCountGetConfig ); archivaConfiguration.save( configuration ); archivaConfigurationControl.replay(); @@ -213,23 +234,36 @@ public class DeleteManagedRepositoryActionTest { ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration(); r.setId( REPO_ID ); - populateRepository( r ); + r.setName( "repo name" ); + r.setLocation( location.getAbsolutePath() ); + r.setLayout( "default" ); + r.setRefreshCronExpression( "* 0/5 * * * ?" ); + r.setDaysOlder( 0 ); + r.setRetentionCount( 0 ); + r.setReleases( true ); + r.setSnapshots( true ); + r.setScanned( false ); + r.setDeleteReleasedSnapshots( false ); return r; } - private void populateRepository( ManagedRepositoryConfiguration repository ) + private RemoteRepositoryConfiguration createRemoteRepository(String id, String url) { - repository.setId( REPO_ID ); - repository.setName( "repo name" ); - repository.setLocation( location.getAbsolutePath() ); - repository.setLayout( "default" ); - repository.setRefreshCronExpression( "* 0/5 * * * ?" ); - repository.setDaysOlder( 31 ); - repository.setRetentionCount( 20 ); - repository.setReleases( true ); - repository.setSnapshots( true ); - repository.setScanned( false ); - repository.setDeleteReleasedSnapshots( true ); + RemoteRepositoryConfiguration r = new RemoteRepositoryConfiguration(); + r.setId( id ); + r.setUrl( url ); + r.setLayout( "default" ); + + return r; + } + + private ProxyConnectorConfiguration createProxyConnector( String managedRepoId, String remoteRepoId ) + { + ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration(); + connector.setSourceRepoId( managedRepoId ); + connector.setTargetRepoId( remoteRepoId ); + + return connector; } private void prepareRoleManagerMock() diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryActionTest.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryActionTest.java index dd38b68e6..a6b5b7eaa 100644 --- a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryActionTest.java +++ b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryActionTest.java @@ -24,6 +24,8 @@ import com.opensymphony.xwork.Action; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; +import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.registry.RegistryException; @@ -89,11 +91,12 @@ public class DeleteRemoteRepositoryActionTest throws RegistryException, IndeterminateConfigurationException { Configuration configuration = createConfigurationForEditing( createRepository() ); + configuration.addManagedRepository( createManagedRepository( "internal", getTestPath( "target/repo/internal" ) ) ); + configuration.addManagedRepository( createManagedRepository( "snapshots", getTestPath( "target/repo/snapshots" ) ) ); + configuration.addProxyConnector( createProxyConnector( "internal", REPO_ID) ); archivaConfiguration.getConfiguration(); - archivaConfigurationControl.setReturnValue( configuration ); - archivaConfiguration.getConfiguration(); - archivaConfigurationControl.setReturnValue( configuration ); + archivaConfigurationControl.setReturnValue( configuration, 4 ); archivaConfiguration.save( configuration ); archivaConfigurationControl.replay(); @@ -106,10 +109,13 @@ public class DeleteRemoteRepositoryActionTest assertNotNull( repository ); assertRepositoryEquals( repository, createRepository() ); + assertEquals( 1, configuration.getProxyConnectors().size() ); + String status = action.delete(); assertEquals( Action.SUCCESS, status ); assertTrue( configuration.getRemoteRepositories().isEmpty() ); + assertEquals( 0, configuration.getProxyConnectors().size() ); } public void testDeleteRemoteRepositoryCancelled() @@ -119,9 +125,7 @@ public class DeleteRemoteRepositoryActionTest Configuration configuration = createConfigurationForEditing( originalRepository ); archivaConfiguration.getConfiguration(); - archivaConfigurationControl.setReturnValue( configuration ); - archivaConfiguration.getConfiguration(); - archivaConfigurationControl.setReturnValue( configuration ); + archivaConfigurationControl.setReturnValue( configuration, 2 ); archivaConfiguration.save( configuration ); archivaConfigurationControl.replay(); @@ -165,6 +169,32 @@ public class DeleteRemoteRepositoryActionTest assertEquals( expectedRepository.getUrl(), actualRepository.getUrl() ); assertEquals( expectedRepository.getName(), actualRepository.getName() ); } + + private ManagedRepositoryConfiguration createManagedRepository( String string, String testPath ) + { + ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration(); + r.setId( REPO_ID ); + r.setName( "repo name" ); + r.setLocation( testPath ); + r.setLayout( "default" ); + r.setRefreshCronExpression( "* 0/5 * * * ?" ); + r.setDaysOlder( 0 ); + r.setRetentionCount( 0 ); + r.setReleases( true ); + r.setSnapshots( true ); + r.setScanned( false ); + r.setDeleteReleasedSnapshots( false ); + return r; + } + + private ProxyConnectorConfiguration createProxyConnector( String managedRepoId, String remoteRepoId ) + { + ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration(); + connector.setSourceRepoId( managedRepoId ); + connector.setTargetRepoId( remoteRepoId ); + + return connector; + } private void populateRepository( RemoteRepositoryConfiguration repository ) { @@ -174,6 +204,5 @@ public class DeleteRemoteRepositoryActionTest repository.setLayout( "default" ); } - // TODO: what if there are proxy connectors attached to a deleted repository? // TODO: what about removing proxied content if a proxy is removed? }