]> source.dussan.org Git - archiva.git/commitdiff
ensure remote repository functions work without DMI
authorBrett Porter <brett@apache.org>
Sun, 2 Feb 2014 02:39:42 +0000 (02:39 +0000)
committerBrett Porter <brett@apache.org>
Sun, 2 Feb 2014 02:39:42 +0000 (02:39 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-1.3.x@1563554 13f79535-47bb-0310-9956-ffa450edef68

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/DeleteRemoteRepositoryAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/resources/struts.xml
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRemoteRepository.jsp
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editRemoteRepository.jsp

index bc2819f6b783a194cf547b07754d19ce34fc18dd..64c52e8f92fa8cabb6c49d7f24ff486dfb7e2de9 100644 (file)
@@ -22,7 +22,6 @@ package org.apache.archiva.web.test;
 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;
@@ -34,6 +33,9 @@ import java.io.IOException;
 public class RepositoryTest
        extends AbstractRepositoryTest
 {
+
+    public static final String DELETE_CONFIGURATION_AND_CONTENTS = "Delete Configuration and Contents";
+
     @BeforeTest
     public void setUp()
     {
@@ -44,10 +46,11 @@ public class RepositoryTest
     public void tearDown()
     {
         goToRepositoriesPage();
-        deleteManagedRepository( "managedrepo1", true, false );
-        deleteManagedRepository( "managedrepo2", true, false );
-        deleteManagedRepository( "managedrepoedit", true, false );
+        deleteManagedRepository( "managedrepo1", false, DELETE_CONFIGURATION_AND_CONTENTS );
+        deleteManagedRepository( "managedrepo2", false, DELETE_CONFIGURATION_AND_CONTENTS );
+        deleteManagedRepository( "managedrepoedit", false, DELETE_CONFIGURATION_AND_CONTENTS );
         deleteRemoteRepository( "remoterepo", false );
+        deleteRemoteRepository( "remoterepoedit", false );
     }
 
     public void testAddManagedRepoValidValues()
@@ -310,19 +313,43 @@ public class RepositoryTest
        public void testDeleteManagedRepo()
         throws IOException
     {
-        File dir = new File( getRepositoryDir() + "managedrepodelete/" );
+        File dir = new File( getRepositoryDir() + "managedrepodeleteconfig/" );
         if ( dir.exists() )
         {
             FileUtils.deleteDirectory( dir );
         }
-        addManagedRepository( "managedrepodelete", "Managed Repository for Deleting", dir.getAbsolutePath(), "",
+        addManagedRepository( "managedrepodeleteconfig", "Managed Repository for Deleting", dir.getAbsolutePath(), "",
                               "Maven 2.x Repository", "0 0 * * * ?", "", "" );
 
-        deleteManagedRepository( "managedrepodelete", false, true );
+        deleteManagedRepository( "managedrepodeleteconfig", true, "Delete Configuration Only" );
 
         // assert removed, but contents remain
         assertRepositoriesPage();
-        assertTextNotPresent( "managedrepodelete" );
+        assertTextNotPresent( "managedrepodeleteconfig" );
+
+        Assert.assertTrue( dir.exists() && dir.isDirectory() );
+    }
+
+       public void testDeleteManagedRepoCancel()
+        throws IOException
+    {
+        File dir = new File( getRepositoryDir() + "managedrepodeletecancel/" );
+
+        goToRepositoriesPage();
+        if ( !isTextPresent( "managedrepodeletecancel" ) )
+        {
+            if ( dir.exists() )
+            {
+                FileUtils.deleteDirectory( dir );
+            }
+
+            addManagedRepository( "managedrepodeletecancel", "Managed Repository for Deleting", dir.getAbsolutePath(),
+                                  "", "Maven 2.x Repository", "0 0 * * * ?", "", "" );
+        }
+        deleteManagedRepository( "managedrepodeletecancel", true, "Cancel" );
+
+        assertRepositoriesPage();
+        assertTextPresent( "managedrepodeletecancel" );
 
         Assert.assertTrue( dir.exists() && dir.isDirectory() );
     }
@@ -338,9 +365,8 @@ public class RepositoryTest
         addManagedRepository( "managedrepodeletecontents", "Managed Repository for Deleting", dir.getAbsolutePath(), "",
                               "Maven 2.x Repository", "0 0 * * * ?", "", "" );
 
-        deleteManagedRepository( "managedrepodeletecontents", true, true );
+        deleteManagedRepository( "managedrepodeletecontents", true, DELETE_CONFIGURATION_AND_CONTENTS );
 
-        // assert removed, but contents remain
         assertRepositoriesPage();
         assertTextNotPresent( "managedrepodeletecontents" );
 
@@ -357,7 +383,8 @@ public class RepositoryTest
 
        public void testAddRemoteRepositoryNullIdentifier()
        {
-               addRemoteRepository( "" , "Remote Repository Sample" , "http://repository.codehaus.org/org/codehaus/mojo/" , "" , "" , "" , "Maven 2.x Repository" );
+               addRemoteRepository( "", "Remote Repository Sample", "http://repository.codehaus.org/org/codehaus/mojo/", "",
+                             "", "", "Maven 2.x Repository" );
                assertTextPresent( "You must enter a repository identifier." );
        }
 
@@ -380,6 +407,46 @@ public class RepositoryTest
                assertTextPresent( "Remote Repository Sample" );
        }
 
+    public void testDeleteRemoteRepo()
+    {
+        addRemoteRepository( "remoterepodeleteconfirm", "Remote Repository for Deleting",
+                             "https://repository.apache.org/", "", "", "", "Maven 2.x Repository" );
+        assertTextPresent( "Remote Repository for Deleting" );
+
+        deleteRemoteRepository( "remoterepodeleteconfirm", true );
+        assertRepositoriesPage();
+        assertTextNotPresent( "remoterepodeleteconfirm" );
+    }
+
+    public void testDeleteRemoteRepoCancel()
+    {
+        goToRepositoriesPage();
+        if ( !isTextPresent( "remoterepodeletecancel" ) )
+        {
+            addRemoteRepository( "remoterepodeletecancel", "Remote Repository for Deleting",
+                                 "https://repository.apache.org/", "", "", "", "Maven 2.x Repository" );
+            assertTextPresent( "Remote Repository for Deleting" );
+        }
+
+        deleteRemoteRepository( "remoterepodeletecancel", true, "Cancel" );
+        assertRepositoriesPage();
+        assertTextPresent( "remoterepodeletecancel" );
+    }
+
+    public void testEditRemoteRepo()
+    {
+        goToRepositoriesPage();
+        addRemoteRepository( "remoterepoedit", "Remote Repository for Editing",
+                             "https://archiva-repository.apache.org/archiva/repository/all", "", "", "",
+                             "Maven 2.x Repository" );
+        assertTextPresent( "Remote Repository for Editing" );
+
+        editRemoteRepository( "repository.name" , "New Remote Repo Name" );
+        assertRepositoriesPage();
+        assertTextNotPresent( "Remote Repository for Editing" );
+        assertTextPresent( "New Remote Repo Name" );
+    }
+
     // *** BUNDLED REPOSITORY TEST ***
 
     @Test ( dependsOnMethods = { "testWithCorrectUsernamePassword" }, alwaysRun = true )
index 481ccbf324a7d000de062c112c0bb9c261f9fb9a..b6997e801b039b10e58d33c7abaee01ddea3ae32 100644 (file)
@@ -420,6 +420,11 @@ public abstract class AbstractRepositoryTest
        }
        
        public void deleteRemoteRepository( String id, boolean validate )
+    {
+        deleteRemoteRepository( id, validate, "Confirm" );
+    }
+
+       public void deleteRemoteRepository( String id, boolean validate, String option )
        {
                goToRepositoriesPage();
         String xpath = "//div[@id='contentArea']//a[contains(@href,'confirmDeleteRemoteRepository.action?repoid=" + id + "')]";
@@ -427,14 +432,14 @@ public abstract class AbstractRepositoryTest
         {
             clickLinkWithXPath( xpath );
                assertDeleteRemoteRepositoryPage();
-               clickButtonWithValue( "Confirm" );
+               clickButtonWithValue( option );
         }
        }
        
        public void editRemoteRepository( String fieldName, String value)
        {
                goToRepositoriesPage();
-               clickLinkWithXPath( "//div[@id='contentArea']/div/div[8]/div[1]/a[1]" );
+        clickLinkWithXPath( getRepositoryXpath( "remoterepoedit" ) + "//a[contains(text(),'Edit')]" );
                setFieldValue( fieldName, value );
                clickButtonWithValue( "Update Repository" );
        }
@@ -468,21 +473,14 @@ public abstract class AbstractRepositoryTest
                 clickButtonWithValue( "Update Repository" );
         }
        
-       public void deleteManagedRepository( String id, boolean deleteContents, boolean validate )
+       public void deleteManagedRepository( String id, boolean validate, String option )
        {
         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" );
-            if ( deleteContents )
-            {
-                clickButtonWithValue( "Delete Configuration and Contents" );
-            }
-            else
-            {
-                clickButtonWithValue( "Delete Configuration Only" );
-            }
+            clickButtonWithValue( option );
         }
     }
        
