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.scheduled.ArchivaTaskScheduler;
+import org.apache.maven.archiva.scheduled.tasks.DatabaseTask;
+import org.apache.maven.archiva.scheduled.tasks.RepositoryTask;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import org.easymock.MockControl;
import org.easymock.classextension.MockClassControl;
private AdministrationService service;
+ private MockControl taskSchedulerControl;
+
+ private ArchivaTaskScheduler taskScheduler;
+
protected void setUp()
throws Exception
{
configControl = MockClassControl.createControl( Configuration.class );
config = ( Configuration ) configControl.getMock();
+ taskSchedulerControl = MockControl.createControl( ArchivaTaskScheduler.class );
+ taskScheduler = ( ArchivaTaskScheduler ) taskSchedulerControl.getMock();
+
service = new AdministrationServiceImpl();
}
-
- public void testConfigureValidDatabaseConsumer()
+
+ // DATABASE CONSUMERS
+ public void testGetAllDbConsumers()
throws Exception
{
/*DatabaseScanningConfiguration dbScanning = new DatabaseScanningConfiguration();
dbScanning.addUnprocessedConsumer( "unprocessed-artifacts" );
dbScanning.addUnprocessedConsumer( "unprocessed-poms" );
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+ configControl.expectAndReturn( config.getDatabaseScanning(), dbScanning );
+
+ archivaConfigControl.replay();
+ configControl.replay();
+
+ List<String> dbConsumers = service.getAllDatabaseConsumers();
+
+ archivaConfigControl.verify();
+ configControl.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" ) );*/
+ }
+
+/* public void testConfigureValidDatabaseConsumer()
+ throws Exception
+ {
+ 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
+
// test enable
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.getDatabaseScanning(), dbScanning );
archivaConfigControl.replay();
configControl.replay();
- boolean success = service.configureDatabaseConsumer( "new-cleanup-consumer", true );
+ try
+ {
+ boolean success = service.configureDatabaseConsumer( "new-cleanup-consumer", true );
+ assertTrue( success );
+ }
+ catch ( Exception e )
+ {
+ fail( "An exception should not have been thrown." );
+ }
archivaConfigControl.verify();
configControl.verify();
-
- assertTrue( success );
-
+
// test disable
archivaConfigControl.reset();
configControl.reset();
+ //TODO mock checking whether the db consumer is valid or not
+
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.getDatabaseScanning(), dbScanning );
archivaConfigControl.replay();
configControl.replay();
- success = service.configureDatabaseConsumer( "new-cleanup-consumer", false );
+ try
+ {
+ boolean success = service.configureDatabaseConsumer( "new-cleanup-consumer", false );
+ assertTrue( success );
+ }
+ catch ( Exception e )
+ {
+ fail( "An exception should not have been thrown." );
+ }
archivaConfigControl.verify();
configControl.verify();
-
- assertTrue( success );*/
}
public void testConfigureInvalidDatabaseConsumer()
throws Exception
{
+ //TODO mock checking whether the db consumer is valid or not
+
+ try
+ {
+ service.configureDatabaseConsumer( "invalid-consumer", true );
+ fail( "An exception should have been thrown." );
+ }
+ catch ( Exception e )
+ {
+ assertEquals( "Invalid database consumer.", e.getMessage() );
+ }
+ }
+
+ // 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();
+
+ List<String> repoConsumers = service.getAllDatabaseConsumers();
+
+ archivaConfigControl.verify();
+ configControl.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" ) );
+ assertTrue( repoConsumers.contains( "check-metadata" ) );
}
public void testConfigureValidRepositoryConsumer()
throws Exception
{
- // test enable & disable
+ //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" );
+
+ // test enable
+ 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();
+
+ archivaConfigControl.replay();
+ configControl.replay();
+
+ try
+ {
+ boolean success = service.configureRepositoryConsumer( null, "new-repo-consumer", true );
+ assertTrue( success );
+ }
+ catch ( Exception e )
+ {
+ fail( "An exception should not have been thrown." );
+ }
+
+ archivaConfigControl.verify();
+ configControl.verify();
+
+ // test disable
+ archivaConfigControl.reset();
+ configControl.reset();
+
+ //TODO mock checking whether the repo consumer is valid or not
+
+ 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();
+
+ archivaConfigControl.replay();
+ configControl.replay();
+
+ try
+ {
+ boolean success = service.configureRepositoryConsumer( null, "new-repo-consumer", false );
+ assertTrue( success );
+ }
+ catch ( Exception e )
+ {
+ fail( "An excecption should not have been thrown." );
+ }
+
+ archivaConfigControl.verify();
+ configControl.verify();
}
public void testConfigureInvalidRepositoryConsumer()
throws Exception
{
-
+ //TODO mock checking whether the repo consumer is valid or not
+
+ try
+ {
+ service.configureRepositoryConsumer( null, "invalid-consumer", true );
+ fail( "An exception should have been thrown." );
+ }
+ catch ( Exception e )
+ {
+ assertEquals( "Invalid database consumer.", e.getMessage() );
+ }
}
+
+// DELETE ARTIFACT
public void testDeleteArtifactArtifactExists()
throws Exception
{
-
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+ configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ),
+ createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
+
+ // TODO
+ // - mock checking of artifact existence in the repo
+ // - mock artifact delete
+
+ archivaConfigControl.replay();
+ configControl.replay();
+
+ try
+ {
+ boolean success = service.deleteArtifact( "internal", "org.apache.archiva", "archiva-test", "1.0" );
+ assertTrue( success );
+ }
+ catch ( Exception e )
+ {
+ fail( "An exception should not have been thrown." );
+ }
+
+ archivaConfigControl.verify();
+ configControl.verify();
}
public void testDeleteArtifactArtifactDoesNotExist()
throws Exception
{
-
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+ configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ),
+ createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
+
+ // TODO mock checking of artifact existence in the repo
+
+ archivaConfigControl.replay();
+ configControl.replay();
+
+ try
+ {
+ service.deleteArtifact( "internal", "org.apache.archiva", "archiva-test", "1.0" );
+ fail( "An exception should have been thrown." );
+ }
+ catch ( Exception e )
+ {
+ assertEquals( "Artifact does not exist.", e.getMessage() );
+ }
+
+ archivaConfigControl.verify();
+ configControl.verify();
}
public void testDeleteArtifacRepositoryDoesNotExist()
throws Exception
{
-
- }
-
- public void testExecuteRepoScannerRepoExists()
- throws Exception
- {
-
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+ configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), null );
+
+ archivaConfigControl.replay();
+ configControl.replay();
+
+ try
+ {
+ service.deleteArtifact( "internal", "org.apache.archiva", "archiva-test", "1.0" );
+ fail( "An exception should have been thrown." );
+ }
+ catch ( Exception e )
+ {
+ assertEquals( "Repository does not exist.", e.getMessage() );
+ }
+
+ archivaConfigControl.verify();
+ configControl.verify();
}
- public void testExecuteRepoScannerRepoDoesNotExist()
- throws Exception
- {
-
- }
+// REPO SCANNING
- public void testExecuteDbScanner()
+ public void testExecuteRepoScannerRepoExists()
throws Exception
- {
+ {
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+ configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ),
+ createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
- }
-
- 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" );
+ RepositoryTask task = new RepositoryTask();
- archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
- configControl.expectAndReturn( config.getDatabaseScanning(), dbScanning );
+ taskSchedulerControl.expectAndReturn( taskScheduler.isProcessingAnyRepositoryTask(), false );
+ taskSchedulerControl.expectAndReturn( taskScheduler.isProcessingRepositoryTask( "internal" ), false );
+
+ taskScheduler.queueRepositoryTask( task );
+ taskSchedulerControl.setMatcher( MockControl.ALWAYS_MATCHER );
+ taskSchedulerControl.setVoidCallable();
archivaConfigControl.replay();
configControl.replay();
-
- List<String> dbConsumers = service.getAllDatabaseConsumers();
+ taskSchedulerControl.replay();
+
+ try
+ {
+ boolean success = service.executeRepositoryScanner( "internal" );
+ assertTrue( success );
+ }
+ catch ( Exception e )
+ {
+ fail( "An exception should not have been thrown." );
+ }
archivaConfigControl.verify();
configControl.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" ) );*/
+ taskSchedulerControl.verify();
}
- public void testGetAllRepoConsumers()
+ public void testExecuteRepoScannerRepoDoesNotExist()
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 );
+ configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), null );
archivaConfigControl.replay();
configControl.replay();
-
- List<String> repoConsumers = service.getAllDatabaseConsumers();
+
+ try
+ {
+ service.executeRepositoryScanner( "internal" );
+ fail( "An exception should have been thrown." );
+ }
+ catch ( Exception e )
+ {
+ assertEquals( "Repository does not exist.", e.getMessage() );
+ }
archivaConfigControl.verify();
configControl.verify();
+ }
+
+ // DATABASE SCANNING
+
+ public void testExecuteDbScanner()
+ throws Exception
+ {
+ DatabaseTask task = new DatabaseTask();
- 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" ) );
- assertTrue( repoConsumers.contains( "check-metadata" ) );*/
+ taskSchedulerControl.expectAndReturn( taskScheduler.isProcessingDatabaseTask(), false );
+
+ taskScheduler.queueDatabaseTask( task );
+ taskSchedulerControl.setMatcher( MockControl.ALWAYS_MATCHER );
+ taskSchedulerControl.setVoidCallable();
+
+ taskSchedulerControl.replay();
+
+ boolean success = service.executeDatabaseScanner();
+
+ taskSchedulerControl.verify();
+
+ assertTrue( success );
}
+
+ // 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 ) );
assertEquals( 2, repos.size() );
assertManagedRepo( ( ManagedRepository ) repos.get( 0 ), managedRepos.get( 0 ) );
- assertManagedRepo( ( ManagedRepository ) repos.get( 1 ), managedRepos.get( 1 ) );*/
+ assertManagedRepo( ( ManagedRepository ) repos.get( 1 ), managedRepos.get( 1 ) );
}
public void testGetAllRemoteRepositories()
throws Exception
{
- /*List<RemoteRepositoryConfiguration> remoteRepos = new ArrayList<RemoteRepositoryConfiguration>();
+ 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") );
assertEquals( 2, repos.size() );
assertRemoteRepo( (RemoteRepository) repos.get( 0 ), remoteRepos.get( 0 ) );
- assertRemoteRepo( (RemoteRepository) repos.get( 1 ), remoteRepos.get( 1 ) ); */
+ assertRemoteRepo( (RemoteRepository) repos.get( 1 ), remoteRepos.get( 1 ) );
}
-
+*/
private void assertRemoteRepo( RemoteRepository remoteRepo, RemoteRepositoryConfiguration expectedRepoConfig )
{
assertEquals( expectedRepoConfig.getId(), remoteRepo.getId() );