archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1165335 - in /archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src: main/java/org/apache/maven/archiva/web/action/admin/repositories/ test/java/org/apache/maven/archiva/web/action/admin/repositories/
Date Mon, 05 Sep 2011 15:31:05 GMT
Author: olamy
Date: Mon Sep  5 15:31:04 2011
New Revision: 1165335

URL: http://svn.apache.org/viewvc?rev=1165335&view=rev
Log:
[MRM-1506] api to configure RemoteRepository : use it in the webapp instead of directly archiva-configuration

Modified:
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRemoteRepositoriesAction.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryAction.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryAction.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditRemoteRepositoryAction.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryActionTest.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryActionTest.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditRemoteRepositoryActionTest.java

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRemoteRepositoriesAction.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRemoteRepositoriesAction.java?rev=1165335&r1=1165334&r2=1165335&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRemoteRepositoriesAction.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRemoteRepositoriesAction.java
Mon Sep  5 15:31:04 2011
@@ -1,10 +1,8 @@
 package org.apache.maven.archiva.web.action.admin.repositories;
 
-import org.apache.maven.archiva.configuration.Configuration;
-import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
-import org.codehaus.plexus.redback.role.RoleManagerException;
+import org.apache.archiva.admin.repository.remote.RemoteRepositoryAdmin;
 
-import java.io.IOException;
+import javax.inject.Inject;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -26,25 +24,23 @@ import java.io.IOException;
  */
 
 /**
- * AbstractRemoteRepositoriesAction 
+ * AbstractRemoteRepositoriesAction
  *
  * @version $Id$
  */
 public class AbstractRemoteRepositoriesAction
     extends AbstractRepositoriesAdminAction
 {
-    protected void addRepository( RemoteRepositoryConfiguration repository, Configuration
configuration )
-        throws IOException, RoleManagerException
+    @Inject
+    private RemoteRepositoryAdmin remoteRepositoryAdmin;
+
+    public RemoteRepositoryAdmin getRemoteRepositoryAdmin()
     {
-        configuration.addRemoteRepository( repository );
+        return remoteRepositoryAdmin;
     }
 
-    protected void removeRepository( String repoId, Configuration configuration )
+    public void setRemoteRepositoryAdmin( RemoteRepositoryAdmin remoteRepositoryAdmin )
     {
-        RemoteRepositoryConfiguration toremove = configuration.findRemoteRepositoryById(
repoId );
-        if ( toremove != null )
-        {
-            configuration.removeRemoteRepository( toremove );
-        }
+        this.remoteRepositoryAdmin = remoteRepositoryAdmin;
     }
 }

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java?rev=1165335&r1=1165334&r2=1165335&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java
Mon Sep  5 15:31:04 2011
@@ -101,7 +101,7 @@ public class AddManagedRepositoryAction
         return result;
     }
 