index 9d9fef04be346957e317ea3ed960187048575530..ff6128e7e73557d5fca0cebe04c4b193d800adff 100644 (file)
@@ -44,6 +44,8 @@ public class DeleteRemoteRepositoryAction
 
     private String repoid;
 
+    private boolean cancel;
+
     public void prepare()
     {
         if ( StringUtils.isNotBlank( repoid ) )
@@ -65,7 +67,11 @@ public class DeleteRemoteRepositoryAction
 
     public String delete()
     {
-        String result = SUCCESS;
+        if ( cancel )
+        {
+            return SUCCESS;
+        }
+
         RemoteRepositoryConfiguration existingRepository = repository;
         if ( existingRepository == null )
         {
@@ -76,7 +82,7 @@ public class DeleteRemoteRepositoryAction
         Configuration configuration = archivaConfiguration.getConfiguration();
         removeRepository( repoid, configuration );
         triggerAuditEvent( repoid, null, AuditEvent.DELETE_REMOTE_REPO );
-        result = saveConfiguration( configuration );
+        String result = saveConfiguration( configuration );
         
         cleanupRepositoryData( existingRepository );
 
@@ -116,4 +122,9 @@ public class DeleteRemoteRepositoryAction
     {
         this.repoid = repoid;
     }
+
+    public void setCancel( String cancel )
+    {
+        this.cancel = StringUtils.isNotEmpty( cancel );
+    }
 }
index 26c2595df4c9ddb51c64be11c9c0b4dd2e1d08d4..da717c1714b2a055a707d3ad49a9f0d4d10860f7 100644 (file)
     </action>
 
     <action name="editRemoteRepository" class="editRemoteRepositoryAction" method="input">
+      <result name="input">/WEB-INF/jsp/admin/editRemoteRepository.jsp</result>
+      <result name="error">/WEB-INF/jsp/admin/editRemoteRepository.jsp</result>
+      <interceptor-ref name="configuredPrepareParamsStack"/>
+    </action>
+
+    <action name="editRemoteRepository_commit" class="editRemoteRepositoryAction" method="commit">
       <result name="input">/WEB-INF/jsp/admin/editRemoteRepository.jsp</result>
       <result name="error">/WEB-INF/jsp/admin/editRemoteRepository.jsp</result>
       <result name="success" type="redirectAction">repositories</result>
index 9d77aa5d72e2b6eb7763e38ba98be53798baf082..26c3d2c0954e0f6420a5624fd9d8baa4f8aa9378 100644 (file)
@@ -64,8 +64,8 @@
   <s:form method="post" action="deleteRemoteRepository" namespace="/admin" validate="true" theme="simple">
     <s:hidden name="repoid"/>
     <div class="buttons">
-      <s:submit value="Confirm" method="delete"/>
-      <s:submit value="Cancel" method="execute"/>
+      <s:submit value="Confirm" />
+      <s:submit value="Cancel" name="cancel" />
     </div>
   </s:form>
 </div>
index e9acc94fd748d3c2cb35cb4740428b8b52b682a7..150af92e123ac9134055de6905a459f4edcfb1b4 100644 (file)
@@ -35,7 +35,7 @@
 <div id="contentArea">
 
   <s:actionmessage/>
-  <s:form method="post" action="editRemoteRepository!commit" namespace="/admin" validate="false">
+  <s:form method="post" action="editRemoteRepository_commit" namespace="/admin" validate="false">
     <s:hidden name="repository.id"/>
     <%@ include file="/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf" %>
     <s:submit value="Update Repository"/>