]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1424] Implement WS for creating stage repository
authorMaria Odea B. Ching <oching@apache.org>
Sat, 9 Oct 2010 13:48:48 +0000 (13:48 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Sat, 9 Oct 2010 13:48:48 +0000 (13:48 +0000)
submitted by Warner Pinero

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1006162 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/AdministrationService.java
archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java
archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java

index ecff3da4ef42573faf1084dd479758d7bb826206..214c9bad28d96ef9b74d9461119b7dda63cda5f9 100644 (file)
@@ -101,7 +101,7 @@ public interface AdministrationService
      */
     public Boolean addManagedRepository( String repoId, String layout, String name, String location,
                                          boolean blockRedeployments, boolean releasesIncluded,
-                                         boolean snapshotsIncluded, String cronExpression )
+                                         boolean snapshotsIncluded, boolean stageRepoNeeded, String cronExpression )
         throws Exception;
 
     /**
index 08db94ec72a9e5b6086b8406195911e3f8b20ea5..eda066da5e4a7b07adb0abeb52674bde8458ee9f 100644 (file)
@@ -87,19 +87,19 @@ public class AdministrationServiceImpl
     private MetadataRepository metadataRepository;
 
     private RepositoryStatisticsManager repositoryStatisticsManager;
-    
+
     private RepositoryMerger repositoryMerger;
-    
+
     private static final String STAGE = "-stage";
-    
+
     private AuditListener auditListener;
 
     public AdministrationServiceImpl( ArchivaConfiguration archivaConfig, RepositoryContentConsumers repoConsumersUtil,
                                       RepositoryContentFactory repoFactory, MetadataRepository metadataRepository,
                                       RepositoryArchivaTaskScheduler repositoryTaskScheduler,
                                       Collection<RepositoryListener> listeners,
-                                      RepositoryStatisticsManager repositoryStatisticsManager, RepositoryMerger repositoryMerger,
-                                      AuditListener auditListener )
+                                      RepositoryStatisticsManager repositoryStatisticsManager,
+                                      RepositoryMerger repositoryMerger, AuditListener auditListener )
     {
         this.archivaConfiguration = archivaConfig;
         this.repoConsumersUtil = repoConsumersUtil;
@@ -344,7 +344,7 @@ public class AdministrationServiceImpl
 
     public Boolean addManagedRepository( String repoId, String layout, String name, String location,
                                          boolean blockRedeployments, boolean releasesIncluded,
-                                         boolean snapshotsIncluded, String cronExpression )
+                                         boolean snapshotsIncluded, boolean stageRepoNeeded, String cronExpression )
         throws Exception
     {
 
@@ -384,20 +384,14 @@ public class AdministrationServiceImpl
         repository.setLayout( layout );
         repository.setRefreshCronExpression( cronExpression );
 
-        File file = new File( repository.getLocation() );
-        repository.setLocation( file.getCanonicalPath() );
+        addRepository( repository, config );
 
-        if ( !file.exists() )
+        if ( stageRepoNeeded )
         {
-            file.mkdirs();
+            ManagedRepositoryConfiguration stagingRepository = getStageRepoConfig( repository );
+            addRepository( stagingRepository, config );
         }
 
-        if ( !file.exists() || !file.isDirectory() )
-        {
-            throw new IOException( "Unable to add repository - no write access, can not create the root directory: "
-                + file );
-        }
-        config.addManagedRepository( repository );
         saveConfiguration( config );
         return Boolean.TRUE;
     }
@@ -446,8 +440,7 @@ public class AdministrationServiceImpl
                 List<String> repoGroups = repoToGroupMap.get( repository.getId() );
                 for ( String repoGroup : repoGroups )
                 {
-                    archivaConfiguration.getConfiguration().findRepositoryGroupById( repoGroup ).removeRepository(
-                                                                                                                   repository.getId() );
+                    archivaConfiguration.getConfiguration().findRepositoryGroupById( repoGroup ).removeRepository( repository.getId() );
                 }
             }
         }
@@ -478,43 +471,46 @@ public class AdministrationServiceImpl
         String stagingId = repoId + STAGE;
         ManagedRepositoryConfiguration repoConfig;
         ManagedRepositoryConfiguration stagingConfig;
-        
+
         Configuration config = archivaConfiguration.getConfiguration();
         repoConfig = config.findManagedRepositoryById( repoId );
 
-        if( repoConfig != null )
-        { 
+        if ( repoConfig != null )
+        {
             stagingConfig = config.findManagedRepositoryById( stagingId );
-            
-            if( stagingConfig != null )
+
+            if ( stagingConfig != null )
             {
                 List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts( stagingId );
-                
-                if( repoConfig.isReleases() && !repoConfig.isSnapshots() )
+
+                if ( repoConfig.isReleases() && !repoConfig.isSnapshots() )
                 {
-                    if( skipConflicts )
-                    {        
-                        List<ArtifactMetadata> conflicts = repositoryMerger.getConflictingArtifacts( stagingId, stagingId );
+                    if ( skipConflicts )
+                    {
+                        List<ArtifactMetadata> conflicts =
+                            repositoryMerger.getConflictingArtifacts( stagingId, stagingId );
                         sourceArtifacts.removeAll( conflicts );
                         mergeWithOutSnapshots( sourceArtifacts, stagingId, repoId );
                     }
                     else
                     {
-                        mergeWithOutSnapshots( sourceArtifacts, stagingId, repoId );    
-                    }       
+                        mergeWithOutSnapshots( sourceArtifacts, stagingId, repoId );
+                    }
                 }
                 else
                 {
-                    if( skipConflicts )
+                    if ( skipConflicts )
                     {
-                        List<ArtifactMetadata> conflicts = repositoryMerger.getConflictingArtifacts( stagingId, stagingId );
+                        List<ArtifactMetadata> conflicts =
+                            repositoryMerger.getConflictingArtifacts( stagingId, stagingId );
                         sourceArtifacts.removeAll( conflicts );
-                        Filter<ArtifactMetadata> artifactsWithOutConflicts = new IncludesFilter<ArtifactMetadata>( sourceArtifacts );
-                        repositoryMerger.merge( stagingId, repoId, artifactsWithOutConflicts );   
+                        Filter<ArtifactMetadata> artifactsWithOutConflicts =
+                            new IncludesFilter<ArtifactMetadata>( sourceArtifacts );
+                        repositoryMerger.merge( stagingId, repoId, artifactsWithOutConflicts );
                     }
                     else
                     {
-                        repositoryMerger.merge( stagingId, repoId );    
+                        repositoryMerger.merge( stagingId, repoId );
                     }
                 }
             }
@@ -527,26 +523,45 @@ public class AdministrationServiceImpl
         {
             throw new Exception( "Repository Id : " + repoId + " not found." );
         }
-        
+
         if ( !repositoryTaskScheduler.isProcessingRepositoryTask( repoId ) )
         {
             RepositoryTask task = new RepositoryTask();
             task.setRepositoryId( repoId );
 
-            repositoryTaskScheduler.queueTask( task );            
+            repositoryTaskScheduler.queueTask( task );
         }
 
         AuditEvent event = createAuditEvent( repoConfig );
 
         // add event for audit log reports
         metadataRepository.addMetadataFacet( event.getRepositoryId(), event );
-        
-        // log event in archiva audit log 
+
+        // log event in archiva audit log
         auditListener.auditEvent( createAuditEvent( repoConfig ) );
-        
+
         return true;
     }
+
+    protected void addRepository( ManagedRepositoryConfiguration repository, Configuration configuration )
+        throws IOException
+    {
+        // Normalize the path
+        File file = new File( repository.getLocation() );
+        repository.setLocation( file.getCanonicalPath() );
+        if ( !file.exists() )
+        {
+            file.mkdirs();
+        }
+        if ( !file.exists() || !file.isDirectory() )
+        {
+            throw new IOException( "Unable to add repository - no write access, can not create the root directory: "
+                + file );
+        }
+
+        configuration.addManagedRepository( repository );
+    }
+
     // todo: setting userid of audit event
     private AuditEvent createAuditEvent( ManagedRepositoryConfiguration repoConfig )
     {
@@ -555,8 +570,8 @@ public class AdministrationServiceImpl
         event.setAction( AuditEvent.MERGE_REPO_REMOTE );
         event.setRepositoryId( repoConfig.getId() );
         event.setResource( repoConfig.getLocation() );
-        event.setTimestamp( new Date( ) );
-        
+        event.setTimestamp( new Date() );
+
         return event;
     }
 
@@ -566,17 +581,38 @@ public class AdministrationServiceImpl
         List<ArtifactMetadata> artifactsWithOutSnapshots = new ArrayList<ArtifactMetadata>();
         for ( ArtifactMetadata metadata : sourceArtifacts )
         {
-    
+
             if ( metadata.getProjectVersion().contains( "SNAPSHOT" ) )
             {
                 artifactsWithOutSnapshots.add( metadata );
             }
-    
+
         }
         sourceArtifacts.removeAll( artifactsWithOutSnapshots );
-    
+
         Filter<ArtifactMetadata> artifactListWithOutSnapShots = new IncludesFilter<ArtifactMetadata>( sourceArtifacts );
-        
+
         repositoryMerger.merge( sourceRepoId, repoid, artifactListWithOutSnapShots );
     }
+
+    private ManagedRepositoryConfiguration getStageRepoConfig( ManagedRepositoryConfiguration repository )
+    {
+        ManagedRepositoryConfiguration stagingRepository = new ManagedRepositoryConfiguration();
+        stagingRepository.setId( repository.getId() + "-stage" );
+        stagingRepository.setLayout( repository.getLayout() );
+        stagingRepository.setName( repository.getName() + "-stage" );
+        stagingRepository.setBlockRedeployments( repository.isBlockRedeployments() );
+        stagingRepository.setDaysOlder( repository.getDaysOlder() );
+        stagingRepository.setDeleteReleasedSnapshots( repository.isDeleteReleasedSnapshots() );
+        stagingRepository.setIndexDir( repository.getIndexDir() );
+        String path = repository.getLocation();
+        int lastIndex = path.lastIndexOf( '/' );
+        stagingRepository.setLocation( path.substring( 0, lastIndex ) + "/" + stagingRepository.getId() );
+        stagingRepository.setRefreshCronExpression( repository.getRefreshCronExpression() );
+        stagingRepository.setReleases( repository.isReleases() );
+        stagingRepository.setRetentionCount( repository.getRetentionCount() );
+        stagingRepository.setScanned( repository.isScanned() );
+        stagingRepository.setSnapshots( repository.isSnapshots() );
+        return stagingRepository;
+    }
 }
index 50ba22f6303611d3fa36e32aa1603f513e04f829..6dd467648a0c4e28984d6a91df9a92c208a7d18e 100644 (file)
@@ -19,6 +19,15 @@ package org.apache.archiva.web.xmlrpc.services;
  * under the License.
  */
 
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 import org.apache.archiva.audit.AuditEvent;
 import org.apache.archiva.audit.AuditListener;
 import org.apache.archiva.metadata.model.ArtifactMetadata;