-    // FIXME olamy dupe with admin repo componennt
+    // FIXME olamy dupe with admin repo component
     @Override
     public void validate()
     {

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryAction.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryAction.java?rev=1165335&r1=1165334&r2=1165335&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryAction.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryAction.java
Mon Sep  5 15:31:04 2011
@@ -21,15 +21,12 @@ package org.apache.maven.archiva.web.act
 
 import com.opensymphony.xwork2.Preparable;
 import com.opensymphony.xwork2.Validateable;
-import org.apache.archiva.audit.AuditEvent;
+import org.apache.archiva.admin.repository.RepositoryAdminException;
+import org.apache.archiva.admin.repository.remote.RemoteRepository;
 import org.apache.maven.archiva.configuration.Configuration;
-import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
-import org.codehaus.plexus.redback.role.RoleManagerException;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Controller;
 
-import java.io.IOException;
-
 /**
  * AddRemoteRepositoryAction
  *
@@ -44,11 +41,11 @@ public class AddRemoteRepositoryAction
     /**
      * The model for this action.
      */
-    private RemoteRepositoryConfiguration repository;
+    private RemoteRepository repository;
 
     public void prepare()
     {
-        this.repository = new RemoteRepositoryConfiguration();
+        this.repository = new RemoteRepository();
     }
 
     public String input()
@@ -58,33 +55,22 @@ public class AddRemoteRepositoryAction
 
     public String commit()
     {
-        Configuration configuration = archivaConfiguration.getConfiguration();
-
-        //MRM-752 - url needs trimming
-        repository.setUrl( repository.getUrl().trim() );
 
-        // Save the repository configuration.
-        String result;
+        String result = SUCCESS;
         try
         {
-            addRepository( repository, configuration );
-            triggerAuditEvent( repository.getId(), null, AuditEvent.ADD_REMOTE_REPO );
-            result = saveConfiguration( configuration );
-        }
-        catch ( IOException e )
-        {
-            addActionError( "I/O Exception: " + e.getMessage() );
-            result = INPUT;
+            getRemoteRepositoryAdmin().addRemoteRepository( repository, getAuditInformation()
);
         }
-        catch ( RoleManagerException e )
+        catch ( RepositoryAdminException e )
         {
-            addActionError( "Role Manager Exception: " + e.getMessage() );
+            addActionError( "RepositoryAdminException: " + e.getMessage() );
             result = INPUT;
         }
 
         return result;
     }
 
+    // FIXME olamy dupe with admin repo component
     @Override
     public void validate()
     {
@@ -109,12 +95,12 @@ public class AddRemoteRepositoryAction
         }
     }
 
-    public RemoteRepositoryConfiguration getRepository()
+    public RemoteRepository getRepository()
     {
         return repository;
     }
 
-    public void setRepository( RemoteRepositoryConfiguration repository )
+    public void setRepository( RemoteRepository repository )
     {
         this.repository = repository;
     }

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryAction.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryAction.java?rev=1165335&r1=1165334&r2=1165335&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryAction.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryAction.java
Mon Sep  5 15:31:04 2011
@@ -20,21 +20,16 @@ package org.apache.maven.archiva.web.act
  */
 
 import com.opensymphony.xwork2.Preparable;
-import org.apache.archiva.audit.AuditEvent;
+import org.apache.archiva.admin.repository.RepositoryAdminException;
+import org.apache.archiva.admin.repository.remote.RemoteRepository;
 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 org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Controller;
 
-import java.util.List;
-
 /**
  * DeleteRemoteRepositoryAction
  *
  * @version $Id$
- * plexus.component role="com.opensymphony.xwork2.Action" role-hint="deleteRemoteRepositoryAction"
instantiation-strategy="per-lookup"
  */
 @Controller( "deleteRemoteRepositoryAction" )
 @Scope( "prototype" )
@@ -42,15 +37,16 @@ public class DeleteRemoteRepositoryActio
     extends AbstractRemoteRepositoriesAction
     implements Preparable
 {
-    private RemoteRepositoryConfiguration repository;
+    private RemoteRepository repository;
 
     private String repoid;
 
     public void prepare()
+        throws RepositoryAdminException
     {
         if ( StringUtils.isNotBlank( repoid ) )
         {
-            this.repository = archivaConfiguration.getConfiguration().findRemoteRepositoryById(
repoid );
+            this.repository = getRemoteRepositoryAdmin().getRemoteRepository( repoid );
         }
     }
 
@@ -68,43 +64,32 @@ public class DeleteRemoteRepositoryActio
     public String delete()
     {
         String result = SUCCESS;
-        RemoteRepositoryConfiguration existingRepository = repository;
+        RemoteRepository existingRepository = repository;
         if ( existingRepository == null )
         {
             addActionError( "A repository with that id does not exist" );
             return ERROR;
         }
 
-        Configuration configuration = archivaConfiguration.getConfiguration();
-        removeRepository( repoid, configuration );
-        triggerAuditEvent( repoid, null, AuditEvent.DELETE_REMOTE_REPO );
-        result = saveConfiguration( configuration );
-
-        cleanupRepositoryData( existingRepository );
-
-        return result;
-    }
-
-    private void cleanupRepositoryData( RemoteRepositoryConfiguration existingRepository
)
-    {
-        // [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository.
-
-        List<ProxyConnectorConfiguration> proxyConnectors = getProxyConnectors();
-        for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors )
+        try
+        {
+            getRemoteRepositoryAdmin().deleteRemoteRepository( existingRepository.getId(),
getAuditInformation() );
+        }
+        catch ( RepositoryAdminException e )
         {
-            if ( StringUtils.equals( proxyConnector.getTargetRepoId(), existingRepository.getId()
) )
-            {
-                archivaConfiguration.getConfiguration().removeProxyConnector( proxyConnector
);
-            }
+            addActionError( "RepositoryAdminException: " + e.getMessage() );
+            result = ERROR;
         }
+        return result;
     }
 
