]> source.dussan.org Git - archiva.git/commitdiff
[MRM-520] Proxy Connectors are not deleted with the deletion of a Repository.
authorJoakim Erdfelt <joakime@apache.org>
Fri, 19 Oct 2007 22:47:43 +0000 (22:47 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Fri, 19 Oct 2007 22:47:43 +0000 (22:47 +0000)
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

archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java
archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java
archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryAction.java
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryActionTest.java

index 17f707bf28c56e98288b398065cc994612e1f1d0..2ba2cb4aa82eac2259d8eb2511d372dea7ecdfbf 100644 (file)
@@ -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<ProxyConnectorConfiguration> getProxyConnectors()
+    {
+        return new ArrayList<ProxyConnectorConfiguration>( archivaConfiguration.getConfiguration().getProxyConnectors() );
+    }
 }
index ed8c14b462c32c714bdbd575d543c3932ea12307..c61eeb4ac98c65d0114b30964735c9c031d98975 100644 (file)
@@ -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<ProxyConnectorConfiguration> proxyConnectors = getProxyConnectors();
+        for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors )
+        {
+            if ( StringUtils.equals( proxyConnector.getSourceRepoId(), cleanupRepository.getId() ) )
+            {
+                archivaConfiguration.getConfiguration().removeProxyConnector( proxyConnector );
+            }
+        }
     }
 
     public ManagedRepositoryConfiguration getRepository()
index 0fdde15765972b9e136342900d93debe10d95688..c63996b5fc28340f16cd9884ee11b1b37059b80e 100644 (file)
@@ -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<ProxyConnectorConfiguration> proxyConnectors = getProxyConnectors();
+        for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors )
+        {
+            if ( StringUtils.equals( proxyConnector.getTargetRepoId(), existingRepository.getId() ) )
+            {
+                archivaConfiguration.getConfiguration().removeProxyConnector( proxyConnector );
+            }
+        }
     }
 
     public RemoteRepositoryConfiguration getRepository()
index 6f26257bed269a14f4627ff322e22326eef66a03..a9b2e44243b1157e4a7fb761be097677071fa1c9 100644 (file)
@@ -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()
index dd38b68e6fec9b8600a698521e436b952425ac1b..a6b5b7eaaee231a097ae52754c2a65ba4616c7e3 100644 (file)
@@ -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?
 }