@@ -40,6 +49,7 @@ import org.apache.maven.archiva.configuration.Configuration;
 import org.apache.maven.archiva.configuration.FileTypes;
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
+import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration;
 import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
 import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
 import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
@@ -53,13 +63,6 @@ import org.codehaus.plexus.spring.PlexusInSpringTestCase;
 import org.easymock.MockControl;
 import org.easymock.classextension.MockClassControl;
 
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-
 /**
  * AdministrationServiceImplTest
  * 
@@ -67,26 +70,26 @@ import java.util.List;
  */
 public class AdministrationServiceImplTest
     extends PlexusInSpringTestCase
-{    
+{
     private MockControl archivaConfigControl;
-    
+
     private ArchivaConfiguration archivaConfig;
-    
+
     private MockControl configControl;
-    
+
     private Configuration config;
-    
+
     private AdministrationServiceImpl service;
-    
+
     private MockControl repositoryTaskSchedulerControl;
 
     private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
-    
+
     // repository consumers
     private MockControl repoConsumerUtilsControl;
-    
+
     private RepositoryContentConsumers repoConsumersUtil;
-    
+
     private MockControl knownContentConsumerControl;
 
     private MockControl invalidContentConsumerControl;
@@ -98,12 +101,12 @@ public class AdministrationServiceImplTest
     private InvalidRepositoryContentConsumer checkPomConsumer;
 
     private InvalidRepositoryContentConsumer checkMetadataConsumer;
-    
+
     // delete artifact
     private MockControl repoFactoryControl;
-    
+
     private RepositoryContentFactory repositoryFactory;
-    
+
     private MockControl listenerControl;
 
     private RepositoryListener listener;
@@ -115,85 +118,85 @@ public class AdministrationServiceImplTest
     private MockControl repositoryStatisticsManagerControl;
 
     private RepositoryStatisticsManager repositoryStatisticsManager;
-    
+
     private MockControl repositoryMergerControl;
-    
+
     private RepositoryMerger repositoryMerger;
-    
+
     private MockControl auditListenerControl;
-    
+
     private AuditListener auditListener;
 
     private static final String STAGE = "-stage";
-    
+
     protected void setUp()
         throws Exception
     {
         super.setUp();
-        
+
         archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class );
-        archivaConfig = ( ArchivaConfiguration ) archivaConfigControl.getMock();
-        
+        archivaConfig = (ArchivaConfiguration) archivaConfigControl.getMock();
+
         configControl = MockClassControl.createControl( Configuration.class );
-        config = ( Configuration ) configControl.getMock();      
-        
+        config = (Configuration) configControl.getMock();
+
         repositoryTaskSchedulerControl = MockClassControl.createControl( RepositoryArchivaTaskScheduler.class );
         repositoryTaskScheduler = (RepositoryArchivaTaskScheduler) repositoryTaskSchedulerControl.getMock();
 
         // repo consumers
         repoConsumerUtilsControl = MockClassControl.createControl( RepositoryContentConsumers.class );
-        repoConsumersUtil = ( RepositoryContentConsumers ) repoConsumerUtilsControl.getMock();
-        
+        repoConsumersUtil = (RepositoryContentConsumers) repoConsumerUtilsControl.getMock();
+
         knownContentConsumerControl = MockControl.createControl( KnownRepositoryContentConsumer.class );
-        indexArtifactConsumer = ( KnownRepositoryContentConsumer ) knownContentConsumerControl.getMock();
-        indexPomConsumer = ( KnownRepositoryContentConsumer ) knownContentConsumerControl.getMock();
-        
+        indexArtifactConsumer = (KnownRepositoryContentConsumer) knownContentConsumerControl.getMock();
+        indexPomConsumer = (KnownRepositoryContentConsumer) knownContentConsumerControl.getMock();
+
         invalidContentConsumerControl = MockControl.createControl( InvalidRepositoryContentConsumer.class );
-        checkPomConsumer = ( InvalidRepositoryContentConsumer ) invalidContentConsumerControl.getMock();
-        checkMetadataConsumer = ( InvalidRepositoryContentConsumer ) invalidContentConsumerControl.getMock();
-        
+        checkPomConsumer = (InvalidRepositoryContentConsumer) invalidContentConsumerControl.getMock();
+        checkMetadataConsumer = (InvalidRepositoryContentConsumer) invalidContentConsumerControl.getMock();
+
         // delete artifact
         repoFactoryControl = MockClassControl.createControl( RepositoryContentFactory.class );
-        repositoryFactory = ( RepositoryContentFactory ) repoFactoryControl.getMock();
-        
+        repositoryFactory = (RepositoryContentFactory) repoFactoryControl.getMock();
+
         metadataRepositoryControl = MockControl.createControl( MetadataRepository.class );
         metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock();
-                
+
         listenerControl = MockControl.createControl( RepositoryListener.class );
         listener = (RepositoryListener) listenerControl.getMock();
 
         repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class );
         repositoryStatisticsManager = (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock();
-        
+
         repositoryMergerControl = MockControl.createControl( RepositoryMerger.class );
         repositoryMerger = (RepositoryMerger) repositoryMergerControl.getMock();
-        
+
         auditListenerControl = MockControl.createControl( AuditListener.class );
-        auditListener = ( AuditListener ) auditListenerControl.getMock();
+        auditListener = (AuditListener) auditListenerControl.getMock();
 
         service =
-            new AdministrationServiceImpl( archivaConfig, repoConsumersUtil, repositoryFactory,
-                                           metadataRepository, repositoryTaskScheduler,
-                                           Collections.singletonList( listener ), repositoryStatisticsManager, repositoryMerger, auditListener );
+            new AdministrationServiceImpl( archivaConfig, repoConsumersUtil, repositoryFactory, metadataRepository,
+                                           repositoryTaskScheduler, Collections.singletonList( listener ),
+                                           repositoryStatisticsManager, repositoryMerger, auditListener );
     }
-  
-    /* Tests for repository consumers  */
-    
+
+    /* Tests for repository consumers */
+
     public void testGetAllRepoConsumers()
         throws Exception
-    {   
+    {
         recordRepoConsumers();
-        
+
         repoConsumerUtilsControl.replay();
         knownContentConsumerControl.replay();
         invalidContentConsumerControl.replay();
-                
-        List<String> repoConsumers = service.getAllRepositoryConsumers(); 
-        
+
+        List<String> repoConsumers = service.getAllRepositoryConsumers();
+
         repoConsumerUtilsControl.verify();
         knownContentConsumerControl.verify();
         invalidContentConsumerControl.verify();
-                        
+
         assertNotNull( repoConsumers );
         assertEquals( 4, repoConsumers.size() );
         assertTrue( repoConsumers.contains( "index-artifact" ) );
@@ -201,34 +204,34 @@ public class AdministrationServiceImplTest
         assertTrue( repoConsumers.contains( "check-pom" ) );
         assertTrue( repoConsumers.contains( "check-metadata" ) );
     }
-    
+
     public void testConfigureValidRepositoryConsumer()
         throws Exception
-    {   
+    {
         RepositoryScanningConfiguration repoScanning = new RepositoryScanningConfiguration();
         repoScanning.addKnownContentConsumer( "index-artifact" );
         repoScanning.addKnownContentConsumer( "index-pom" );
-        repoScanning.addInvalidContentConsumer( "check-pom" );        
-        
-     // test enable "check-metadata" consumer
+        repoScanning.addInvalidContentConsumer( "check-pom" );
+
+        // test enable "check-metadata" consumer
         recordRepoConsumers();
-        
+
         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
         configControl.expectAndReturn( config.getRepositoryScanning(), repoScanning );
-        
-        config.setRepositoryScanning( repoScanning );                
+
+        config.setRepositoryScanning( repoScanning );
         configControl.setMatcher( MockControl.ALWAYS_MATCHER );
         configControl.setVoidCallable();
-        
+
         archivaConfig.save( config );
         archivaConfigControl.setVoidCallable();
-                
+
         repoConsumerUtilsControl.replay();
         knownContentConsumerControl.replay();
         invalidContentConsumerControl.replay();
         archivaConfigControl.replay();
-        configControl.replay();        
-        
+        configControl.replay();
+
         try
         {
             boolean success = service.configureRepositoryConsumer( null, "check-metadata", true );
@@ -238,68 +241,67 @@ public class AdministrationServiceImplTest
         {
             fail( "An exception should not have been thrown." );
         }
-        
+
         repoConsumerUtilsControl.verify();
         knownContentConsumerControl.verify();
-        invalidContentConsumerControl.verify();        
+        invalidContentConsumerControl.verify();
         archivaConfigControl.verify();
         configControl.verify();
-                
-     // test disable "check-metadata" consumer 
+
+        // test disable "check-metadata" consumer
         repoConsumerUtilsControl.reset();
         knownContentConsumerControl.reset();
-        invalidContentConsumerControl.reset();        
+        invalidContentConsumerControl.reset();
         archivaConfigControl.reset();
         configControl.reset();
-        
+
         repoScanning.addInvalidContentConsumer( "check-metadata" );
 
         recordRepoConsumers();
-        
+
         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
         configControl.expectAndReturn( config.getRepositoryScanning(), repoScanning );
-        
+
         config.setRepositoryScanning( repoScanning );
         configControl.setMatcher( MockControl.ALWAYS_MATCHER );
         configControl.setVoidCallable();
-        
+
         archivaConfig.save( config );
         archivaConfigControl.setVoidCallable();
-                
+
         repoConsumerUtilsControl.replay();
         knownContentConsumerControl.replay();
         invalidContentConsumerControl.replay();
         archivaConfigControl.replay();
         configControl.replay();
-        
+
         try
         {
             boolean success = service.configureRepositoryConsumer( null, "check-metadata", false );
-            
+
             repoConsumerUtilsControl.verify();
             knownContentConsumerControl.verify();
-            invalidContentConsumerControl.verify();        
+            invalidContentConsumerControl.verify();
             archivaConfigControl.verify();
             configControl.verify();
-            
+
             assertTrue( success );
         }
         catch ( Exception e )
         {
             fail( "An excecption should not have been thrown." );
-        }     
+        }
     }
-    
+
     public void testConfigureInvalidRepositoryConsumer()
         throws Exception
     {
         recordRepoConsumers();
-        
+
         repoConsumerUtilsControl.replay();
         knownContentConsumerControl.replay();
         invalidContentConsumerControl.replay();
-        
+
         try
         {
             service.configureRepositoryConsumer( null, "invalid-consumer", true );
@@ -309,95 +311,97 @@ public class AdministrationServiceImplTest
         {
             assertEquals( "Invalid repository consumer.", e.getMessage() );
         }
-        
+
         repoConsumerUtilsControl.verify();
         knownContentConsumerControl.verify();
-        invalidContentConsumerControl.verify(); 
+        invalidContentConsumerControl.verify();
     }
 
-/* Tests for delete artifact  */
-    
+    /* Tests for delete artifact */
+
     public void testDeleteM2ArtifactArtifactExists()
         throws Exception
     {
-        ManagedRepositoryConfiguration managedRepo = createManagedRepo("default", "default-repo");
-        
+        ManagedRepositoryConfiguration managedRepo = createManagedRepo( "default", "default-repo" );
+
         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
         configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), managedRepo );
-        
+
         ManagedDefaultRepositoryContent repoContent = new ManagedDefaultRepositoryContent();
         repoContent.setRepository( managedRepo );
-        
+
         repoFactoryControl.expectAndReturn( repositoryFactory.getManagedRepositoryContent( "internal" ), repoContent );
-                
+
         List<ArtifactMetadata> artifacts = getArtifacts();
         ArtifactMetadata artifact = artifacts.get( 0 );
 
-        metadataRepositoryControl.expectAndReturn(
-            metadataRepository.getArtifacts( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
-                                             artifact.getVersion() ), artifacts );
+        metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( repoContent.getId(),
+                                                                                    artifact.getNamespace(),
+                                                                                    artifact.getProject(),
+                                                                                    artifact.getVersion() ), artifacts );
         metadataRepository.deleteArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
                                            artifact.getVersion(), artifact.getId() );
 
         listener.deleteArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
                                  artifact.getVersion(), artifact.getId() );
         listenerControl.setVoidCallable( 1 );