-    public RemoteRepositoryConfiguration getRepository()
+
+    public RemoteRepository getRepository()
     {
         return repository;
     }
 
-    public void setRepository( RemoteRepositoryConfiguration repository )
+    public void setRepository( RemoteRepository repository )
     {
         this.repository = repository;
     }

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditRemoteRepositoryAction.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditRemoteRepositoryAction.java?rev=1165335&r1=1165334&r2=1165335&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditRemoteRepositoryAction.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditRemoteRepositoryAction.java
Mon Sep  5 15:31:04 2011
@@ -20,22 +20,16 @@ package org.apache.maven.archiva.web.act
  */
 
 import com.opensymphony.xwork2.Preparable;
-import org.apache.archiva.audit.AuditEvent;
+import org.apache.archiva.admin.repository.RepositoryAdminException;
+import org.apache.archiva.admin.repository.remote.RemoteRepository;
 import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.configuration.Configuration;
-import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
-import org.codehaus.plexus.redback.role.RoleManagerException;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Controller;
 
-import java.io.IOException;
-
 /**
  * EditRemoteRepositoryAction
  *
  * @version $Id$
- *          <p/>
- *          plexus.component role="com.opensymphony.xwork2.Action" role-hint="editRemoteRepositoryAction"
instantiation-strategy="per-lookup"
  */
 @Controller( "editRemoteRepositoryAction" )
 @Scope( "prototype" )
@@ -46,7 +40,7 @@ public class EditRemoteRepositoryAction
     /**
      * The model for this action.
      */
-    private RemoteRepositoryConfiguration repository;
+    private RemoteRepository repository;
 
     /**
      * The repository id to edit.
@@ -54,11 +48,11 @@ public class EditRemoteRepositoryAction
     private String repoid;
 
     public void prepare()
+        throws RepositoryAdminException
     {
-        String id = repoid;
         if ( StringUtils.isNotBlank( repoid ) )
         {
-            this.repository = archivaConfiguration.getConfiguration().findRemoteRepositoryById(
id );
+            this.repository = getRemoteRepositoryAdmin().getRemoteRepository( repoid );
         }
     }
 
@@ -75,39 +69,26 @@ public class EditRemoteRepositoryAction
 
     public String commit()
     {
-        Configuration configuration = archivaConfiguration.getConfiguration();
-
-        // We are in edit mode, remove the old repository configuration.
-        removeRepository( repository.getId(), configuration );
-
-        // Save the repository configuration.
-        String result;
+        String result = SUCCESS;
         try
         {
-            addRepository( repository, configuration );
-            triggerAuditEvent( repository.getId(), null, AuditEvent.MODIFY_REMOTE_REPO );
-            result = saveConfiguration( configuration );
-        }
-        catch ( IOException e )
-        {
-            addActionError( "I/O Exception: " + e.getMessage() );
-            result = INPUT;
+            getRemoteRepositoryAdmin().updateRemoteRepository( getRepository(), getAuditInformation()
);
         }
-        catch ( RoleManagerException e )
+        catch ( RepositoryAdminException e )
         {
-            addActionError( "Role Manager Exception: " + e.getMessage() );
+            addActionError( "RepositoryAdminException: " + e.getMessage() );
             result = INPUT;
         }
 
         return result;
     }
 
-    public RemoteRepositoryConfiguration getRepository()
+    public RemoteRepository getRepository()
     {
         return repository;
     }
 
-    public void setRepository( RemoteRepositoryConfiguration repository )
+    public void setRepository( RemoteRepository repository )
     {
         this.repository = repository;
     }

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryActionTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryActionTest.java?rev=1165335&r1=1165334&r2=1165335&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryActionTest.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryActionTest.java
Mon Sep  5 15:31:04 2011
@@ -20,9 +20,10 @@ package org.apache.maven.archiva.web.act
  */
 
 import com.opensymphony.xwork2.Action;
