aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-web/archiva-xmlrpc
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2011-09-02 08:18:38 +0000
committerOlivier Lamy <olamy@apache.org>2011-09-02 08:18:38 +0000
commit75f7fab6d40a5afb86620f567f585694a87a7100 (patch)
treeeb57f6d4739e31e6155d6c59d0a6e877864bde99 /archiva-modules/archiva-web/archiva-xmlrpc
parent56587c1e6dba06f0c29646440db87077a5155ce5 (diff)
downloadarchiva-75f7fab6d40a5afb86620f567f585694a87a7100.tar.gz
archiva-75f7fab6d40a5afb86620f567f585694a87a7100.zip
[MRM-1509] change xmlrpc to use new repository administration management api
use new api for ManagedRepository git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1164392 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-web/archiva-xmlrpc')
-rw-r--r--archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/pom.xml4
-rw-r--r--archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/AdministrationService.java63
-rw-r--r--archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml4
-rw-r--r--archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java172
-rw-r--r--archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java50
5 files changed, 127 insertions, 166 deletions
diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/pom.xml b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/pom.xml
index b1bcf198d..8dce1e56d 100644
--- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/pom.xml
+++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/pom.xml
@@ -36,6 +36,10 @@
<artifactId>stage-repository-merge</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.archiva</groupId>
+ <artifactId>archiva-repository-admin</artifactId>
+ </dependency>
+ <dependency>
<groupId>com.atlassian.xmlrpc</groupId>
<artifactId>atlassian-xmlrpc-binder-annotations</artifactId>
</dependency>
diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/AdministrationService.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/AdministrationService.java
index 78e90b24c..f7640c29e 100644
--- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/AdministrationService.java
+++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/AdministrationService.java
@@ -19,75 +19,78 @@ package org.apache.archiva.web.xmlrpc.api;
* under the License.
*/
-import java.util.List;
-
import com.atlassian.xmlrpc.ServiceObject;
+import org.apache.archiva.admin.repository.RepositoryAdminException;
import org.apache.archiva.web.xmlrpc.api.beans.ManagedRepository;
import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository;
+import java.util.List;
+
@ServiceObject( "AdministrationService" )
public interface AdministrationService
{
/**
* Executes repository scanner on the given repository.
- *
+ *
* @param repoId id of the repository to be scanned
* @return
* @throws Exception
*/
- public Boolean executeRepositoryScanner( String repoId )
+ Boolean executeRepositoryScanner( String repoId )
throws Exception;
/**
* Gets all available repository consumers.
- *
+ *
* @return
*/
- public List<String> getAllRepositoryConsumers();
+ List<String> getAllRepositoryConsumers();
// TODO should we already implement config of consumers per repository?
+
/**
* Configures (enable or disable) repository consumer.
- *
+ *
* @param repoId
* @param consumerId
* @param enable
* @return
* @throws Exception
*/
- public Boolean configureRepositoryConsumer( String repoId, String consumerId, boolean enable )
+ Boolean configureRepositoryConsumer( String repoId, String consumerId, boolean enable )
throws Exception;
/**
* Gets all managed repositories.
- *
+ *
* @return
*/
- public List<ManagedRepository> getAllManagedRepositories();
+ List<ManagedRepository> getAllManagedRepositories()
+ throws RepositoryAdminException;
/**
* Gets all remote repositories.
- *
+ *
* @return
*/
- public List<RemoteRepository> getAllRemoteRepositories();
+ List<RemoteRepository> getAllRemoteRepositories();
/**
* Deletes given artifact from the specified repository.
- *
- * @param repoId id of the repository where the artifact to be deleted resides
- * @param groupId groupId of the artifact to be deleted
+ *
+ * @param repoId id of the repository where the artifact to be deleted resides
+ * @param groupId groupId of the artifact to be deleted
* @param artifactId artifactId of the artifact to be deleted
- * @param version version of the artifact to be deleted
+ * @param version version of the artifact to be deleted
* @return
* @throws Exception
*/
- public Boolean deleteArtifact( String repoId, String groupId, String artifactId, String version )
+ Boolean deleteArtifact( String repoId, String groupId, String artifactId, String version )
throws Exception;
/**
* Create a new managed repository with the given parameters.
- *
+ *
* @param repoId
* @param layout
* @param name
@@ -99,37 +102,39 @@ public interface AdministrationService
* @return
* @throws Exception
*/
- public Boolean addManagedRepository( String repoId, String layout, String name, String location,
- boolean blockRedeployments, boolean releasesIncluded,
- boolean snapshotsIncluded, boolean stageRepoNeeded, String cronExpression )
+ Boolean addManagedRepository( String repoId, String layout, String name, String location,
+ boolean blockRedeployments, boolean releasesIncluded, boolean snapshotsIncluded,
+ boolean stageRepoNeeded, String cronExpression )
throws Exception;
/**
* Deletes a managed repository with the given repository id.
- *
+ *
* @param repoId
* @return
*/
- public Boolean deleteManagedRepository( String repoId )
+ Boolean deleteManagedRepository( String repoId )
throws Exception;
/**
* Deletes a managed repository content with the given repository id
- *
+ *
* @param repoId
* @return
* @throws Exception
*/
- public Boolean deleteManagedRepositoryContent( String repoId )
+ Boolean deleteManagedRepositoryContent( String repoId )
throws Exception;
/**
* Get a managed repository with the given repository id.
+ *
* @param repoId
* @return
* @throws Exception
*/
- public ManagedRepository getManagedRepository(String repoId) throws Exception;
+ ManagedRepository getManagedRepository( String repoId )
+ throws Exception;
// TODO
// consider the following as additional services:
// - getAllConfiguredRepositoryConsumers( String repoId ) - list all enabled consumers for the repo
@@ -137,11 +142,13 @@ public interface AdministrationService
/**
* Merge staging repository with the managed repository and skips if there are conflicts
+ *
* @param repoId
* @param skipConflicts
* @return
* @throws Exception
*/
- public boolean merge( String repoId, boolean skipConflicts ) throws Exception;
-
+ boolean merge( String repoId, boolean skipConflicts )
+ throws Exception;
+
}
diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml
index bfb1f9108..e6597f845 100644
--- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml
+++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml
@@ -41,6 +41,10 @@
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
+ <artifactId>archiva-repository-admin</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.archiva</groupId>
<artifactId>archiva-xmlrpc-security</artifactId>
</dependency>
<dependency>
diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java
index b6f4b9da0..f7eadc19c 100644
--- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java
+++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java
@@ -19,6 +19,9 @@ package org.apache.archiva.web.xmlrpc.services;
* under the License.
*/
+import org.apache.archiva.admin.AuditInformation;
+import org.apache.archiva.admin.repository.RepositoryAdminException;
+import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin;
import org.apache.archiva.audit.AuditEvent;
import org.apache.archiva.audit.AuditListener;
import org.apache.archiva.metadata.model.ArtifactMetadata;
@@ -38,7 +41,6 @@ import org.apache.archiva.web.xmlrpc.api.beans.ManagedRepository;
import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
-import org.apache.commons.validator.GenericValidator;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
@@ -54,9 +56,7 @@ import org.apache.maven.archiva.repository.ManagedRepositoryContent;
import org.apache.maven.archiva.repository.RepositoryContentFactory;
import org.apache.maven.archiva.repository.RepositoryException;
import org.apache.maven.archiva.repository.RepositoryNotFoundException;
-import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryException;
-import org.codehaus.redback.components.scheduler.CronExpressionValidator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -98,7 +98,7 @@ public class AdministrationServiceImpl
private RepositorySessionFactory repositorySessionFactory;
- private Registry registry;
+ private ManagedRepositoryAdmin managedRepositoryAdmin;
private static final String REPOSITORY_ID_VALID_EXPRESSION = "^[a-zA-Z0-9._-]+$";
@@ -113,7 +113,7 @@ public class AdministrationServiceImpl
Collection<RepositoryListener> listeners,
RepositoryStatisticsManager repositoryStatisticsManager,
RepositoryMerger repositoryMerger, AuditListener auditListener,
- Registry registry )
+ ManagedRepositoryAdmin managedRepositoryAdmin )
{
this.archivaConfiguration = archivaConfig;
this.repoConsumersUtil = repoConsumersUtil;
@@ -124,7 +124,7 @@ public class AdministrationServiceImpl
this.repositoryStatisticsManager = repositoryStatisticsManager;
this.repositoryMerger = repositoryMerger;
this.auditListener = auditListener;
- this.registry = registry;
+ this.managedRepositoryAdmin = managedRepositoryAdmin;
}
/**
@@ -214,8 +214,8 @@ public class AdministrationServiceImpl
repoContent.deleteVersion( ref );
MetadataRepository metadataRepository = repositorySession.getRepository();
- Collection<ArtifactMetadata> artifacts = metadataRepository.getArtifacts( repoId, groupId, artifactId,
- version );
+ Collection<ArtifactMetadata> artifacts =
+ metadataRepository.getArtifacts( repoId, groupId, artifactId, version );
for ( ArtifactMetadata artifact : artifacts )
{
@@ -307,18 +307,15 @@ public class AdministrationServiceImpl
* @see AdministrationService#getAllManagedRepositories()
*/
public List<ManagedRepository> getAllManagedRepositories()
+ throws RepositoryAdminException
{
List<ManagedRepository> managedRepos = new ArrayList<ManagedRepository>();
- Configuration config = archivaConfiguration.getConfiguration();
- List<ManagedRepositoryConfiguration> managedRepoConfigs = config.getManagedRepositories();
-
- for ( ManagedRepositoryConfiguration repoConfig : managedRepoConfigs )
+ for ( org.apache.archiva.admin.repository.managed.ManagedRepository repoConfig : managedRepositoryAdmin.getManagedRepositories() )
{
- // TODO fix resolution of repo url!
- ManagedRepository repo = new ManagedRepository( repoConfig.getId(), repoConfig.getName(), "URL",
- repoConfig.getLayout(), repoConfig.isSnapshots(),
- repoConfig.isReleases() );
+ ManagedRepository repo =
+ new ManagedRepository( repoConfig.getId(), repoConfig.getName(), repoConfig.getLocation(),
+ repoConfig.getLayout(), repoConfig.isSnapshots(), repoConfig.isReleases() );
managedRepos.add( repo );
}
@@ -368,89 +365,12 @@ public class AdministrationServiceImpl
throws Exception
{
- Configuration config = archivaConfiguration.getConfiguration();
-
- CronExpressionValidator validator = new CronExpressionValidator();
-
- if ( config.getManagedRepositoriesAsMap().containsKey( repoId ) )
- {
- throw new Exception( "Unable to add new repository with id [" + repoId +
- "], that id already exists as a managed repository." );
- }
- else if ( config.getRemoteRepositoriesAsMap().containsKey( repoId ) )
- {
- throw new Exception( "Unable to add new repository with id [" + repoId +
- "], that id already exists as a remote repository." );
- }
- else if ( config.getRepositoryGroupsAsMap().containsKey( repoId ) )
- {
- throw new Exception( "Unable to add new repository with id [" + repoId +
- "], that id already exists as a repository group." );
- }
-
- if ( !validator.validate( cronExpression ) )
- {
- throw new Exception( "Invalid cron expression." );
- }
-
- if( !GenericValidator.matchRegexp( repoId, REPOSITORY_ID_VALID_EXPRESSION ) )
- {
- throw new Exception( "Invalid repository ID. Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)." );
- }
-
- if( !GenericValidator.matchRegexp( name, REPOSITORY_NAME_VALID_EXPRESSION ) )
- {
- throw new Exception( "Invalid repository name. Repository Name must only contain alphanumeric characters, white-spaces(' '), " +
- "forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-)." );
- }
-
- String repoLocation = removeExpressions( location );
-
- if( !GenericValidator.matchRegexp( repoLocation, REPOSITORY_LOCATION_VALID_EXPRESSION ) )
- {
- throw new Exception( "Invalid repository location. Directory must only contain alphanumeric characters, equals(=), question-marks(?), " +
- "exclamation-points(!), ampersands(&amp;), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
- }
-
- ManagedRepositoryConfiguration repository = new ManagedRepositoryConfiguration();
+ org.apache.archiva.admin.repository.managed.ManagedRepository repository =
+ new org.apache.archiva.admin.repository.managed.ManagedRepository( repoId, name, location, layout,
+ snapshotsIncluded, releasesIncluded,
+ blockRedeployments, cronExpression );
+ return managedRepositoryAdmin.addManagedRepository( repository, stageRepoNeeded, getAuditInformation() );
- repository.setId( repoId );
- repository.setBlockRedeployments( blockRedeployments );
- repository.setReleases( releasesIncluded );
- repository.setSnapshots( snapshotsIncluded );
- repository.setName( name );
- repository.setLocation( repoLocation );
- repository.setLayout( layout );
- repository.setRefreshCronExpression( cronExpression );
-
- addRepository( repository, config );
-
- if ( stageRepoNeeded )
- {
- ManagedRepositoryConfiguration stagingRepository = getStageRepoConfig( repository );
- addRepository( stagingRepository, config );
- }
-
- saveConfiguration( config );
-
- //MRM-1342 Repository statistics report doesn't appear to be working correctly
- //scan repository when adding of repository is successful
- try
- {
- executeRepositoryScanner( repoId );
- if ( stageRepoNeeded )
- {
- ManagedRepositoryConfiguration stagingRepository = getStageRepoConfig( repository );
- executeRepositoryScanner( stagingRepository.getId() );
- }
- }
- catch ( Exception e )
- {
- log.warn( new StringBuilder( "Unable to scan repository [" ).append( repoId ).append( "]: " ).append(
- e.getMessage() ).toString(), e );
- }
-
- return Boolean.TRUE;
}
public Boolean deleteManagedRepository( String repoId )
@@ -608,16 +528,16 @@ public class AdministrationServiceImpl
log.info( "Repository to be merged contains releases only.." );
if ( skipConflicts )
{
- List<ArtifactMetadata> conflicts = repositoryMerger.getConflictingArtifacts(
- metadataRepository, repoId, stagingId );
+ List<ArtifactMetadata> conflicts =
+ repositoryMerger.getConflictingArtifacts( metadataRepository, repoId, stagingId );
if ( log.isDebugEnabled() )
{
log.debug( "Artifacts in conflict.." );
for ( ArtifactMetadata metadata : conflicts )
{
- log.debug( metadata.getNamespace() + ":" + metadata.getProject() + ":" +
- metadata.getProjectVersion() );
+ log.debug( metadata.getNamespace() + ":" + metadata.getProject() + ":"
+ + metadata.getProjectVersion() );
}
}
@@ -637,16 +557,16 @@ public class AdministrationServiceImpl
log.info( "Repository to be merged has snapshot artifacts.." );
if ( skipConflicts )
{
- List<ArtifactMetadata> conflicts = repositoryMerger.getConflictingArtifacts(
- metadataRepository, repoId, stagingId );
+ List<ArtifactMetadata> conflicts =
+ repositoryMerger.getConflictingArtifacts( metadataRepository, repoId, stagingId );
if ( log.isDebugEnabled() )
{
log.debug( "Artifacts in conflict.." );
for ( ArtifactMetadata metadata : conflicts )
{
- log.debug( metadata.getNamespace() + ":" + metadata.getProject() + ":" +
- metadata.getProjectVersion() );
+ log.debug( metadata.getNamespace() + ":" + metadata.getProject() + ":"
+ + metadata.getProjectVersion() );
}
}
@@ -654,19 +574,19 @@ public class AdministrationServiceImpl
log.debug( "Source artifacts size :: " + sourceArtifacts.size() );
- Filter<ArtifactMetadata> artifactsWithOutConflicts = new IncludesFilter<ArtifactMetadata>(
- sourceArtifacts );
+ Filter<ArtifactMetadata> artifactsWithOutConflicts =
+ new IncludesFilter<ArtifactMetadata>( sourceArtifacts );
repositoryMerger.merge( metadataRepository, stagingId, repoId, artifactsWithOutConflicts );
- log.info( "Staging repository '" + stagingId + "' merged successfully with managed repo '" +
- repoId + "'." );
+ log.info( "Staging repository '" + stagingId + "' merged successfully with managed repo '"
+ + repoId + "'." );
}
else
{
repositoryMerger.merge( metadataRepository, stagingId, repoId );
- log.info( "Staging repository '" + stagingId + "' merged successfully with managed repo '" +
- repoId + "'." );
+ log.info( "Staging repository '" + stagingId + "' merged successfully with managed repo '"
+ + repoId + "'." );
}
}
}
@@ -705,25 +625,6 @@ public class AdministrationServiceImpl
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 )
{
@@ -779,12 +680,9 @@ public class AdministrationServiceImpl
return stagingRepository;
}
- private String removeExpressions( String directory )
+ // FIXME find a way to get user id and adress
+ private AuditInformation getAuditInformation()
{
- String value = StringUtils.replace( directory, "${appserver.base}", registry.getString( "appserver.base",
- "${appserver.base}" ) );
- value = StringUtils.replace( value, "${appserver.home}", registry.getString( "appserver.home",
- "${appserver.home}" ) );
- return value;
+ return new AuditInformation( null, null );
}
}
diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java
index 9acec835a..041c431f5 100644
--- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java
+++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java
@@ -20,6 +20,8 @@ package org.apache.archiva.web.xmlrpc.services;
*/
import junit.framework.TestCase;
+import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
+import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin;
import org.apache.archiva.audit.AuditEvent;
import org.apache.archiva.audit.AuditListener;
import org.apache.archiva.metadata.model.ArtifactMetadata;
@@ -53,6 +55,8 @@ import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryConte
import org.apache.maven.archiva.repository.content.ManagedLegacyRepositoryContent;
import org.apache.maven.archiva.repository.content.PathParser;
import org.apache.maven.archiva.repository.layout.LayoutException;
+import org.apache.maven.archiva.security.ArchivaRoleConstants;
+import org.codehaus.plexus.redback.role.RoleManager;
import org.codehaus.plexus.registry.Registry;
import org.easymock.MockControl;
import org.easymock.classextension.MockClassControl;
@@ -65,6 +69,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
@@ -140,12 +145,18 @@ public class AdministrationServiceImplTest
private AuditListener auditListener;
+ private MockControl roleManagerControl;
+
+ private RoleManager roleManager;
+
private MockControl registryControl;
private Registry registry;
private static final String STAGE = "-stage";
+ private DefaultManagedRepositoryAdmin managedRepositoryAdmin;
+
@Before
public void setUp()
throws Exception
@@ -189,6 +200,9 @@ public class AdministrationServiceImplTest
listenerControl = MockControl.createControl( RepositoryListener.class );
listener = (RepositoryListener) listenerControl.getMock();
+ roleManagerControl = MockControl.createControl( RoleManager.class );
+ roleManager = (RoleManager) roleManagerControl.getMock();
+
repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class );
repositoryStatisticsManager = (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock();
@@ -201,10 +215,20 @@ public class AdministrationServiceImplTest
registryControl = MockControl.createControl( Registry.class );
registry = (Registry) registryControl.getMock();
+
+ managedRepositoryAdmin = new DefaultManagedRepositoryAdmin();
+ managedRepositoryAdmin.setArchivaConfiguration( archivaConfig );
+ managedRepositoryAdmin.setRegistry( registry );
+ managedRepositoryAdmin.setRepositoryStatisticsManager( repositoryStatisticsManager );
+ managedRepositoryAdmin.setRepositoryTaskScheduler( repositoryTaskScheduler );
+ managedRepositoryAdmin.setRepositorySessionFactory( repositorySessionFactory );
+ managedRepositoryAdmin.setAuditListeners( Arrays.asList( auditListener ) );
+ managedRepositoryAdmin.setRoleManager( roleManager );
+
service = new AdministrationServiceImpl( archivaConfig, repoConsumersUtil, repositoryFactory,
repositorySessionFactory, repositoryTaskScheduler,
Collections.singletonList( listener ), repositoryStatisticsManager,
- repositoryMerger, auditListener, registry );
+ repositoryMerger, auditListener, managedRepositoryAdmin );
}
/* Tests for repository consumers */
@@ -948,6 +972,27 @@ public class AdministrationServiceImplTest
configControl.expectAndReturn( config.getManagedRepositoriesAsMap(), managedRepoMap );
configControl.expectAndReturn( config.getRemoteRepositoriesAsMap(), remoteRepoMap );
configControl.expectAndReturn( config.getRepositoryGroupsAsMap(), repoGroupMap );
+
+ roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
+ roleManagerControl.setReturnValue( false );
+ roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
+ roleManagerControl.setVoidCallable();
+ roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
+ roleManagerControl.setReturnValue( false );
+ roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
+ roleManagerControl.setVoidCallable();
+
+ roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId + "-stage" );
+ roleManagerControl.setReturnValue( false );
+ roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId + "-stage" );
+ roleManagerControl.setVoidCallable();
+ roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId + "-stage" );
+ roleManagerControl.setReturnValue( false );
+ roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId + "-stage" );
+ roleManagerControl.setVoidCallable();
+
+ roleManagerControl.replay();
+
registryControl.expectAndReturn( registry.getString( "appserver.base", "${appserver.base}" ), appserverBase );
registryControl.expectAndReturn( registry.getString( "appserver.home", "${appserver.home}" ), appserverBase );
config.addManagedRepository( managedRepo );
@@ -959,6 +1004,9 @@ public class AdministrationServiceImplTest
archivaConfig.save( config );
archivaConfigControl.setVoidCallable();
+
+
+
//managed repo
repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( repoId ), false );