-                  
+
         archivaConfigControl.replay();
         configControl.replay();
-        repoFactoryControl.replay();    
+        repoFactoryControl.replay();
         metadataRepositoryControl.replay();
         listenerControl.replay();
-       
+
         boolean success = service.deleteArtifact( "internal", "org.apache.archiva", "archiva-test", "1.0" );
-        assertTrue( success ); 
-        
+        assertTrue( success );
+
         archivaConfigControl.verify();
         configControl.verify();
         repoFactoryControl.verify();
         metadataRepositoryControl.verify();
         listenerControl.verify();
-        
+
         assertFalse( new File( managedRepo.getLocation(), "org/apache/archiva/archiva-test/1.0" ).exists() );
         assertTrue( new File( managedRepo.getLocation(), "org/apache/archiva/archiva-test/1.1" ).exists() );
     }
-    
+
     public void testDeleteM1ArtifactArtifactExists()
         throws Exception
     {
         MockControl fileTypesControl = MockClassControl.createControl( FileTypes.class );
-        FileTypes fileTypes = ( FileTypes ) fileTypesControl.getMock();
-        
+        FileTypes fileTypes = (FileTypes) fileTypesControl.getMock();
+
         MockControl pathParserControl = MockClassControl.createControl( PathParser.class );
-        PathParser parser = ( PathParser ) pathParserControl.getMock();
-        
+        PathParser parser = (PathParser) pathParserControl.getMock();
+
         ManagedRepositoryConfiguration managedRepo = createManagedRepo( "legacy", "legacy-repo" );
-        
+
         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
         configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), managedRepo );