+import org.apache.archiva.admin.repository.remote.DefaultRemoteRepositoryAdmin;
+import org.apache.archiva.admin.repository.remote.RemoteRepository;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
 import org.apache.maven.archiva.configuration.Configuration;
-import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
 import org.apache.maven.archiva.web.action.AbstractActionTestCase;
 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
 import org.codehaus.redback.integration.interceptor.SecureActionException;
@@ -31,7 +32,7 @@ import org.easymock.MockControl;
 import java.util.Collections;
 
 /**
- * AddRemoteRepositoryActionTest 
+ * AddRemoteRepositoryActionTest
  *
  * @version $Id$
  */
@@ -51,12 +52,13 @@ public class AddRemoteRepositoryActionTe
     {
         super.setUp();
 
-        //action = (AddRemoteRepositoryAction) lookup( Action.class.getName(), "addRemoteRepositoryAction"
);
         action = (AddRemoteRepositoryAction) getActionProxy( "/admin/addRemoteRepository.action"
).getAction();
 
         archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class
);
         archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
         action.setArchivaConfiguration( archivaConfiguration );
+        ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration(
+            archivaConfiguration );
     }
 
     public void testSecureActionBundle()
@@ -80,7 +82,7 @@ public class AddRemoteRepositoryActionTe
         archivaConfigurationControl.replay();
 
         action.prepare();
-        RemoteRepositoryConfiguration configuration = action.getRepository();
+        RemoteRepository configuration = action.getRepository();
         assertNotNull( configuration );
         assertNull( configuration.getId() );
 
@@ -97,31 +99,35 @@ public class AddRemoteRepositoryActionTe
 
         archivaConfiguration.save( configuration );
 
+        archivaConfiguration.getConfiguration();
+        archivaConfigurationControl.setReturnValue( configuration );
+
         archivaConfigurationControl.replay();
 
         action.prepare();
-        RemoteRepositoryConfiguration repository = action.getRepository();
+        RemoteRepository repository = action.getRepository();
         populateRepository( repository );
-        
-        assertEquals("url ", repository.getUrl());
+
+        assertEquals( "url ", repository.getUrl() );
 
         String status = action.commit();
         assertEquals( Action.SUCCESS, status );
 
-        assertEquals( Collections.singletonList( repository ), configuration.getRemoteRepositories()
);
-        
-        assertEquals("url", repository.getUrl());
+        assertEquals( Collections.singletonList( repository ),
+                      action.getRemoteRepositoryAdmin().getRemoteRepositories() );
+
+        assertEquals( "url", repository.getUrl() );
 
         archivaConfigurationControl.verify();
     }
-    
-    private void populateRepository( RemoteRepositoryConfiguration repository )
+
+    private void populateRepository( RemoteRepository repository )
     {
         repository.setId( REPO_ID );
         repository.setName( "repo name" );
         repository.setUrl( "url " );
         repository.setLayout( "default" );
     }
-    
+
     // TODO: test errors during add, other actions
 }

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryActionTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryActionTest.java?rev=1165335&r1=1165334&r2=1165335&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryActionTest.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryActionTest.java
Mon Sep  5 15:31:04 2011
@@ -20,6 +20,9 @@ package org.apache.maven.archiva.web.act
  */
 
 import com.opensymphony.xwork2.Action;
