]> source.dussan.org Git - archiva.git/commitdiff
ensure repository deletion works without DMI
authorBrett Porter <brett@apache.org>
Sun, 2 Feb 2014 02:38:57 +0000 (02:38 +0000)
committerBrett Porter <brett@apache.org>
Sun, 2 Feb 2014 02:38:57 +0000 (02:38 +0000)
Also update and cleanup functional tests accordingly

git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-1.3.x@1563551 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/CSRFSecurityTest.java
archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/RepositoryTest.java
archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/parent/AbstractRepositoryTest.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRepository.jsp

index afa3130ed56fd12f1ac6549ff409dbbcdc602f40..0c2b51100d9cfd494f0ec80cb4e984fa921f657b 100644 (file)
@@ -36,12 +36,10 @@ public class CSRFSecurityTest
         loginAsAdmin();
     }
 
-    // TODO: TEMPORARILY DISABLED TO ADDRESS METHOD PARAMETER
-    @Test(enabled = false)
     public void testCSRFDeleteRepository()
     {
         getSelenium().open( baseUrl );
-        getSelenium().open( baseUrl + "/admin/deleteRepository.action?repoid=test&method%3AdeleteContents=Delete+Configuration+and+Contents" );
+        getSelenium().open( baseUrl + "/admin/deleteRepository.action?repoid=test&deleteContents=Delete+Configuration+and+Contents" );
         assertTextPresent( "Security Alert - Invalid Token Found" );
         assertTextPresent( "Possible CSRF attack detected! Invalid token found in the request." );
     }
index 08d7c9c63e592822288a596c8da159eb7e8fe4ee..a7842c73f9dd024c8f44055493b4b84e9a66f810 100644 (file)
@@ -19,11 +19,17 @@ package org.apache.archiva.web.test;
  * under the License.
  */
 
+import junit.framework.Assert;
 import org.apache.archiva.web.test.parent.AbstractRepositoryTest;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
 import org.testng.annotations.AfterSuite;
 import org.testng.annotations.BeforeTest;
 import org.testng.annotations.Test;
 
+import java.io.File;
+import java.io.IOException;
+
 @Test( groups = { "repository" }, sequential = true )
 public class RepositoryTest
        extends AbstractRepositoryTest
@@ -38,22 +44,29 @@ public class RepositoryTest
     public void tearDown()
     {
         goToRepositoriesPage();
-        deleteManagedRepository( "managedrepo1", false );
-        deleteManagedRepository( "managedrepo", false );
+        deleteManagedRepository( "managedrepo1", true, false );
+        deleteManagedRepository( "managedrepoedit", true, false );
         deleteRemoteRepository( "remoterepo", false );
     }
 
     public void testAddManagedRepoValidValues()
-       {
+        throws IOException
+    {
                goToRepositoriesPage();
                getSelenium().open( "/archiva/admin/addRepository.action" );
-               addManagedRepository( "managedrepo1", "Managed Repository Sample 1" , getRepositoryDir() + "repository/" , "", "Maven 2.x Repository", "0 0 * * * ?", "", "" );
-               clickButtonWithValue( "Save" );
-               assertTextPresent( "Managed Repository Sample 1" );
+        File dir = new File( getRepositoryDir() + "repository/" );
+        if ( dir.exists() )
+        {
+            FileUtils.deleteDirectory( dir );
+        }
+        addManagedRepository( "managedrepo1", "Managed Repository Sample 1", dir.getAbsolutePath(), "",
+                              "Maven 2.x Repository", "0 0 * * * ?", "", "" );
+        assertTextPresent( "Managed Repository Sample 1" );
                assertRepositoriesPage();
-       }
 
-        @Test(dependsOnMethods = { "testAddManagedRepoValidValues" } )
+        Assert.assertTrue( dir.exists() && dir.isDirectory() );
+    }
+
         public void testAddManagedRepoInvalidValues()
         {
                 goToRepositoriesPage();
@@ -68,49 +81,42 @@ public class RepositoryTest
                assertTextPresent( "Invalid cron expression." );
         }
 
-        @Test(dependsOnMethods = { "testAddManagedRepoInvalidValues" } )
        public void testAddManagedRepoInvalidIdentifier()
        {
                addManagedRepository( "<> \\/~+[ ]'\"", "name" , "/home" , "/.index", "Maven 2.x Repository", "0 0 * * * ?", "1", "1" );
                assertTextPresent( "Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)." );
        }
 