-                
+
         ManagedLegacyRepositoryContent repoContent = new ManagedLegacyRepositoryContent();
         repoContent.setRepository( managedRepo );
         repoContent.setFileTypes( fileTypes );
         repoContent.setLegacyPathParser( parser );
-                
+
         repoFactoryControl.expectAndReturn( repositoryFactory.getManagedRepositoryContent( "internal" ), repoContent );
-        
+
         recordInManagedLegacyRepoContent( fileTypesControl, fileTypes, pathParserControl, parser );
-        
+
         List<ArtifactMetadata> artifacts = getArtifacts();
         ArtifactMetadata artifact = artifacts.get( 0 );
 
-        metadataRepositoryControl.expectAndReturn(
-            metadataRepository.getArtifacts( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
-                                             artifact.getVersion() ), artifacts );
+        metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( repoContent.getId(),
+                                                                                    artifact.getNamespace(),
+                                                                                    artifact.getProject(),
+                                                                                    artifact.getVersion() ), artifacts );
         metadataRepository.deleteArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
                                            artifact.getVersion(), artifact.getId() );
 
         listener.deleteArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
                                  artifact.getVersion(), artifact.getId() );
         listenerControl.setVoidCallable( 1 );
-        
+
         archivaConfigControl.replay();
         configControl.replay();
         repoFactoryControl.replay();
@@ -405,10 +409,10 @@ public class AdministrationServiceImplTest
         listenerControl.replay();
         fileTypesControl.replay();
         pathParserControl.replay();
-       
+
         boolean success = service.deleteArtifact( "internal", "org.apache.archiva", "archiva-test", "1.0" );
-        assertTrue( success ); 
-        
+        assertTrue( success );
+
         archivaConfigControl.verify();
         configControl.verify();
         repoFactoryControl.verify();
@@ -416,11 +420,11 @@ public class AdministrationServiceImplTest
         listenerControl.verify();
         fileTypesControl.verify();
         pathParserControl.verify();
-        
+
         File repo = new File( managedRepo.getLocation() );
         assertFalse( new File( repo, "org.apache.archiva/jars/archiva-test-1.0.jar" ).exists() );
         assertFalse( new File( repo, "org.apache.archiva/poms/archiva-test-1.0.pom" ).exists() );
-        
+
         assertTrue( new File( repo, "org.apache.archiva/jars/archiva-test-1.1.jar" ).exists() );
         assertTrue( new File( repo, "org.apache.archiva/jars/archiva-diff-1.0.jar" ).exists() );
         assertTrue( new File( repo, "org.apache.archiva/poms/archiva-test-1.1.pom" ).exists() );