+import org.apache.archiva.admin.repository.RepositoryAdminException;
+import org.apache.archiva.admin.repository.remote.DefaultRemoteRepositoryAdmin;
+import org.apache.archiva.admin.repository.remote.RemoteRepository;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
 import org.apache.maven.archiva.configuration.Configuration;
 import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
@@ -59,23 +62,30 @@ public class DeleteRemoteRepositoryActio
         archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class
);
         archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
         action.setArchivaConfiguration( archivaConfiguration );
+
+        ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration(
+            archivaConfiguration );
     }
 
     public void testDeleteRemoteRepositoryConfirmation()
         throws Exception
     {
-        RemoteRepositoryConfiguration originalRepository = createRepository();
+        RemoteRepository originalRepository = createRepository();
         Configuration configuration = createConfigurationForEditing( originalRepository );
 
         archivaConfiguration.getConfiguration();
         archivaConfigurationControl.setReturnValue( configuration );
+
+        archivaConfiguration.getConfiguration();
+        archivaConfigurationControl.setReturnValue( configuration );
+
         archivaConfigurationControl.replay();
 
         action.setRepoid( REPO_ID );
 
         action.prepare();
         assertEquals( REPO_ID, action.getRepoid() );
-        RemoteRepositoryConfiguration repository = action.getRepository();
+        RemoteRepository repository = action.getRepository();
         assertNotNull( repository );
         assertRepositoryEquals( repository, createRepository() );
 
@@ -83,17 +93,16 @@ public class DeleteRemoteRepositoryActio
         assertEquals( Action.INPUT, status );
         repository = action.getRepository();
         assertRepositoryEquals( repository, createRepository() );
-        assertEquals( Collections.singletonList( originalRepository ), configuration.getRemoteRepositories()
);
+        assertEquals( Collections.singletonList( originalRepository ),
+                      action.getRemoteRepositoryAdmin().getRemoteRepositories() );
     }
 
     public void testDeleteRemoteRepository()
-        throws RegistryException, IndeterminateConfigurationException
+        throws RegistryException, IndeterminateConfigurationException, RepositoryAdminException
     {
         Configuration configuration = createConfigurationForEditing( createRepository() );
-        configuration.addManagedRepository(
-            createManagedRepository( "internal", "target/repo/internal" ));
-        configuration.addManagedRepository(
-            createManagedRepository( "snapshots", "target/repo/snapshots" ) );
+        configuration.addManagedRepository( createManagedRepository( "internal", "target/repo/internal"
) );
+        configuration.addManagedRepository( createManagedRepository( "snapshots", "target/repo/snapshots"
) );
         configuration.addProxyConnector( createProxyConnector( "internal", REPO_ID ) );
 
         archivaConfiguration.getConfiguration();
@@ -106,7 +115,7 @@ public class DeleteRemoteRepositoryActio
 
         action.prepare();
         assertEquals( REPO_ID, action.getRepoid() );
-        RemoteRepositoryConfiguration repository = action.getRepository();
+        RemoteRepository repository = action.getRepository();
         assertNotNull( repository );
         assertRepositoryEquals( repository, createRepository() );
 
@@ -122,7 +131,7 @@ public class DeleteRemoteRepositoryActio
     public void testDeleteRemoteRepositoryCancelled()
         throws Exception
     {
-        RemoteRepositoryConfiguration originalRepository = createRepository();
+        RemoteRepository originalRepository = createRepository();
         Configuration configuration = createConfigurationForEditing( originalRepository );
 
         archivaConfiguration.getConfiguration();
@@ -135,35 +144,40 @@ public class DeleteRemoteRepositoryActio
 
         action.prepare();
         assertEquals( REPO_ID, action.getRepoid() );
-        RemoteRepositoryConfiguration repositoryConfiguration = action.getRepository();
+        RemoteRepository repositoryConfiguration = action.getRepository();
         assertNotNull( repositoryConfiguration );
         assertRepositoryEquals( repositoryConfiguration, createRepository() );
 
         String status = action.execute();
         assertEquals( Action.SUCCESS, status );
 
-        RemoteRepositoryConfiguration repository = action.getRepository();
+        RemoteRepository repository = action.getRepository();
         assertRepositoryEquals( repository, createRepository() );
-        assertEquals( Collections.singletonList( originalRepository ), configuration.getRemoteRepositories()
);
+        assertEquals( Collections.singletonList( originalRepository ),
+                      action.getRemoteRepositoryAdmin().getRemoteRepositories() );
     }
 
-    private Configuration createConfigurationForEditing( RemoteRepositoryConfiguration repositoryConfiguration
)
+    private Configuration createConfigurationForEditing( RemoteRepository repositoryConfiguration
)
     {
         Configuration configuration = new Configuration();
-        configuration.addRemoteRepository( repositoryConfiguration );
+        RemoteRepositoryConfiguration conf = new RemoteRepositoryConfiguration();
+        conf.setId( repositoryConfiguration.getId() );
+        conf.setLayout( repositoryConfiguration.getLayout() );
+        conf.setUrl( repositoryConfiguration.getUrl() );
+        conf.setName( repositoryConfiguration.getName() );
+        configuration.addRemoteRepository( conf );
         return configuration;
     }
 
-    private RemoteRepositoryConfiguration createRepository()
+    private RemoteRepository createRepository()
     {
-        RemoteRepositoryConfiguration r = new RemoteRepositoryConfiguration();
+        RemoteRepository r = new RemoteRepository();
         r.setId( REPO_ID );
         populateRepository( r );
         return r;
     }
 
-    private void assertRepositoryEquals( RemoteRepositoryConfiguration expectedRepository,
-                                         RemoteRepositoryConfiguration actualRepository )
+    private void assertRepositoryEquals( RemoteRepository expectedRepository, RemoteRepository
actualRepository )
     {
         assertEquals( expectedRepository.getId(), actualRepository.getId() );
         assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() );
@@ -197,7 +211,7 @@ public class DeleteRemoteRepositoryActio
         return connector;
     }
 
