]> source.dussan.org Git - archiva.git/commitdiff
[MRM-462] test deletion
authorBrett Porter <brett@apache.org>
Wed, 12 Sep 2007 02:58:42 +0000 (02:58 +0000)
committerBrett Porter <brett@apache.org>
Wed, 12 Sep 2007 02:58:42 +0000 (02:58 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@574771 13f79535-47bb-0310-9956-ffa450edef68

MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRepositoryAction.java
MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRepositoryActionTest.java

index 13f26b5d408a999af012151ec9c4e1736a9a8687..1a522b65e6b40108e68b0110a3573a948c776a1a 100644 (file)
@@ -80,6 +80,7 @@ public class ConfigureRepositoryAction
         return INPUT;
     }
 
+    // TODO: rename to confirmDelete
     public String confirm()
     {
         return INPUT;
@@ -101,8 +102,9 @@ public class ConfigureRepositoryAction
 
             try
             {
-                removeRepository( repoid, archivaConfiguration.getConfiguration() );
-                result = saveConfiguration( archivaConfiguration.getConfiguration() );
+                Configuration configuration = archivaConfiguration.getConfiguration();
+                removeRepository( repoid, configuration );
+                result = saveConfiguration( configuration );
 
                 if ( result.equals( SUCCESS ) )
                 {
index dbb0b4b13679dac4e61ad4a39121754dcfa30324..a525edb6204a157f7a6f317b0bb6f839cf744dbb 100644 (file)
@@ -23,11 +23,13 @@ import com.opensymphony.xwork.Action;
 import org.apache.commons.io.FileUtils;
 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.codehaus.plexus.PlexusTestCase;
 import org.codehaus.plexus.redback.role.RoleManager;
 import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle;
 import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException;
+import org.codehaus.plexus.registry.RegistryException;
 import org.easymock.MockControl;
 
 import java.io.File;
@@ -133,7 +135,7 @@ public class ConfigureRepositoryActionTest
         assertEquals( Action.SUCCESS, status );
         assertTrue( location.exists() );
 
-        assertEquals( configuration.getManagedRepositories(), Collections.singletonList( repository ) );
+        assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() );
 
         roleManagerControl.verify();
         archivaConfigurationControl.verify();
@@ -142,7 +144,7 @@ public class ConfigureRepositoryActionTest
     public void testEditRepositoryInitialPage()
         throws Exception
     {
-        Configuration configuration = createConfigurationForEditing();
+        Configuration configuration = createConfigurationForEditing( createRepository() );
 
         archivaConfiguration.getConfiguration();
         archivaConfigurationControl.setReturnValue( configuration );
@@ -180,11 +182,10 @@ public class ConfigureRepositoryActionTest
         assertEquals( expectedRepository.isSnapshots(), actualRepository.isSnapshots() );
     }
 
-    private Configuration createConfigurationForEditing()
+    private Configuration createConfigurationForEditing( ManagedRepositoryConfiguration repositoryConfiguration )
     {
         Configuration configuration = new Configuration();
-        ManagedRepositoryConfiguration r = createRepository();
-        configuration.addManagedRepository( r );
+        configuration.addManagedRepository( repositoryConfiguration );
         return configuration;
     }
 
@@ -205,7 +206,7 @@ public class ConfigureRepositoryActionTest
 
         roleManagerControl.replay();
 
-        Configuration configuration = createConfigurationForEditing();
+        Configuration configuration = createConfigurationForEditing( createRepository() );
         archivaConfiguration.getConfiguration();
         archivaConfigurationControl.setReturnValue( configuration );
         archivaConfiguration.getConfiguration();
@@ -227,12 +228,101 @@ public class ConfigureRepositoryActionTest
         ManagedRepositoryConfiguration newRepository = createRepository();
         newRepository.setName( "new repo name" );
         assertRepositoryEquals( repository, newRepository );
-        assertEquals( configuration.getManagedRepositories(), Collections.singletonList( repository ) );
+        assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() );
 
         roleManagerControl.verify();
         archivaConfigurationControl.verify();
     }
 
+    public void testDeleteRepositoryConfirmation()
+    {
+        ManagedRepositoryConfiguration originalRepository = createRepository();
+        Configuration configuration = createConfigurationForEditing( originalRepository );
+
+        archivaConfiguration.getConfiguration();
+        archivaConfigurationControl.setReturnValue( configuration );
+        archivaConfigurationControl.replay();
+
+        action.setRepoid( REPO_ID );
+
+        action.prepare();
+        assertEquals( REPO_ID, action.getRepoid() );
+        assertNull( action.getMode() );
+        AdminRepositoryConfiguration repository = action.getRepository();
+        assertNotNull( repository );
+        assertRepositoryEquals( repository, createRepository() );
+
+        String status = action.confirm();
+        assertEquals( Action.INPUT, status );
+        repository = action.getRepository();
+        assertRepositoryEquals( repository, createRepository() );
+        assertEquals( Collections.singletonList( originalRepository ), configuration.getManagedRepositories() );
+    }
+
+    public void testDeleteRepositoryKeepContent()
+        throws RegistryException, IndeterminateConfigurationException
+    {
+        Configuration configuration = executeDeletionTest( "delete-entry", createRepository() );
+
+        assertTrue( configuration.getManagedRepositories().isEmpty() );
+
+        assertTrue( location.exists() );
+    }
+
+    public void testDeleteRepositoryDeleteContent()
+        throws RegistryException, IndeterminateConfigurationException
+    {
+        Configuration configuration = executeDeletionTest( "delete-contents", createRepository() );
+
+        assertTrue( configuration.getManagedRepositories().isEmpty() );
+
+        assertFalse( location.exists() );
+    }
+
+    public void testDeleteRepositoryCancelled()
+        throws RegistryException, IndeterminateConfigurationException
+    {
+        ManagedRepositoryConfiguration originalRepository = createRepository();
+        Configuration configuration = executeDeletionTest( "unmodified", originalRepository );
+
+        AdminRepositoryConfiguration repository = action.getRepository();
+        assertRepositoryEquals( repository, createRepository() );
+        assertEquals( Collections.singletonList( originalRepository ), configuration.getManagedRepositories() );
+
+        assertTrue( location.exists() );
+    }
+
+    private Configuration executeDeletionTest( String mode, ManagedRepositoryConfiguration originalRepository )
+        throws RegistryException, IndeterminateConfigurationException
+    {
+        location.mkdirs();
+
+        Configuration configuration = createConfigurationForEditing( originalRepository );
+
+        archivaConfiguration.getConfiguration();
+        archivaConfigurationControl.setReturnValue( configuration );
+        archivaConfiguration.getConfiguration();
+        archivaConfigurationControl.setReturnValue( configuration );
+
+        archivaConfiguration.save( configuration );
+        archivaConfigurationControl.replay();
+
+        action.setRepoid( REPO_ID );
+        action.setMode( mode );
+
+        action.prepare();
+        assertEquals( REPO_ID, action.getRepoid() );
+        assertEquals( mode, action.getMode() );
+        AdminRepositoryConfiguration repository = action.getRepository();
+        assertNotNull( repository );
+        assertRepositoryEquals( repository, createRepository() );
+
+        assertTrue( location.exists() );
+        String status = action.delete();
+        assertEquals( Action.SUCCESS, status );
+        return configuration;
+    }
+
     private void populateRepository( ManagedRepositoryConfiguration repository )
     {
         repository.setId( REPO_ID );