@@ -430,20 +434,20 @@ public class AdministrationServiceImplTest
     public void testDeleteArtifactArtifactDoesNotExist()
         throws Exception
     {
-        ManagedRepositoryConfiguration managedRepo = createManagedRepo("default", "default-repo");
-        
+        ManagedRepositoryConfiguration managedRepo = createManagedRepo( "default", "default-repo" );
+
         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
         configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), managedRepo );
-        
+
         ManagedDefaultRepositoryContent repoContent = new ManagedDefaultRepositoryContent();
         repoContent.setRepository( managedRepo );
-        
+
         repoFactoryControl.expectAndReturn( repositoryFactory.getManagedRepositoryContent( "internal" ), repoContent );
-        
+
         archivaConfigControl.replay();
         configControl.replay();
         repoFactoryControl.replay();
-       
+
         try
         {
             service.deleteArtifact( "internal", "org.apache.archiva", "archiva-non-existing", "1.0" );
@@ -453,16 +457,16 @@ public class AdministrationServiceImplTest
         {
             assertEquals( "Artifact does not exist.", e.getMessage() );
         }
-        
+
         archivaConfigControl.verify();
         configControl.verify();
         repoFactoryControl.verify();
     }
 
-    private ManagedRepositoryConfiguration createManagedRepo(String layout, String directory)
+    private ManagedRepositoryConfiguration createManagedRepo( String layout, String directory )
         throws IOException
     {
-        File srcDir = new File( getBasedir(), "src/test/repositories/"+ directory );
+        File srcDir = new File( getBasedir(), "src/test/repositories/" + directory );
 
         File repoDir = getTestFile( "target/test-repos/" + directory );
 
@@ -475,16 +479,16 @@ public class AdministrationServiceImplTest
         managedRepo.setLocation( repoDir.getAbsolutePath() );
         return managedRepo;
     }
-    
+
     public void testDeleteArtifacRepositoryDoesNotExist()
         throws Exception
-    {   
+    {
         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
         configControl.expectAndReturn( config.findManagedRepositoryById( "non-existing-repo" ), null );
-        
+
         archivaConfigControl.replay();
         configControl.replay();
-       
+
         try
         {
             service.deleteArtifact( "non-existing-repo", "org.apache.archiva", "archiva-test", "1.0" );
@@ -494,28 +498,29 @@ public class AdministrationServiceImplTest
         {
             assertEquals( "Repository does not exist.", e.getMessage() );
         }
-        
+
         archivaConfigControl.verify();
         configControl.verify();
     }
-    
-/* Tests for repository scanning  */
-    
+
+    /* Tests for repository scanning */
+
     public void testExecuteRepoScannerRepoExistsAndNotBeingScanned()
         throws Exception
-    {        
+    {
         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
         configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ),
                                        createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
-        
+
         RepositoryTask task = new RepositoryTask();
-        
-        repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( "internal" ), false );
-        
+
+        repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( "internal" ),
+                                                        false );
+
         repositoryTaskScheduler.queueTask( task );
         repositoryTaskSchedulerControl.setMatcher( MockControl.ALWAYS_MATCHER );
         repositoryTaskSchedulerControl.setVoidCallable();
-        
+
         archivaConfigControl.replay();
         configControl.replay();
         repositoryTaskSchedulerControl.replay();
@@ -529,25 +534,26 @@ public class AdministrationServiceImplTest
         {
             fail( "An exception should not have been thrown." );
         }
-        
+
         archivaConfigControl.verify();
         configControl.verify();
         repositoryTaskSchedulerControl.verify();
     }
-    
+
     public void testExecuteRepoScannerRepoExistsButBeingScanned()
         throws Exception
-    {        
+    {
         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
         configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ),
                                        createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
-        
-        repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( "internal" ), true);
-        
+
+        repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( "internal" ),
+                                                        true );
+
         archivaConfigControl.replay();
         configControl.replay();
         repositoryTaskSchedulerControl.replay();
-    
+
         try
         {
             boolean success = service.executeRepositoryScanner( "internal" );
@@ -557,21 +563,21 @@ public class AdministrationServiceImplTest
         {
             fail( "An exception should not have been thrown." );
         }
-        
+
         archivaConfigControl.verify();
         configControl.verify();
         repositoryTaskSchedulerControl.verify();
     }
-    
+
     public void testExecuteRepoScannerRepoDoesNotExist()
         throws Exception
     {
         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
         configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), null );
-        
+
         archivaConfigControl.replay();
         configControl.replay();
-       
+
         try
         {
             service.executeRepositoryScanner( "internal" );
@@ -581,34 +587,34 @@ public class AdministrationServiceImplTest
         {
             assertEquals( "Repository does not exist.", e.getMessage() );
         }
-        
+
         archivaConfigControl.verify();
         configControl.verify();
     }