-    private void populateRepository( RemoteRepositoryConfiguration repository )
+    private void populateRepository( RemoteRepository repository )
     {
         repository.setId( REPO_ID );
         repository.setName( "repo name" );

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditRemoteRepositoryActionTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditRemoteRepositoryActionTest.java?rev=1165335&r1=1165334&r2=1165335&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditRemoteRepositoryActionTest.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditRemoteRepositoryActionTest.java
Mon Sep  5 15:31:04 2011
@@ -20,6 +20,9 @@ package org.apache.maven.archiva.web.act
  */
 
 import com.opensymphony.xwork2.Action;
+import org.apache.archiva.admin.repository.RepositoryAdminException;
+import org.apache.archiva.admin.repository.remote.DefaultRemoteRepositoryAdmin;
+import org.apache.archiva.admin.repository.remote.RemoteRepository;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
 import org.apache.maven.archiva.configuration.Configuration;
 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
@@ -31,7 +34,7 @@ import org.easymock.MockControl;
 import java.util.Collections;
 
 /**
- * EditRemoteRepositoryActionTest 
+ * EditRemoteRepositoryActionTest
  *
  * @version $Id$
  */
@@ -52,6 +55,21 @@ public class EditRemoteRepositoryActionT
         return new String[]{ "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml"
};
     }
 
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        action = (EditRemoteRepositoryAction) getActionProxy( "/admin/editRemoteRepository.action"
).getAction();
+
+        archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class
);
+        archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
+        action.setArchivaConfiguration( archivaConfiguration );
+
+        ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration(
+            archivaConfiguration );
+    }
+
     public void testEditRemoteRepository()
         throws Exception
     {
@@ -59,23 +77,26 @@ public class EditRemoteRepositoryActionT
         archivaConfiguration.getConfiguration();
         archivaConfigurationControl.setReturnValue( configuration );
         archivaConfigurationControl.setReturnValue( configuration );
+        archivaConfigurationControl.setReturnValue( configuration );
         archivaConfiguration.save( configuration );
         archivaConfigurationControl.replay();
 
         action.setRepoid( REPO_ID );
         action.prepare();
+
         assertEquals( REPO_ID, action.getRepoid() );
-        RemoteRepositoryConfiguration repository = action.getRepository();
+        RemoteRepository repository = action.getRepository();
         populateRepository( repository );
         repository.setName( "new repo name" );
 
         String status = action.commit();
         assertEquals( Action.SUCCESS, status );
 
-        RemoteRepositoryConfiguration newRepository = createRepository();
+        RemoteRepository newRepository = createRepository();
         newRepository.setName( "new repo name" );
         assertRepositoryEquals( repository, newRepository );
-        assertEquals( Collections.singletonList( repository ), configuration.getRemoteRepositories()
);
+        assertEquals( Collections.singletonList( repository ),
+                      action.getRemoteRepositoryAdmin().getRemoteRepositories() );
 
         archivaConfigurationControl.verify();
     }
