* under the License.
*/
+import java.util.ArrayList;
import java.util.List;
import org.apache.archiva.web.xmlrpc.api.AdministrationService;
import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
+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.InvalidRepositoryContentConsumer;
+import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
+import org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers;
+import org.codehaus.plexus.registry.RegistryException;
public class AdministrationServiceImpl
implements AdministrationService
*/
private ArchivaConfiguration archivaConfiguration;
+ private RepositoryContentConsumers consumerUtil;
+
public boolean configureDatabaseConsumer( String consumerId, boolean enable ) throws Exception
{
//Configuration config = archivaConfiguration.getConfiguration();
-
-
+
// TODO Auto-generated method stub
return false;
}
- public boolean configureRepositoryConsumer( String repoId, String consumerId, boolean enable ) throws Exception
+ /**
+ * @see AdministrationService#configureRepositoryConsumer(String, String, boolean)
+ */
+ public boolean configureRepositoryConsumer( String repoId, String consumerId, boolean enable )
+ throws Exception
{
- // TODO Auto-generated method stub
- return false;
+ List<KnownRepositoryContentConsumer> knownConsumers = consumerUtil.getAvailableKnownConsumers();
+ List<InvalidRepositoryContentConsumer> invalidConsumers = consumerUtil.getAvailableInvalidConsumers();
+
+ boolean found = false;
+ boolean isKnownContentConsumer = false;
+ for( KnownRepositoryContentConsumer consumer : knownConsumers )
+ {
+ if( consumer.getId().equals( consumerId ) )
+ {
+ found = true;
+ isKnownContentConsumer = true;
+ break;
+ }
+ }
+
+ if( !found )
+ {
+ for( InvalidRepositoryContentConsumer consumer : invalidConsumers )
+ {
+ if( consumer.getId().equals( consumerId ) )
+ {
+ found = true;
+ break;
+ }
+ }
+ }
+
+ if( !found )
+ {
+ throw new Exception( "Invalid repository consumer." );
+ }
+
+ Configuration config = archivaConfiguration.getConfiguration();
+ RepositoryScanningConfiguration repoScanningConfig = config.getRepositoryScanning();
+
+ if( isKnownContentConsumer )
+ {
+ repoScanningConfig.addKnownContentConsumer( consumerId );
+ }
+ else
+ {
+ repoScanningConfig.addInvalidContentConsumer( consumerId );
+ }
+
+ config.setRepositoryScanning( repoScanningConfig );
+ saveConfiguration( config );
+
+ return true;
}
-
+
public boolean deleteArtifact( String repoId, String groupId, String artifactId, String version ) throws Exception
{
// TODO implement delete artifact in Archiva
return false;
}
+ /**
+ * @see AdministrationService#getAllDatabaseConsumers()
+ */
public List<String> getAllDatabaseConsumers()
{
- // TODO Auto-generated method stub
- return null;
+ List<String> consumers = new ArrayList<String>();
+
+ return consumers;
}
+ /**
+ * @see AdministrationService#getAllRepositoryConsumers()
+ */
public List<String> getAllRepositoryConsumers()
{
- // TODO Auto-generated method stub
- return null;
+ List<String> consumers = new ArrayList<String>();
+
+ List<KnownRepositoryContentConsumer> knownConsumers = consumerUtil.getAvailableKnownConsumers();
+ List<InvalidRepositoryContentConsumer> invalidConsumers = consumerUtil.getAvailableInvalidConsumers();
+
+ for( KnownRepositoryContentConsumer consumer : knownConsumers )
+ {
+ consumers.add( consumer.getId() );
+ }
+
+ for( InvalidRepositoryContentConsumer consumer : invalidConsumers )
+ {
+ consumers.add( consumer.getId() );
+ }
+
+ return consumers;
}
public List<ManagedRepository> getAllManagedRepositories()
{
return null;
}
+
+ private void saveConfiguration( Configuration config )
+ throws Exception
+ {
+ try
+ {
+ archivaConfiguration.save( config );
+ }
+ catch( RegistryException e )
+ {
+ throw new Exception( "Error occurred in the registry." );
+ }
+ catch ( IndeterminateConfigurationException e )
+ {
+ throw new Exception( "Error occurred while saving the configuration." );
+ }
+ }
+
+ public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
+ {
+ this.archivaConfiguration = archivaConfiguration;
+ }
+
+ public RepositoryContentConsumers getConsumerUtil()
+ {
+ return consumerUtil;
+ }
+
+ public void setConsumerUtil( RepositoryContentConsumers consumerUtil )
+ {
+ this.consumerUtil = 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.InvalidRepositoryContentConsumer;
+import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
+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.apache.maven.archiva.scheduled.tasks.RepositoryTask;
private Configuration config;
- private AdministrationService service;
+ private AdministrationServiceImpl service;
private MockControl taskSchedulerControl;
private ArchivaTaskScheduler taskScheduler;
+
+ private MockControl consumerUtilControl;
+
+ private RepositoryContentConsumers consumerUtil;
+
+ private MockControl knownContentConsumerControl;
+
+ private MockControl invalidContentConsumerControl;
+
+ private KnownRepositoryContentConsumer indexArtifactConsumer;
+
+ private KnownRepositoryContentConsumer indexPomConsumer;
+
+ private InvalidRepositoryContentConsumer checkPomConsumer;
+
+ private InvalidRepositoryContentConsumer checkMetadataConsumer;
protected void setUp()
throws Exception
taskSchedulerControl = MockControl.createControl( ArchivaTaskScheduler.class );
taskScheduler = ( ArchivaTaskScheduler ) taskSchedulerControl.getMock();
+ consumerUtilControl = MockClassControl.createControl( RepositoryContentConsumers.class );
+ consumerUtil = ( RepositoryContentConsumers ) consumerUtilControl.getMock();
+
+ knownContentConsumerControl = MockControl.createControl( KnownRepositoryContentConsumer.class );
+ indexArtifactConsumer = ( KnownRepositoryContentConsumer ) knownContentConsumerControl.getMock();
+ indexPomConsumer = ( KnownRepositoryContentConsumer ) knownContentConsumerControl.getMock();
+
+ invalidContentConsumerControl = MockControl.createControl( InvalidRepositoryContentConsumer.class );
+ checkPomConsumer = ( InvalidRepositoryContentConsumer ) invalidContentConsumerControl.getMock();
+ checkMetadataConsumer = ( InvalidRepositoryContentConsumer ) invalidContentConsumerControl.getMock();
+
service = new AdministrationServiceImpl();
+ service.setArchivaConfiguration( archivaConfig );
+ service.setConsumerUtil( consumerUtil );
}
// DATABASE CONSUMERS
- public void testGetAllDbConsumers()
+ /* public void testGetAllDbConsumers()
throws Exception
- {
- /*DatabaseScanningConfiguration dbScanning = new DatabaseScanningConfiguration();
+ {
+ DatabaseScanningConfiguration dbScanning = new DatabaseScanningConfiguration();
dbScanning.addCleanupConsumer( "cleanup-index" );
dbScanning.addCleanupConsumer( "cleanup-database" );
dbScanning.addUnprocessedConsumer( "unprocessed-artifacts" );
archivaConfigControl.replay();
configControl.replay();
+
+
List<String> dbConsumers = service.getAllDatabaseConsumers();
archivaConfigControl.verify();
assertTrue( dbConsumers.contains( "cleanup-index" ) );
assertTrue( dbConsumers.contains( "cleanup-database" ) );
assertTrue( dbConsumers.contains( "unprocessed-artifacts" ) );
- assertTrue( dbConsumers.contains( "unprocessed-poms" ) );*/
+ assertTrue( dbConsumers.contains( "unprocessed-poms" ) );
}
-/* public void testConfigureValidDatabaseConsumer()
+ public void testConfigureValidDatabaseConsumer()
throws Exception
{
DatabaseScanningConfiguration dbScanning = new DatabaseScanningConfiguration();
}
}
+ */
+
// REPOSITORY CONSUMERS
public void testGetAllRepoConsumers()
throws Exception
- {
- RepositoryScanningConfiguration repoScanning = new RepositoryScanningConfiguration();
- repoScanning.addKnownContentConsumer( "index-artifacts" );
- repoScanning.addKnownContentConsumer( "index-poms" );
- repoScanning.addKnownContentConsumer( "fix-checksums" );
- repoScanning.addInvalidContentConsumer( "check-poms" );
- repoScanning.addInvalidContentConsumer( "check-metadata" );
-
- archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
- configControl.expectAndReturn( config.getRepositoryScanning(), repoScanning );
-
- archivaConfigControl.replay();
- configControl.replay();
+ {
+ recordRepoConsumerValidation();
- List<String> repoConsumers = service.getAllDatabaseConsumers();
-
- archivaConfigControl.verify();
- configControl.verify();
+ consumerUtilControl.replay();
+ knownContentConsumerControl.replay();
+ invalidContentConsumerControl.replay();
+
+ List<String> repoConsumers = service.getAllRepositoryConsumers();
+ consumerUtilControl.verify();
+ knownContentConsumerControl.verify();
+ invalidContentConsumerControl.verify();
+
assertNotNull( repoConsumers );
- assertEquals( 5, repoConsumers.size() );
- assertTrue( repoConsumers.contains( "index-artifacts" ) );
- assertTrue( repoConsumers.contains( "index-poms" ) );
- assertTrue( repoConsumers.contains( "fix-checksums" ) );
- assertTrue( repoConsumers.contains( "check-poms" ) );
+ assertEquals( 4, repoConsumers.size() );
+ assertTrue( repoConsumers.contains( "index-artifact" ) );
+ assertTrue( repoConsumers.contains( "index-pom" ) );
+ assertTrue( repoConsumers.contains( "check-pom" ) );
assertTrue( repoConsumers.contains( "check-metadata" ) );
}
public void testConfigureValidRepositoryConsumer()
throws Exception
- {
- //TODO mock checking whether the repo consumer is valid or not
-
+ {
RepositoryScanningConfiguration repoScanning = new RepositoryScanningConfiguration();
- repoScanning.addKnownContentConsumer( "index-artifacts" );
- repoScanning.addKnownContentConsumer( "index-poms" );
- repoScanning.addKnownContentConsumer( "fix-checksums" );
- repoScanning.addInvalidContentConsumer( "check-poms" );
- repoScanning.addInvalidContentConsumer( "check-metadata" );
+ repoScanning.addKnownContentConsumer( "index-artifact" );
+ repoScanning.addKnownContentConsumer( "index-pom" );
+ repoScanning.addInvalidContentConsumer( "check-pom" );
+
+ // test enable "check-metadata" consumer
+ recordRepoConsumerValidation();
- // test enable
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();
-
+
+ consumerUtilControl.replay();
+ knownContentConsumerControl.replay();
+ invalidContentConsumerControl.replay();
archivaConfigControl.replay();
- configControl.replay();
+ configControl.replay();
try
{
- boolean success = service.configureRepositoryConsumer( null, "new-repo-consumer", true );
+ boolean success = service.configureRepositoryConsumer( null, "check-metadata", true );
assertTrue( success );
}
catch ( Exception e )
fail( "An exception should not have been thrown." );
}
+ consumerUtilControl.verify();
+ knownContentConsumerControl.verify();
+ invalidContentConsumerControl.verify();
archivaConfigControl.verify();
configControl.verify();
- // test disable
+ // test disable "check-metadata" consumer
+ consumerUtilControl.reset();
+ knownContentConsumerControl.reset();
+ invalidContentConsumerControl.reset();
archivaConfigControl.reset();
configControl.reset();
- //TODO mock checking whether the repo consumer is valid or not
+ repoScanning.addInvalidContentConsumer( "check-metadata" );
+
+ recordRepoConsumerValidation();
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.getRepositoryScanning(), repoScanning );
archivaConfig.save( config );
archivaConfigControl.setVoidCallable();
-
+
+ consumerUtilControl.replay();
+ knownContentConsumerControl.replay();
+ invalidContentConsumerControl.replay();
archivaConfigControl.replay();
configControl.replay();
try
{
- boolean success = service.configureRepositoryConsumer( null, "new-repo-consumer", false );
+ boolean success = service.configureRepositoryConsumer( null, "check-metadata", false );
+
+ consumerUtilControl.verify();
+ knownContentConsumerControl.verify();
+ invalidContentConsumerControl.verify();
+ archivaConfigControl.verify();
+ configControl.verify();
+
assertTrue( success );
}
catch ( Exception e )
{
fail( "An excecption should not have been thrown." );
- }
-
- archivaConfigControl.verify();
- configControl.verify();
+ }
}
-
+
+ /*
public void testConfigureInvalidRepositoryConsumer()
throws Exception
{
}
catch ( Exception e )
{
- assertEquals( "Invalid database consumer.", e.getMessage() );
+ assertEquals( "Invalid repository consumer.", e.getMessage() );
}
}
return repoConfig;
}
+ private void recordRepoConsumerValidation()
+ {
+ List<KnownRepositoryContentConsumer> availableKnownConsumers = new ArrayList<KnownRepositoryContentConsumer>();
+ availableKnownConsumers.add( indexArtifactConsumer );
+ availableKnownConsumers.add( indexPomConsumer );
+
+ List<InvalidRepositoryContentConsumer> availableInvalidConsumers = new ArrayList<InvalidRepositoryContentConsumer>();
+ availableInvalidConsumers.add( checkPomConsumer );
+ availableInvalidConsumers.add( checkMetadataConsumer );
+
+ consumerUtilControl.expectAndReturn( consumerUtil.getAvailableKnownConsumers(), availableKnownConsumers );
+ knownContentConsumerControl.expectAndReturn( indexArtifactConsumer.getId(), "index-artifact" );
+ knownContentConsumerControl.expectAndReturn( indexPomConsumer.getId(), "index-pom" );
+
+ consumerUtilControl.expectAndReturn( consumerUtil.getAvailableInvalidConsumers(), availableInvalidConsumers );
+ invalidContentConsumerControl.expectAndReturn( checkPomConsumer.getId(), "check-pom" );
+ invalidContentConsumerControl.expectAndReturn( checkMetadataConsumer.getId(), "check-metadata" );
+ }
+
}
\ No newline at end of file