-    
-    /* Tests for querying repositories  */
-    
+
+    /* Tests for querying repositories */
+
     public void testGetAllManagedRepositories()
         throws Exception
     {
-        List<ManagedRepositoryConfiguration> managedRepos = new ArrayList<ManagedRepositoryConfiguration>();        
+        List<ManagedRepositoryConfiguration> managedRepos = new ArrayList<ManagedRepositoryConfiguration>();
         managedRepos.add( createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
         managedRepos.add( createManagedRepo( "snapshots", "default", "Snapshots Repository", false, true ) );
-        
+
         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
         configControl.expectAndReturn( config.getManagedRepositories(), managedRepos );
-        
+
         archivaConfigControl.replay();
         configControl.replay();
-        
-        List<ManagedRepository> repos = service.getAllManagedRepositories(); 
-        
+
+        List<ManagedRepository> repos = service.getAllManagedRepositories();
+
         archivaConfigControl.verify();
         configControl.verify();
-        
+
         assertNotNull( repos );
         assertEquals( 2, repos.size() );
-                
+
         assertManagedRepo( repos.get( 0 ), managedRepos.get( 0 ) );
         assertManagedRepo( repos.get( 1 ), managedRepos.get( 1 ) );
     }
@@ -616,114 +622,119 @@ public class AdministrationServiceImplTest
     public void testGetAllRemoteRepositories()
         throws Exception
     {
-        List<RemoteRepositoryConfiguration> remoteRepos = new ArrayList<RemoteRepositoryConfiguration>(); 
-        remoteRepos.add( createRemoteRepository( "central", "Central Repository", "default", "http://repo1.maven.org/maven2") );
-        remoteRepos.add( createRemoteRepository( "dummy", "Dummy Remote Repository", "legacy", "http://dummy.com/dummy") );
-        
+        List<RemoteRepositoryConfiguration> remoteRepos = new ArrayList<RemoteRepositoryConfiguration>();
+        remoteRepos.add( createRemoteRepository( "central", "Central Repository", "default",
+                                                 "http://repo1.maven.org/maven2" ) );
+        remoteRepos.add( createRemoteRepository( "dummy", "Dummy Remote Repository", "legacy", "http://dummy.com/dummy" ) );
+
         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
         configControl.expectAndReturn( config.getRemoteRepositories(), remoteRepos );
-        
+
         archivaConfigControl.replay();
         configControl.replay();
-        
-        List<RemoteRepository> repos = service.getAllRemoteRepositories(); 
-        
+
+        List<RemoteRepository> repos = service.getAllRemoteRepositories();
+
         archivaConfigControl.verify();
         configControl.verify();
-        
+
         assertNotNull( repos );
         assertEquals( 2, repos.size() );
-         
+
         assertRemoteRepo( repos.get( 0 ), remoteRepos.get( 0 ) );
-        assertRemoteRepo( repos.get( 1 ), remoteRepos.get( 1 ) );        
+        assertRemoteRepo( repos.get( 1 ), remoteRepos.get( 1 ) );
     }
-    
-/* Merge method */
-    
+
+    /* Merge method */
+
     public void testMergeRepositoryWithInvalidRepository()
         throws Exception
     {
         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
         configControl.expectAndReturn( config.findManagedRepositoryById( "invalid" ), null );
-        
+
         archivaConfigControl.replay();
         configControl.replay();
-        
+
         try
         {
             service.merge( "invalid", true );
         }
-        catch( Exception e )
+        catch ( Exception e )
         {
             assertEquals( "Repository Id : invalid not found.", e.getMessage() );
         }
-        
+
         archivaConfigControl.verify();
         configControl.verify();
     }
-    
+
     public void testMergeWithNoStagingRepository()
-        throws Exception 
+        throws Exception
     {
         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
-        configControl.expectAndReturn( config.findManagedRepositoryById( "repo" ), createManagedRepo( "repo", "default", "repo", true, false ) );
+        configControl.expectAndReturn( config.findManagedRepositoryById( "repo" ),
+                                       createManagedRepo( "repo", "default", "repo", true, false ) );
         configControl.expectAndReturn( config.findManagedRepositoryById( "repo-stage" ), null );
-        
+
         archivaConfigControl.replay();
         configControl.replay();
-        
+
         try
         {
             service.merge( "repo", true );
         }
-        catch( Exception e )
+        catch ( Exception e )
         {
             assertEquals( "Staging Id : repo-stage not found.", e.getMessage() );
         }
-        
+
         archivaConfigControl.verify();
-        configControl.verify();   
+        configControl.verify();
     }
-    
-    public void testMergeRepositoriesAndScan( )
+
+    public void testMergeRepositoriesAndScan()
         throws Exception
     {
         List<ArtifactMetadata> sources = new ArrayList<ArtifactMetadata>();
-        
+
         ArtifactMetadata artifact = new ArtifactMetadata();
         artifact.setId( "artifact" );
         artifact.setFileLastModified( System.currentTimeMillis() );
-        
+
         sources.add( artifact );
-        
+
         ManagedRepositoryConfiguration merge = createManagedRepo( "merge", "default", "merge", true, true );
         merge.setLocation( "target/test-repository/merge" );
         ManagedRepositoryConfiguration staging = createStagingRepo( merge );
-        
+
         RepositoryTask task = new RepositoryTask();
         task.setScanAll( true );
-        
+
         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
         configControl.expectAndReturn( config.findManagedRepositoryById( "merge" ), merge );
         configControl.expectAndReturn( config.findManagedRepositoryById( "merge-stage" ), staging );
-        
+
         metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( staging.getId() ), sources );
-        repositoryMergerControl.expectAndDefaultReturn( repositoryMerger.getConflictingArtifacts( staging.getId(), merge.getId() ), sources );
+        repositoryMergerControl.expectAndDefaultReturn( repositoryMerger.getConflictingArtifacts( staging.getId(),
+                                                                                                  merge.getId() ),
+                                                        sources );
         repositoryMerger.merge( staging.getId(), merge.getId() );
         repositoryMergerControl.setMatcher( MockControl.ALWAYS_MATCHER );
         repositoryMergerControl.setVoidCallable();
-        repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( "merge" ), false);
-        
+        repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( "merge" ),
+                                                        false );
+
         // scanning after merge
         repositoryTaskScheduler.queueTask( task );
         repositoryTaskSchedulerControl.setMatcher( MockControl.ALWAYS_MATCHER );
         repositoryTaskSchedulerControl.setVoidCallable();
-        
+
         // audit logs
-        metadataRepository.addMetadataFacet( merge.getId() ,createAuditEvent( merge) );
+        metadataRepository.addMetadataFacet( merge.getId(), createAuditEvent( merge ) );
         metadataRepositoryControl.setMatcher( MockControl.ALWAYS_MATCHER );
         metadataRepositoryControl.setVoidCallable();
-        
+
         archivaConfigControl.replay();
         metadataRepositoryControl.replay();
         configControl.replay();
@@ -732,7 +743,7 @@ public class AdministrationServiceImplTest
 
         boolean a = service.merge( "merge", false );
         assertTrue( a );
-        
+
         archivaConfigControl.verify();
         configControl.verify();
         configControl.verify();
@@ -740,55 +751,58 @@ public class AdministrationServiceImplTest
         repositoryMergerControl.verify();
         repositoryTaskSchedulerControl.verify();
     }
-    
-    public void testMergeRepositoriesWithConflictsAndScan( )
+
+    public void testMergeRepositoriesWithConflictsAndScan()
         throws Exception
     {
         List<ArtifactMetadata> sources = new ArrayList<ArtifactMetadata>();
         ArtifactMetadata one = new ArtifactMetadata();
         one.setId( "one" );
         one.setVersion( "1.0" );
-        
+
         ArtifactMetadata two = new ArtifactMetadata();
         two.setId( "two" );
         two.setVersion( "1.0-SNAPSHOT" );
-        
+
         sources.add( one );
         sources.add( two );
-        
+
         List<ArtifactMetadata> conflicts = new ArrayList<ArtifactMetadata>();
         conflicts.add( one );
-        
+
         sources.removeAll( conflicts );
-        
+
         Filter<ArtifactMetadata> artifactsWithOutConflicts = new IncludesFilter<ArtifactMetadata>( sources );
-        
+
         RepositoryTask task = new RepositoryTask();
         task.setScanAll( true );
-        
+
         ManagedRepositoryConfiguration repo = createManagedRepo( "repo", "default", "repo", true, true );
         repo.setLocation( "target/test-repository/one" );
         ManagedRepositoryConfiguration staging = createStagingRepo( repo );
-        
+
         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
         configControl.expectAndReturn( config.findManagedRepositoryById( "repo" ), repo );
         configControl.expectAndReturn( config.findManagedRepositoryById( "repo-stage" ), staging );
-        
+
         metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( staging.getId() ), sources );
-        repositoryMergerControl.expectAndDefaultReturn( repositoryMerger.getConflictingArtifacts( staging.getId(), repo.getId() ), conflicts );
+        repositoryMergerControl.expectAndDefaultReturn( repositoryMerger.getConflictingArtifacts( staging.getId(),
+                                                                                                  repo.getId() ),
+                                                        conflicts );
         repositoryMerger.merge( staging.getId(), repo.getId(), artifactsWithOutConflicts );
         repositoryMergerControl.setMatcher( MockControl.ALWAYS_MATCHER );
         repositoryMergerControl.setVoidCallable();
