import org.apache.maven.archiva.configuration.DatabaseScanningConfiguration;
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
+import org.apache.maven.archiva.consumers.DatabaseCleanupConsumer;
+import org.apache.maven.archiva.consumers.DatabaseUnprocessedArtifactConsumer;
import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
+import org.apache.maven.archiva.database.updater.DatabaseConsumers;
import org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers;
import org.codehaus.plexus.registry.RegistryException;
+/**
+ * AdministrationServiceImpl
+ *
+ * @version $Id: AdministrationServiceImpl.java
+ */
public class AdministrationServiceImpl
implements AdministrationService
{
*/
private ArchivaConfiguration archivaConfiguration;
- private RepositoryContentConsumers consumerUtil;
+ private RepositoryContentConsumers repoConsumersUtil;
+
+ private DatabaseConsumers dbConsumersUtil;
+ /**
+ * @see AdministrationService#configureDatabaseConsumer(String, boolean)
+ */
public boolean configureDatabaseConsumer( String consumerId, boolean enable ) throws Exception
{
- //Configuration config = archivaConfiguration.getConfiguration();
-
- // TODO Auto-generated method stub
- return false;
+ List<DatabaseCleanupConsumer> cleanupConsumers = dbConsumersUtil.getAvailableCleanupConsumers();
+ List<DatabaseUnprocessedArtifactConsumer> unprocessedConsumers =
+ dbConsumersUtil.getAvailableUnprocessedConsumers();
+
+ boolean found = false;
+ boolean isCleanupConsumer = false;
+ for( DatabaseCleanupConsumer consumer : cleanupConsumers )
+ {
+ if( consumer.getId().equals( consumerId ) )
+ {
+ found = true;
+ isCleanupConsumer = true;
+ break;
+ }
+ }
+
+ if( !found )
+ {
+ for( DatabaseUnprocessedArtifactConsumer consumer : unprocessedConsumers )
+ {
+ if( consumer.getId().equals( consumerId ) )
+ {
+ found = true;
+ break;
+ }
+ }
+ }
+
+ if( !found )
+ {
+ throw new Exception( "Invalid database consumer." );
+ }
+
+ Configuration config = archivaConfiguration.getConfiguration();
+ DatabaseScanningConfiguration dbScanningConfig = config.getDatabaseScanning();
+
+ if( isCleanupConsumer )
+ {
+ dbScanningConfig.addCleanupConsumer( consumerId );
+ }
+ else
+ {
+ dbScanningConfig.addUnprocessedConsumer( consumerId );
+ }
+
+ config.setDatabaseScanning( dbScanningConfig );
+ saveConfiguration( config );
+
+ return true;
}
/**
public boolean configureRepositoryConsumer( String repoId, String consumerId, boolean enable )
throws Exception
{
- List<KnownRepositoryContentConsumer> knownConsumers = consumerUtil.getAvailableKnownConsumers();
- List<InvalidRepositoryContentConsumer> invalidConsumers = consumerUtil.getAvailableInvalidConsumers();
+ // TODO use repoId once consumers are configured per repository! (MRM-930)
+
+ List<KnownRepositoryContentConsumer> knownConsumers = repoConsumersUtil.getAvailableKnownConsumers();
+ List<InvalidRepositoryContentConsumer> invalidConsumers = repoConsumersUtil.getAvailableInvalidConsumers();
boolean found = false;
boolean isKnownContentConsumer = false;
return true;
}
+ /**
+ * @see AdministrationService#deleteArtifact(String, String, String, String)
+ */
public boolean deleteArtifact( String repoId, String groupId, String artifactId, String version ) throws Exception
{
// TODO implement delete artifact in Archiva
return false;
}
+ /**
+ * @see AdministrationService#executeDatabaseScanner()
+ */
public boolean executeDatabaseScanner() throws Exception
{
// TODO Auto-generated method stub
return false;
}
+ /**
+ * @see AdministrationService#executeRepositoryScanner(String)
+ */
public boolean executeRepositoryScanner( String repoId ) throws Exception
{
// TODO Auto-generated method stub
{
List<String> consumers = new ArrayList<String>();
+ List<DatabaseCleanupConsumer> cleanupConsumers = dbConsumersUtil.getAvailableCleanupConsumers();
+ List<DatabaseUnprocessedArtifactConsumer> unprocessedConsumers = dbConsumersUtil.getAvailableUnprocessedConsumers();
+
+ for( DatabaseCleanupConsumer consumer : cleanupConsumers )
+ {
+ consumers.add( consumer.getId() );
+ }
+
+ for( DatabaseUnprocessedArtifactConsumer consumer : unprocessedConsumers )
+ {
+ consumers.add( consumer.getId() );
+ }
+
return consumers;
}
{
List<String> consumers = new ArrayList<String>();
- List<KnownRepositoryContentConsumer> knownConsumers = consumerUtil.getAvailableKnownConsumers();
- List<InvalidRepositoryContentConsumer> invalidConsumers = consumerUtil.getAvailableInvalidConsumers();
+ List<KnownRepositoryContentConsumer> knownConsumers = repoConsumersUtil.getAvailableKnownConsumers();
+ List<InvalidRepositoryContentConsumer> invalidConsumers = repoConsumersUtil.getAvailableInvalidConsumers();
for( KnownRepositoryContentConsumer consumer : knownConsumers )
{
return consumers;
}
+ /**
+ * @see AdministrationService#getAllManagedRepositories()
+ */
public List<ManagedRepository> getAllManagedRepositories()
{
return null;
}
+ /**
+ * @see AdministrationService#getAllRemoteRepositories()
+ */
public List<RemoteRepository> getAllRemoteRepositories()
{
return null;
this.archivaConfiguration = archivaConfiguration;
}
- public RepositoryContentConsumers getConsumerUtil()
- {
- return consumerUtil;
- }
-
- public void setConsumerUtil( RepositoryContentConsumers consumerUtil )
+ public void setRepoConsumersUtil( RepositoryContentConsumers consumerUtil )
{
- this.consumerUtil = consumerUtil;
+ this.repoConsumersUtil = consumerUtil;
}
+
+ public void setDbConsumersUtil( DatabaseConsumers consumerUtil )
+ {
+ this.dbConsumersUtil = consumerUtil;
+ }
}
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
+import org.apache.maven.archiva.consumers.DatabaseCleanupConsumer;
+import org.apache.maven.archiva.consumers.DatabaseUnprocessedArtifactConsumer;
import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
+import org.apache.maven.archiva.database.updater.DatabaseConsumers;
import org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers;
import org.apache.maven.archiva.scheduled.ArchivaTaskScheduler;
import org.apache.maven.archiva.scheduled.tasks.DatabaseTask;
import org.easymock.classextension.MockClassControl;
/**
+ * AdministrationServiceImplTest
*
- * @version $Id$
+ * @version $Id: AdministrationServiceImplTest.java
*/
public class AdministrationServiceImplTest
extends PlexusInSpringTestCase
private ArchivaTaskScheduler taskScheduler;
- private MockControl consumerUtilControl;
+ // repository consumers
+ private MockControl repoConsumerUtilsControl;
+
+ private RepositoryContentConsumers repoConsumersUtil;
- private RepositoryContentConsumers consumerUtil;
-
private MockControl knownContentConsumerControl;
private MockControl invalidContentConsumerControl;
private InvalidRepositoryContentConsumer checkPomConsumer;
private InvalidRepositoryContentConsumer checkMetadataConsumer;
+
+ // database consumers
+ private MockControl dbConsumersUtilControl;
+
+ private DatabaseConsumers dbConsumersUtil;
+
+ private MockControl unprocessedConsumersControl;
+
+ private MockControl cleanupConsumersControl;
+
+ private DatabaseUnprocessedArtifactConsumer processArtifactConsumer;
+
+ private DatabaseUnprocessedArtifactConsumer processPomConsumer;
+
+ private DatabaseCleanupConsumer cleanupIndexConsumer;
+
+ private DatabaseCleanupConsumer cleanupDbConsumer;
protected void setUp()
throws Exception
taskSchedulerControl = MockControl.createControl( ArchivaTaskScheduler.class );
taskScheduler = ( ArchivaTaskScheduler ) taskSchedulerControl.getMock();
- consumerUtilControl = MockClassControl.createControl( RepositoryContentConsumers.class );
- consumerUtil = ( RepositoryContentConsumers ) consumerUtilControl.getMock();
+ // repo consumers
+ repoConsumerUtilsControl = MockClassControl.createControl( RepositoryContentConsumers.class );
+ repoConsumersUtil = ( RepositoryContentConsumers ) repoConsumerUtilsControl.getMock();
knownContentConsumerControl = MockControl.createControl( KnownRepositoryContentConsumer.class );
indexArtifactConsumer = ( KnownRepositoryContentConsumer ) knownContentConsumerControl.getMock();
checkPomConsumer = ( InvalidRepositoryContentConsumer ) invalidContentConsumerControl.getMock();
checkMetadataConsumer = ( InvalidRepositoryContentConsumer ) invalidContentConsumerControl.getMock();
+ // db consumers
+ dbConsumersUtilControl = MockClassControl.createControl( DatabaseConsumers.class );
+ dbConsumersUtil = ( DatabaseConsumers ) dbConsumersUtilControl.getMock();
+
+ cleanupConsumersControl = MockControl.createControl( DatabaseCleanupConsumer.class );
+ cleanupIndexConsumer = ( DatabaseCleanupConsumer ) cleanupConsumersControl.getMock();
+ cleanupDbConsumer = ( DatabaseCleanupConsumer ) cleanupConsumersControl.getMock();
+
+ unprocessedConsumersControl = MockControl.createControl( DatabaseUnprocessedArtifactConsumer.class );
+ processArtifactConsumer = ( DatabaseUnprocessedArtifactConsumer ) unprocessedConsumersControl.getMock();
+ processPomConsumer = ( DatabaseUnprocessedArtifactConsumer ) unprocessedConsumersControl.getMock();
+
service = new AdministrationServiceImpl();
service.setArchivaConfiguration( archivaConfig );
- service.setConsumerUtil( consumerUtil );
+ service.setRepoConsumersUtil( repoConsumersUtil );
+ service.setDbConsumersUtil( dbConsumersUtil );
}
-
- // DATABASE CONSUMERS
- /* public void testGetAllDbConsumers()
+
+/* Tests for database consumers */
+
+ public void testGetAllDbConsumers()
throws Exception
{
- DatabaseScanningConfiguration dbScanning = new DatabaseScanningConfiguration();
- dbScanning.addCleanupConsumer( "cleanup-index" );
- dbScanning.addCleanupConsumer( "cleanup-database" );
- dbScanning.addUnprocessedConsumer( "unprocessed-artifacts" );
- dbScanning.addUnprocessedConsumer( "unprocessed-poms" );
-
- archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
- configControl.expectAndReturn( config.getDatabaseScanning(), dbScanning );
-
- archivaConfigControl.replay();
- configControl.replay();
+ recordDbConsumers();
+ dbConsumersUtilControl.replay();
+ cleanupConsumersControl.replay();
+ unprocessedConsumersControl.replay();
+ List<String> dbConsumers = service.getAllDatabaseConsumers();
- List<String> dbConsumers = service.getAllDatabaseConsumers();
-
- archivaConfigControl.verify();
- configControl.verify();
+ dbConsumersUtilControl.verify();
+ cleanupConsumersControl.verify();
+ unprocessedConsumersControl.verify();
assertNotNull( dbConsumers );
assertEquals( 4, dbConsumers.size() );
assertTrue( dbConsumers.contains( "cleanup-index" ) );
assertTrue( dbConsumers.contains( "cleanup-database" ) );
- assertTrue( dbConsumers.contains( "unprocessed-artifacts" ) );
- assertTrue( dbConsumers.contains( "unprocessed-poms" ) );
+ assertTrue( dbConsumers.contains( "process-artifact" ) );
+ assertTrue( dbConsumers.contains( "process-pom" ) );
}
public void testConfigureValidDatabaseConsumer()
DatabaseScanningConfiguration dbScanning = new DatabaseScanningConfiguration();
dbScanning.addCleanupConsumer( "cleanup-index" );
dbScanning.addCleanupConsumer( "cleanup-database" );
- dbScanning.addUnprocessedConsumer( "unprocessed-artifacts" );
- dbScanning.addUnprocessedConsumer( "unprocessed-poms" );
-
- //TODO mock checking whether the db consumer is valid or not
+ dbScanning.addUnprocessedConsumer( "process-artifact" );
+
+ recordDbConsumers();
- // test enable
+ // test enable "process-pom" db consumer
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.getDatabaseScanning(), dbScanning );
archivaConfig.save( config );
archivaConfigControl.setVoidCallable();
+ dbConsumersUtilControl.replay();
+ cleanupConsumersControl.replay();
+ unprocessedConsumersControl.replay();
archivaConfigControl.replay();
configControl.replay();
try
{
- boolean success = service.configureDatabaseConsumer( "new-cleanup-consumer", true );
+ boolean success = service.configureDatabaseConsumer( "process-pom", true );
assertTrue( success );
}
catch ( Exception e )
fail( "An exception should not have been thrown." );
}
+ dbConsumersUtilControl.verify();
+ cleanupConsumersControl.verify();
+ unprocessedConsumersControl.verify();
archivaConfigControl.verify();
configControl.verify();
- // test disable
+ // test disable "process-pom" db consumer
+ dbConsumersUtilControl.reset();
+ cleanupConsumersControl.reset();
+ unprocessedConsumersControl.reset();
archivaConfigControl.reset();
configControl.reset();
+
+ dbScanning.addUnprocessedConsumer( "process-pom" );
- //TODO mock checking whether the db consumer is valid or not
+ recordDbConsumers();
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.getDatabaseScanning(), dbScanning );
archivaConfig.save( config );
archivaConfigControl.setVoidCallable();
+ dbConsumersUtilControl.replay();
+ cleanupConsumersControl.replay();
+ unprocessedConsumersControl.replay();
archivaConfigControl.replay();
configControl.replay();
try
{
- boolean success = service.configureDatabaseConsumer( "new-cleanup-consumer", false );
+ boolean success = service.configureDatabaseConsumer( "process-pom", false );
assertTrue( success );
}
catch ( Exception e )
fail( "An exception should not have been thrown." );
}
+ dbConsumersUtilControl.verify();
+ cleanupConsumersControl.verify();
+ unprocessedConsumersControl.verify();
archivaConfigControl.verify();
configControl.verify();
}
public void testConfigureInvalidDatabaseConsumer()
throws Exception
{
- //TODO mock checking whether the db consumer is valid or not
+ recordDbConsumers();
+
+ dbConsumersUtilControl.replay();
+ cleanupConsumersControl.replay();
+ unprocessedConsumersControl.replay();
try
{
{
assertEquals( "Invalid database consumer.", e.getMessage() );
}
+
+ dbConsumersUtilControl.verify();
+ cleanupConsumersControl.verify();
+ unprocessedConsumersControl.verify();
}
+
+/* Tests for repository consumers */
- */
-
- // REPOSITORY CONSUMERS
public void testGetAllRepoConsumers()
throws Exception
{
- recordRepoConsumerValidation();
+ recordRepoConsumers();
- consumerUtilControl.replay();
+ repoConsumerUtilsControl.replay();
knownContentConsumerControl.replay();
invalidContentConsumerControl.replay();
List<String> repoConsumers = service.getAllRepositoryConsumers();
- consumerUtilControl.verify();
+ repoConsumerUtilsControl.verify();
knownContentConsumerControl.verify();
invalidContentConsumerControl.verify();
repoScanning.addInvalidContentConsumer( "check-pom" );
// test enable "check-metadata" consumer
- recordRepoConsumerValidation();
+ recordRepoConsumers();
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.getRepositoryScanning(), repoScanning );
archivaConfig.save( config );
archivaConfigControl.setVoidCallable();
- consumerUtilControl.replay();
+ repoConsumerUtilsControl.replay();
knownContentConsumerControl.replay();
invalidContentConsumerControl.replay();
archivaConfigControl.replay();
fail( "An exception should not have been thrown." );
}
- consumerUtilControl.verify();
+ repoConsumerUtilsControl.verify();
knownContentConsumerControl.verify();
invalidContentConsumerControl.verify();
archivaConfigControl.verify();
configControl.verify();
// test disable "check-metadata" consumer
- consumerUtilControl.reset();
+ repoConsumerUtilsControl.reset();
knownContentConsumerControl.reset();
invalidContentConsumerControl.reset();
archivaConfigControl.reset();
repoScanning.addInvalidContentConsumer( "check-metadata" );
- recordRepoConsumerValidation();
+ recordRepoConsumers();
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.getRepositoryScanning(), repoScanning );
archivaConfig.save( config );
archivaConfigControl.setVoidCallable();
- consumerUtilControl.replay();
+ repoConsumerUtilsControl.replay();
knownContentConsumerControl.replay();
invalidContentConsumerControl.replay();
archivaConfigControl.replay();
{
boolean success = service.configureRepositoryConsumer( null, "check-metadata", false );
- consumerUtilControl.verify();
+ repoConsumerUtilsControl.verify();
knownContentConsumerControl.verify();
invalidContentConsumerControl.verify();
archivaConfigControl.verify();
}
}
- /*
+
public void testConfigureInvalidRepositoryConsumer()
throws Exception
{
- //TODO mock checking whether the repo consumer is valid or not
+ recordRepoConsumers();
+
+ repoConsumerUtilsControl.replay();
+ knownContentConsumerControl.replay();
+ invalidContentConsumerControl.replay();
try
{
{
assertEquals( "Invalid repository consumer.", e.getMessage() );
}
+
+ repoConsumerUtilsControl.verify();
+ knownContentConsumerControl.verify();
+ invalidContentConsumerControl.verify();
}
-// DELETE ARTIFACT
+/* Tests for delete artifact */
- public void testDeleteArtifactArtifactExists()
+ /* public void testDeleteArtifactArtifactExists()
throws Exception
{
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
return repoConfig;
}
- private void recordRepoConsumerValidation()
+ private void recordRepoConsumers()
{
List<KnownRepositoryContentConsumer> availableKnownConsumers = new ArrayList<KnownRepositoryContentConsumer>();
availableKnownConsumers.add( indexArtifactConsumer );
availableInvalidConsumers.add( checkPomConsumer );
availableInvalidConsumers.add( checkMetadataConsumer );
- consumerUtilControl.expectAndReturn( consumerUtil.getAvailableKnownConsumers(), availableKnownConsumers );
+ repoConsumerUtilsControl.expectAndReturn( repoConsumersUtil.getAvailableKnownConsumers(), availableKnownConsumers );
knownContentConsumerControl.expectAndReturn( indexArtifactConsumer.getId(), "index-artifact" );
knownContentConsumerControl.expectAndReturn( indexPomConsumer.getId(), "index-pom" );
- consumerUtilControl.expectAndReturn( consumerUtil.getAvailableInvalidConsumers(), availableInvalidConsumers );
+ repoConsumerUtilsControl.expectAndReturn( repoConsumersUtil.getAvailableInvalidConsumers(), availableInvalidConsumers );
invalidContentConsumerControl.expectAndReturn( checkPomConsumer.getId(), "check-pom" );
invalidContentConsumerControl.expectAndReturn( checkMetadataConsumer.getId(), "check-metadata" );
}
+ private void recordDbConsumers()
+ {
+ List<DatabaseCleanupConsumer> cleanupConsumers = new ArrayList<DatabaseCleanupConsumer>();
+ cleanupConsumers.add( cleanupIndexConsumer );
+ cleanupConsumers.add( cleanupDbConsumer );
+
+ List<DatabaseUnprocessedArtifactConsumer> unprocessedConsumers =
+ new ArrayList<DatabaseUnprocessedArtifactConsumer>();
+ unprocessedConsumers.add( processArtifactConsumer );
+ unprocessedConsumers.add( processPomConsumer );
+
+ dbConsumersUtilControl.expectAndReturn( dbConsumersUtil.getAvailableCleanupConsumers(), cleanupConsumers );
+ cleanupConsumersControl.expectAndReturn( cleanupIndexConsumer.getId(), "cleanup-index" );
+ cleanupConsumersControl.expectAndReturn( cleanupDbConsumer.getId(), "cleanup-database" );
+
+ dbConsumersUtilControl.expectAndReturn( dbConsumersUtil.getAvailableUnprocessedConsumers(), unprocessedConsumers );
+ unprocessedConsumersControl.expectAndReturn( processArtifactConsumer.getId(), "process-artifact" );
+ unprocessedConsumersControl.expectAndReturn( processPomConsumer.getId(), "process-pom" );
+ }
}
\ No newline at end of file