-       @Test(dependsOnMethods = { "testAddManagedRepoInvalidIdentifier" } )
        public void testAddManagedRepoInvalidRepoName()
        {
                addManagedRepository( "identifier", "<>\\~+[]'\"" , "/home" , "/.index", "Maven 2.x Repository", "0 0 * * * ?", "1", "1" );
                assertTextPresent( "Repository Name must only contain alphanumeric characters, white-spaces(' '), forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-)." );
        }
 
-       @Test(dependsOnMethods = { "testAddManagedRepoInvalidRepoName" } )
        public void testAddManagedRepoInvalidDirectory()
        {
                addManagedRepository( "identifier", "name" , "<> ~+[ ]'\"" , "/.index", "Maven 2.x Repository", "0 0 * * * ?", "1", "1" );
                assertTextPresent( "Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
        }
 
-       @Test(dependsOnMethods = { "testAddManagedRepoInvalidDirectory" } )
        public void testAddManagedRepoInvalidIndexDir()
        {
                addManagedRepository( "identifier", "name" , "/home" , "<> ~+[ ]'\"", "Maven 2.x Repository", "0 0 * * * ?", "1", "1" );
                assertTextPresent( "Index directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
        }
 
-        @Test(dependsOnMethods = { "testAddManagedRepoInvalidIndexDir" } )
        public void testAddManagedRepoInvalidRetentionCount()
        {
                addManagedRepository( "identifier", "name" , "/home" , "/.index", "Maven 2.x Repository", "0 0 * * * ?", "1", "101" );
                assertTextPresent( "Repository Purge By Retention Count needs to be between 1 and 100." );
        }
 
-        @Test(dependsOnMethods = { "testAddManagedRepoInvalidRetentionCount" } )
        public void testAddManagedRepoInvalidDaysOlder()
        {
                addManagedRepository( "identifier", "name" , "/home" , "/.index", "Maven 2.x Repository", "0 0 * * * ?", "-1", "1" );
                assertTextPresent( "Repository Purge By Days Older Than needs to be larger than 0." );
        }
 
-       @Test(dependsOnMethods = { "testAddManagedRepoInvalidDaysOlder" } )
        public void testAddManagedRepoBlankValues()
        {
                goToRepositoriesPage();
@@ -122,46 +128,50 @@ public class RepositoryTest
                assertTextPresent( "Invalid cron expression." );
        }
 
-       @Test(dependsOnMethods = { "testAddManagedRepoBlankValues" } )
        public void testAddManagedRepoNoIdentifier()
        {
-               addManagedRepository( "", "name" , "/home" , "/.index", "Maven 2.x Repository", "0 0 * * * ?", "", "" );
+               addManagedRepository( "", "name", "/home", "/.index", "Maven 2.x Repository", "0 0 * * * ?", "", "" );
                assertTextPresent( "You must enter a repository identifier." );
        }
 
-       @Test(dependsOnMethods = { "testAddManagedRepoNoIdentifier" } )
        public void testAddManagedRepoNoRepoName()
        {
                addManagedRepository( "identifier", "" , "/home" , "/.index", "Maven 2.x Repository", "0 0 * * * ?", "", "" );
                assertTextPresent( "You must enter a repository name." );
        }
 
-       @Test(dependsOnMethods = { "testAddManagedRepoNoRepoName" } )
        public void testAddManagedRepoNoDirectory()
        {
                addManagedRepository( "identifier", "name" , "" , "/.index", "Maven 2.x Repository", "0 0 * * * ?", "", "" );
                assertTextPresent( "You must enter a directory." );
        }
 
-       @Test(dependsOnMethods = { "testAddManagedRepoNoDirectory" } )
        public void testAddManagedRepoNoCron()
        {
                addManagedRepository( "identifier", "name" , "/home" , "/.index", "Maven 2.x Repository", "", "", "" );
                assertTextPresent( "Invalid cron expression." );
        }
 
-       @Test(dependsOnMethods = { "testAddManagedRepoNoCron" } )
-       public void testAddManagedRepoForEdit()
-       {
-               goToRepositoriesPage();
-               clickLinkWithText( "Add" );
-               addManagedRepository( "managedrepo", "Managed Repository Sample" , getRepositoryDir() + "local-repo/", "", "Maven 2.x Repository", "0 0 * * * ?", "", "" );
-               clickButtonWithValue( "Save" );
-               assertTextPresent( "Managed Repository Sample" );
-       }
+    public void testEditManagedRepo()
+        throws IOException
+    {
+        goToRepositoriesPage();
+        clickLinkWithText( "Add" );
+        String directory = getRepositoryDir() + "local-repo/";
+        File dir = new File( directory );
+        if ( dir.exists() )
+        {
+            FileUtils.deleteDirectory( dir );
+        }
+        addManagedRepository( "managedrepoedit", "Managed Repository for Editing", directory, "",
+                              "Maven 2.x Repository", "0 0 * * * ?", "", "" );
 
-        @Test(dependsOnMethods = { "testAddManagedRepoForEdit" } )
-        public void testEditManagedRepoInvalidValues()
+        editManagedRepository( "repository.name" , "New Managed Repo Name" );
+        assertTextNotPresent( "Managed Repository for Editing" );
+        assertTextPresent( "New Managed Repo Name" );
+    }
+
+    public void testEditManagedRepoInvalidValues()
        {
                editManagedRepository("<>\\~+[]'\"" , "<> ~+[ ]'\"" , "<> ~+[ ]'\"", "Maven 2.x Repository", "", "-1", "101");
                 assertTextPresent( "Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
@@ -172,95 +182,112 @@ public class RepositoryTest
                assertTextPresent( "Invalid cron expression." );
        }
 
-        @Test(dependsOnMethods = { "testEditManagedRepoInvalidValues" } )
         public void testEditManagedRepoInvalidRepoName()
        {
                 editManagedRepository("<>\\~+[]'\"" , "/home" , "/.index", "Maven 2.x Repository", "0 0 * * * ?", "1", "1");
                 assertTextPresent( "Repository Name must only contain alphanumeric characters, white-spaces(' '), forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-)." );
        }
 
-        @Test(dependsOnMethods = { "testEditManagedRepoInvalidRepoName" } )
         public void testEditManagedRepoInvalidDirectory()
        {
                 editManagedRepository("name" , "<> ~+[ ]'\"" , "/.index", "Maven 2.x Repository", "0 0 * * * ?", "1", "1");
                 assertTextPresent( "Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
        }
 
-        @Test(dependsOnMethods = { "testEditManagedRepoInvalidDirectory" } )
         public void testEditManagedRepoInvalidIndexDir()
        {
                 editManagedRepository("name" , "/home" , "<> ~+[ ]'\"", "Maven 2.x Repository", "0 0 * * * ?", "1", "1");
                 assertTextPresent( "Index directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
        }
 
-        @Test(dependsOnMethods = { "testEditManagedRepoInvalidIndexDir" } )
         public void testEditManagedRepoInvalidCron()
        {
                 editManagedRepository("name" , "/home" , "/.index", "Maven 2.x Repository", "", "1", "1");
                 assertTextPresent( "Invalid cron expression." );
        }
 
-        @Test(dependsOnMethods = { "testEditManagedRepoInvalidCron" } )
         public void testEditManagedRepoInvalidRetentionCount()
        {
                 editManagedRepository("name" , "/home" , "/.index", "Maven 2.x Repository", "0 0 * * * ?", "1", "101");
                 assertTextPresent( "Repository Purge By Retention Count needs to be between 1 and 100." );
        }
 
-        @Test(dependsOnMethods = { "testEditManagedRepoInvalidRetentionCount" } )
         public void testEditManagedRepoInvalidDaysOlder()
        {
                 editManagedRepository("name" , "/home" , "/.index", "Maven 2.x Repository", "0 0 * * * ?", "-1", "1");
                 assertTextPresent( "Repository Purge By Days Older Than needs to be larger than 0." );
        }
 
-       //TODO
-       @Test(dependsOnMethods = { "testEditManagedRepoInvalidDaysOlder" } )
-       public void testEditManagedRepo()
-       {
-               editManagedRepository( "repository.name" , "Managed Repo" );
-               assertTextPresent( "Managed Repository Sample" );
-       }
+       public void testDeleteManagedRepo()
+        throws IOException
+    {
+        goToRepositoriesPage();
+        clickLinkWithText( "Add" );
+        File dir = new File( getRepositoryDir() + "managedrepodelete/" );
+        if ( dir.exists() )
+        {
+            FileUtils.deleteDirectory( dir );
+        }
+        addManagedRepository( "managedrepodelete", "Managed Repository for Deleting", dir.getAbsolutePath(), "",
+                              "Maven 2.x Repository", "0 0 * * * ?", "", "" );
 
-       //TODO
-       @Test(dependsOnMethods = { "testEditManagedRepo" } )
-       public void testDeleteManageRepo()
-       {
-               deleteManagedRepository( "managedrepo", true );
-       }
+        deleteManagedRepository( "managedrepodelete", false, true );
+
+        // assert removed, but contents remain
+        assertRepositoriesPage();
+        assertTextNotPresent( "managedrepodelete" );
+
+        Assert.assertTrue( dir.exists() && dir.isDirectory() );
+    }
+
+       public void testDeleteManagedRepoWithContents()
+        throws IOException
+    {
+        goToRepositoriesPage();
+        clickLinkWithText( "Add" );
+        File dir = new File( getRepositoryDir() + "managedrepodeletecontents/" );
+        if ( dir.exists() )
+        {
+            FileUtils.deleteDirectory( dir );
+        }
+        addManagedRepository( "managedrepodeletecontents", "Managed Repository for Deleting", dir.getAbsolutePath(), "",
+                              "Maven 2.x Repository", "0 0 * * * ?", "", "" );
+
+        deleteManagedRepository( "managedrepodeletecontents", true, true );
+
+        // assert removed, but contents remain
+        assertRepositoriesPage();
+        assertTextNotPresent( "managedrepodeletecontents" );
+
+        Assert.assertFalse( dir.exists() );
+    }
 
-       @Test(dependsOnMethods = { "testAddRemoteRepoValidValues" } )
        public void testAddRemoteRepoNullValues()
        {
-           getSelenium().open( "/archiva/admin/addRemoteRepository.action" );
                addRemoteRepository( "" , "" , "" , "" , "" , "" , "Maven 2.x Repository" );
                assertTextPresent( "You must enter a repository identifier." );
                assertTextPresent( "You must enter a repository name." );
                assertTextPresent( "You must enter a url." );
        }
 
-       @Test(dependsOnMethods = { "testAddRemoteRepoNullValues" } )
        public void testAddRemoteRepositoryNullIdentifier()
        {
                addRemoteRepository( "" , "Remote Repository Sample" , "http://repository.codehaus.org/org/codehaus/mojo/" , "" , "" , "" , "Maven 2.x Repository" );
                assertTextPresent( "You must enter a repository identifier." );
        }
 
-       @Test(dependsOnMethods = { "testAddRemoteRepositoryNullIdentifier" } )
        public void testAddRemoteRepoNullName()
        {
-               addRemoteRepository( "remoterepo" , "" , "http://repository.codehaus.org/org/codehaus/mojo/" , "" , "" , "" , "Maven 2.x Repository" );
+               addRemoteRepository( "remotenullrepo" , "" , "http://repository.codehaus.org/org/codehaus/mojo/" , "" , "" , "" , "Maven 2.x Repository" );
                assertTextPresent( "You must enter a repository name." );
        }
 
-       @Test(dependsOnMethods = { "testAddRemoteRepoNullName" } )
        public void testAddRemoteRepoNullURL()
        {
-               addRemoteRepository( "remoterepo" , "Remote Repository Sample" , "" , "" , "" , "" , "Maven 2.x Repository" );
+               addRemoteRepository( "remotenullrepo" , "Remote Repository Sample" , "" , "" , "" , "" , "Maven 2.x Repository" );
                assertTextPresent( "You must enter a url." );
        }
 
-       @Test(dependsOnMethods = { "testDeleteManageRepo" } )
        public void testAddRemoteRepoValidValues()
        {
                getSelenium().open( "/archiva/admin/addRemoteRepository.action" );
index c155c03088264ab161acbe4f14a87efe7463a304..481ccbf324a7d000de062c112c0bb9c261f9fb9a 100644 (file)
@@ -405,7 +405,9 @@ public abstract class AbstractRepositoryTest
        
        public void addRemoteRepository( String identifier, String name, String url, String username, String password, String timeout, String type )
        {
-                       //goToRepositoriesPage();
+                       if (!getSelenium().getLocation().contains( "/archiva/admin/addRemoteRepository.action" )) {
+                getSelenium().open( "/archiva/admin/addRemoteRepository.action" );
+            }
                        assertAddRemoteRepository();
                        setFieldValue( "addRemoteRepository_commit_repository_id" ,  identifier );
                        setFieldValue( "addRemoteRepository_commit_repository_name" , name );
@@ -440,17 +442,21 @@ public abstract class AbstractRepositoryTest
        public void editManagedRepository( String fieldName, String value )
        {           
                goToRepositoriesPage();
-               clickLinkWithXPath( "//div[@id='contentArea']/div/div[5]/div[1]/a[1]/img" );
-               assertPage( "Apache Archiva \\ Admin: Edit Managed Repository" );
+        clickLinkWithXPath( getRepositoryXpath( "managedrepoedit" ) + "//a[contains(text(),'Edit')]" );
+        assertPage( "Apache Archiva \\ Admin: Edit Managed Repository" );
                setFieldValue(fieldName, value);
-               //TODO
                clickButtonWithValue( "Update Repository" );
        }
 
-        public void editManagedRepository(String name, String directory, String indexDirectory, String type, String cron, String daysOlder, String retentionCount)
+    private String getRepositoryXpath( String repositoryId )
+    {
+        return "//code[text()='" + repositoryId + "']/ancestor::div[contains(@class,'repository')]";
+    }
+
+    public void editManagedRepository(String name, String directory, String indexDirectory, String type, String cron, String daysOlder, String retentionCount)
         {
                 goToRepositoriesPage();
-               clickLinkWithXPath( "//div[@id='contentArea']/div/div[5]/div[1]/a[1]/img" );
+               clickLinkWithXPath( getRepositoryXpath( "managedrepoedit" ) + "//a[contains(text(),'Edit')]");
                assertPage( "Apache Archiva \\ Admin: Edit Managed Repository" );
                 setFieldValue( "repository.name" , name );
                 setFieldValue( "repository.location" , directory );
@@ -462,14 +468,21 @@ public abstract class AbstractRepositoryTest
                 clickButtonWithValue( "Update Repository" );
         }
        
-       public void deleteManagedRepository( String id, boolean validate )
+       public void deleteManagedRepository( String id, boolean deleteContents, boolean validate )
        {
         String xpath = "//div[@id='contentArea']//a[contains(@href,'confirmDeleteRepository.action?repoid=" + id + "')]";
         if ( validate || isElementPresent( "xpath=" + xpath ) )
         {
             clickLinkWithXPath( xpath );
             assertPage( "Apache Archiva \\ Admin: Delete Managed Repository" );
-            clickButtonWithValue( "Delete Configuration Only" );
+            if ( deleteContents )
+            {
+                clickButtonWithValue( "Delete Configuration and Contents" );
+            }
+            else
+            {
+                clickButtonWithValue( "Delete Configuration Only" );
+            }
         }
     }
        
index a2793ce0964b267df9c2ca651847562a154446a1..0f65e6b1e724555f53c7b8fdd700b33038eb3298 100644 (file)
@@ -58,6 +58,10 @@ public class DeleteManagedRepositoryAction
 
     private String repoid;
 
+    private boolean deleteContents;
+
+    private boolean cancel;
+
     /**
      * @plexus.requirement role-hint="jdo"
      */
@@ -82,18 +86,13 @@ public class DeleteManagedRepositoryAction
         return INPUT;
     }
 
-    public String deleteEntry()
+    public String delete()
     {
-        return deleteRepository( false );
-    }
-
-    public String deleteContents()
-    {
-        return deleteRepository( true );
-    }
+        if ( cancel )
+        {
+            return SUCCESS;
+        }
 
-    private String deleteRepository( boolean deleteContents )
-    {   
         ManagedRepositoryConfiguration existingRepository = repository;
         if ( existingRepository == null )
         {
@@ -101,7 +100,7 @@ public class DeleteManagedRepositoryAction
             return ERROR;
         }
 
-        String result = SUCCESS;
+        String result;
 
         try
         {
@@ -243,4 +242,14 @@ public class DeleteManagedRepositoryAction
     {
         return archivaDAO;
     }
+
+    public void setDeleteContents( String deleteContents )
+    {
+        this.deleteContents = StringUtils.isNotBlank( deleteContents );
+    }
+
+    public void setCancel( String cancel )
+    {
+        this.cancel = StringUtils.isNotBlank( cancel );
+    }
 }
index def8b68f69eb9a531f2f5a79fd5d8526afd0c214..863b3ed8feb2647828f88a010cfe86381351b7d2 100644 (file)
@@ -74,9 +74,9 @@
     <s:hidden name="repoid"/>
     <s:token/>
     <div class="buttons">
-      <s:submit value="Delete Configuration Only" method="deleteEntry" />
-      <s:submit value="Delete Configuration and Contents" method="deleteContents" />
-      <s:submit value="Cancel" method="execute"/>
+      <s:submit value="Delete Configuration Only" />
+      <s:submit value="Delete Configuration and Contents" name="deleteContents" />
+      <s:submit value="Cancel" name="cancel"/>
     </div>
   </s:form>
 </div>