-        repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( "repo" ), false);
+        repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( "repo" ),
+                                                        false );
         repositoryTaskScheduler.queueTask( task );
         repositoryTaskSchedulerControl.setMatcher( MockControl.ALWAYS_MATCHER );
         repositoryTaskSchedulerControl.setVoidCallable();
-        
+
         // audit logs
-        metadataRepository.addMetadataFacet( repo.getId() ,createAuditEvent( repo ) );
+        metadataRepository.addMetadataFacet( repo.getId()createAuditEvent( repo ) );
         metadataRepositoryControl.setMatcher( MockControl.ALWAYS_MATCHER );
-        metadataRepositoryControl.setVoidCallable();        
-        
+        metadataRepositoryControl.setVoidCallable();
+
         archivaConfigControl.replay();
         metadataRepositoryControl.replay();
         configControl.replay();
@@ -797,44 +811,97 @@ public class AdministrationServiceImplTest
 
         boolean a = service.merge( "repo", true );
         assertTrue( a );
-        
+
         archivaConfigControl.verify();
         configControl.verify();
         configControl.verify();
         metadataRepositoryControl.verify();
-        repositoryMergerControl.verify();        
+        repositoryMergerControl.verify();
         repositoryTaskSchedulerControl.verify();
     }
-    
-/* private methods  */
-    
+
+    public void testAddManagedRepository()
+        throws Exception
+    {
+        String projId = "org.apache.archiva";
+        String repoId = projId + ".releases";
+        String layout = "default";
+        String name = projId + " Releases";
+        String releaseLocation = "target/test-repository/" + projId + ".releases";
+        String stageLocation = releaseLocation + "-stage";
+
+        ManagedRepositoryConfiguration managedRepo = createManagedRepo( "repo1", "default", "repo", true, false );
+        RemoteRepositoryConfiguration remoteRepo =
+            createRemoteRepository( "central", "Central Repository", "default", "http://repo1.maven.org/maven2" );
+        List<String> repositories = new ArrayList<String>();
+        repositories.add( managedRepo.getName() );
+        RepositoryGroupConfiguration repoGroup = createRepoGroupConfig( "repoGroup", repositories );
+        Map<String, ManagedRepositoryConfiguration> managedRepoMap =
+            new HashMap<String, ManagedRepositoryConfiguration>();
+        Map<String, RemoteRepositoryConfiguration> remoteRepoMap = new HashMap<String, RemoteRepositoryConfiguration>();
+        Map<String, RepositoryGroupConfiguration> repoGroupMap = new HashMap<String, RepositoryGroupConfiguration>();
+        managedRepoMap.put( "repo1", managedRepo );
+        remoteRepoMap.put( "repo1", remoteRepo );
+        repoGroupMap.put( "repo1", repoGroup );
+
+        archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+
+        configControl.expectAndReturn( config.getManagedRepositoriesAsMap(), managedRepoMap );
+        configControl.expectAndReturn( config.getRemoteRepositoriesAsMap(), remoteRepoMap );
+        configControl.expectAndReturn( config.getRepositoryGroupsAsMap(), repoGroupMap );
+        config.addManagedRepository( managedRepo );
+        configControl.setMatcher( MockControl.ALWAYS_MATCHER );
+        configControl.setVoidCallable();
+        config.addManagedRepository( managedRepo );
+        configControl.setMatcher( MockControl.ALWAYS_MATCHER );
+        configControl.setVoidCallable();
+        archivaConfig.save( config );
+        archivaConfigControl.setVoidCallable();
+
+        archivaConfigControl.replay();
+        configControl.replay();
+        assertFalse( new File( releaseLocation ).isDirectory() );
+        assertFalse( new File( stageLocation ).isDirectory() );
+        boolean success =
+            service.addManagedRepository( repoId, layout, name, releaseLocation, true, true, false, true,
+                                          "0 15 3 * * ? *" );
+        assertTrue( success );
+        assertTrue( new File( releaseLocation ).isDirectory() );
+        assertTrue( new File( stageLocation ).isDirectory() );
+        new File( releaseLocation ).delete();
+        new File( stageLocation ).delete();
+    }
+
+    /* private methods */
+
     private void assertRemoteRepo( RemoteRepository remoteRepo, RemoteRepositoryConfiguration expectedRepoConfig )
     {
         assertEquals( expectedRepoConfig.getId(), remoteRepo.getId() );
         assertEquals( expectedRepoConfig.getLayout(), remoteRepo.getLayout() );
         assertEquals( expectedRepoConfig.getName(), remoteRepo.getName() );
-        assertEquals( expectedRepoConfig.getUrl(), remoteRepo.getUrl() );       
+        assertEquals( expectedRepoConfig.getUrl(), remoteRepo.getUrl() );
     }
-    
-    private RemoteRepositoryConfiguration createRemoteRepository(String id, String name, String layout, String url)
+
+    private RemoteRepositoryConfiguration createRemoteRepository( String id, String name, String layout, String url )
     {
         RemoteRepositoryConfiguration remoteConfig = new RemoteRepositoryConfiguration();
         remoteConfig.setId( id );
         remoteConfig.setName( name );
         remoteConfig.setLayout( layout );
         remoteConfig.setUrl( url );
-        
+
         return remoteConfig;
     }
-    
+
     private void assertManagedRepo( ManagedRepository managedRepo, ManagedRepositoryConfiguration expectedRepoConfig )
     {
         assertEquals( expectedRepoConfig.getId(), managedRepo.getId() );
         assertEquals( expectedRepoConfig.getLayout(), managedRepo.getLayout() );
         assertEquals( expectedRepoConfig.getName(), managedRepo.getName() );
-        
-        //TODO enable assert once fixed in AdministrationServiceImpl!
-        //assertEquals( "http://localhost:8080/archiva/repository/" + expectedRepoConfig.getId(), managedRepo.getUrl() );
+
+        // TODO enable assert once fixed in AdministrationServiceImpl!
+        // assertEquals( "http://localhost:8080/archiva/repository/" + expectedRepoConfig.getId(), managedRepo.getUrl()
+        // );
         assertEquals( expectedRepoConfig.isReleases(), managedRepo.isReleases() );
         assertEquals( expectedRepoConfig.isSnapshots(), managedRepo.isSnapshots() );
     }
@@ -848,10 +915,10 @@ public class AdministrationServiceImplTest
         repoConfig.setName( name );
         repoConfig.setReleases( hasReleases );
         repoConfig.setSnapshots( hasSnapshots );
-        
+
         return repoConfig;
     }
-    
+
     private ManagedRepositoryConfiguration createStagingRepo( ManagedRepositoryConfiguration repoConfig )
     {
         ManagedRepositoryConfiguration stagingRepo = new ManagedRepositoryConfiguration();
@@ -861,37 +928,40 @@ public class AdministrationServiceImplTest
         stagingRepo.setReleases( repoConfig.isReleases() );
         stagingRepo.setSnapshots( repoConfig.isSnapshots() );
         stagingRepo.setLocation( repoConfig.getLocation() );
-        
+
         return stagingRepo;
     }