@@ -93,7 +114,7 @@ public class EditRemoteRepositoryActionT
 
         action.prepare();
         assertEquals( REPO_ID, action.getRepoid() );
-        RemoteRepositoryConfiguration repository = action.getRepository();
+        RemoteRepository repository = action.getRepository();
         assertNotNull( repository );
         assertRepositoryEquals( repository, createRepository() );
 
@@ -104,7 +125,7 @@ public class EditRemoteRepositoryActionT
     }
 
     public void testSecureActionBundle()
-        throws SecureActionException
+        throws SecureActionException, RepositoryAdminException
     {
         archivaConfiguration.getConfiguration();
         archivaConfigurationControl.setReturnValue( new Configuration() );
@@ -116,8 +137,7 @@ public class EditRemoteRepositoryActionT
         assertEquals( 1, bundle.getAuthorizationTuples().size() );
     }
 
-    private void assertRepositoryEquals( RemoteRepositoryConfiguration expectedRepository,
-                                         RemoteRepositoryConfiguration actualRepository )
+    private void assertRepositoryEquals( RemoteRepository expectedRepository, RemoteRepository
actualRepository )
     {
         assertEquals( expectedRepository.getId(), actualRepository.getId() );
         assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() );
@@ -125,40 +145,31 @@ public class EditRemoteRepositoryActionT
         assertEquals( expectedRepository.getName(), actualRepository.getName() );
     }
 
-    private Configuration createConfigurationForEditing( RemoteRepositoryConfiguration repositoryConfiguration
)
+    private Configuration createConfigurationForEditing( RemoteRepository repositoryConfiguration
)
     {
         Configuration configuration = new Configuration();
-        configuration.addRemoteRepository( repositoryConfiguration );
+        RemoteRepositoryConfiguration conf = new RemoteRepositoryConfiguration();
+        conf.setId( repositoryConfiguration.getId() );
+        conf.setLayout( repositoryConfiguration.getLayout() );
+        conf.setUrl( repositoryConfiguration.getUrl() );
+        conf.setName( repositoryConfiguration.getName() );
+        configuration.addRemoteRepository( conf );
         return configuration;
     }
-    
-    private RemoteRepositoryConfiguration createRepository()
+
+    private RemoteRepository createRepository()
     {
-        RemoteRepositoryConfiguration r = new RemoteRepositoryConfiguration();
+        RemoteRepository r = new RemoteRepository();
         r.setId( REPO_ID );
         populateRepository( r );
         return r;
     }
-    
-    private void populateRepository( RemoteRepositoryConfiguration repository )
+
+    private void populateRepository( RemoteRepository repository )
     {
         repository.setId( REPO_ID );
         repository.setName( "repo name" );
         repository.setUrl( "url" );
         repository.setLayout( "default" );
     }
-    
-    protected void setUp()
-        throws Exception
-    {
-        super.setUp();
-
-        //action = (EditRemoteRepositoryAction) lookup( Action.class.getName(), "editRemoteRepositoryAction"
);
-
-        action = (EditRemoteRepositoryAction) getActionProxy( "/admin/editRemoteRepository.action"
).getAction();
-
-        archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class
);
-        archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
-        action.setArchivaConfiguration( archivaConfiguration );
-    }
 }



Mime
View raw message