-    
+
     private AuditEvent createAuditEvent( ManagedRepositoryConfiguration repoConfig )
     {
         AuditEvent auditEvent = new AuditEvent();
-        
+
         auditEvent.setAction( AuditEvent.MERGE_REPO_REMOTE );
         auditEvent.setRepositoryId( repoConfig.getId() );
         auditEvent.setResource( repoConfig.getLocation() );
-        auditEvent.setTimestamp( new Date( ) );
-        
+        auditEvent.setTimestamp( new Date() );
+
         return auditEvent;
     }
-    
+
     private void recordRepoConsumers()
     {
         List<KnownRepositoryContentConsumer> availableKnownConsumers = new ArrayList<KnownRepositoryContentConsumer>();
         availableKnownConsumers.add( indexArtifactConsumer );
         availableKnownConsumers.add( indexPomConsumer );
-        
-        List<InvalidRepositoryContentConsumer> availableInvalidConsumers = new ArrayList<InvalidRepositoryContentConsumer>();
+
+        List<InvalidRepositoryContentConsumer> availableInvalidConsumers =
+            new ArrayList<InvalidRepositoryContentConsumer>();
         availableInvalidConsumers.add( checkPomConsumer );
         availableInvalidConsumers.add( checkMetadataConsumer );
-        
-        repoConsumerUtilsControl.expectAndReturn( repoConsumersUtil.getAvailableKnownConsumers(), availableKnownConsumers );
+
+        repoConsumerUtilsControl.expectAndReturn( repoConsumersUtil.getAvailableKnownConsumers(),
+                                                  availableKnownConsumers );
         knownContentConsumerControl.expectAndReturn( indexArtifactConsumer.getId(), "index-artifact" );
         knownContentConsumerControl.expectAndReturn( indexPomConsumer.getId(), "index-pom" );
-        
-        repoConsumerUtilsControl.expectAndReturn( repoConsumersUtil.getAvailableInvalidConsumers(), availableInvalidConsumers );
+
+        repoConsumerUtilsControl.expectAndReturn( repoConsumersUtil.getAvailableInvalidConsumers(),
+                                                  availableInvalidConsumers );
         invalidContentConsumerControl.expectAndReturn( checkPomConsumer.getId(), "check-pom" );
         invalidContentConsumerControl.expectAndReturn( checkMetadataConsumer.getId(), "check-metadata" );
     }
@@ -900,13 +970,13 @@ public class AdministrationServiceImplTest
                                                    MockControl pathParserControl, PathParser parser )
         throws LayoutException
     {
-               String sep = File.separator;
-               String ad10p = "org.apache.archiva" + sep + "poms" + sep + "archiva-diff-1.0.pom";
-               String at10p = "org.apache.archiva" + sep + "poms" + sep + "archiva-test-1.0.pom";
-               String at11p = "org.apache.archiva" + sep + "poms" + sep + "archiva-test-1.1.pom";
-               String ad10j = "org.apache.archiva" + sep + "jars" + sep + "archiva-diff-1.0.jar";
-               String at10j = "org.apache.archiva" + sep + "jars" + sep + "archiva-test-1.0.jar";
-               String at11j = "org.apache.archiva" + sep + "jars" + sep + "archiva-test-1.1.jar";
+        String sep = File.separator;
+        String ad10p = "org.apache.archiva" + sep + "poms" + sep + "archiva-diff-1.0.pom";
+        String at10p = "org.apache.archiva" + sep + "poms" + sep + "archiva-test-1.0.pom";
+        String at11p = "org.apache.archiva" + sep + "poms" + sep + "archiva-test-1.1.pom";
+        String ad10j = "org.apache.archiva" + sep + "jars" + sep + "archiva-diff-1.0.jar";
+        String at10j = "org.apache.archiva" + sep + "jars" + sep + "archiva-test-1.0.jar";
+        String at11j = "org.apache.archiva" + sep + "jars" + sep + "archiva-test-1.1.jar";
 
         fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( at10p ), true );
         fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( at11p ), true );
@@ -914,30 +984,30 @@ public class AdministrationServiceImplTest
         fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( ad10j ), true );
         fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( at10j ), true );
         fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( at11j ), true );
-        
-        ArtifactReference aRef = createArtifactReference("archiva-test", "org.apache.archiva", "1.1", "pom");
+
+        ArtifactReference aRef = createArtifactReference( "archiva-test", "org.apache.archiva", "1.1", "pom" );
         pathParserControl.expectAndReturn( parser.toArtifactReference( at11p ), aRef );
-        
-        aRef = createArtifactReference("archiva-test", "org.apache.archiva", "1.0", "pom");                
+
+        aRef = createArtifactReference( "archiva-test", "org.apache.archiva", "1.0", "pom" );
         pathParserControl.expectAndReturn( parser.toArtifactReference( at10p ), aRef );
-        
-        aRef = createArtifactReference("archiva-diff", "org.apache.archiva", "1.0", "pom");
+
+        aRef = createArtifactReference( "archiva-diff", "org.apache.archiva", "1.0", "pom" );
         pathParserControl.expectAndReturn( parser.toArtifactReference( ad10p ), aRef );
-        
-        aRef = createArtifactReference("archiva-diff", "org.apache.archiva", "1.0", "jar");                
+
+        aRef = createArtifactReference( "archiva-diff", "org.apache.archiva", "1.0", "jar" );
         pathParserControl.expectAndReturn( parser.toArtifactReference( ad10j ), aRef );
-        
-        aRef = createArtifactReference("archiva-test", "org.apache.archiva", "1.0", "jar");
+
+        aRef = createArtifactReference( "archiva-test", "org.apache.archiva", "1.0", "jar" );
         pathParserControl.expectAndReturn( parser.toArtifactReference( at10j ), aRef );
-        
-        aRef = createArtifactReference("archiva-test", "org.apache.archiva", "1.1", "jar");
+
+        aRef = createArtifactReference( "archiva-test", "org.apache.archiva", "1.1", "jar" );
         pathParserControl.expectAndReturn( parser.toArtifactReference( at11j ), aRef );
     }
-    
+
     private List<ArtifactMetadata> getArtifacts()
     {
         List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>();
-        
+
         ArtifactMetadata artifact = new ArtifactMetadata();
         artifact.setId( "archiva-test-1.0.jar" );
         artifact.setProject( "archiva-test" );
@@ -956,7 +1026,15 @@ public class AdministrationServiceImplTest
         aRef.setGroupId( groupId );
         aRef.setType( type );
         aRef.setVersion( version );
-        
+
         return aRef;
     }
+
+    private RepositoryGroupConfiguration createRepoGroupConfig( String id, List<String> repositories )
+    {
+        RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
+        repoGroup.setId( id );
+        repoGroup.setRepositories( repositories );
+        return repoGroup;
+    }
 }