archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From och...@apache.org
Subject svn commit: r703301 - in /archiva/branches/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src: main/java/org/apache/archiva/web/xmlrpc/services/ test/java/org/apache/archiva/web/xmlrpc/services/
Date Fri, 10 Oct 2008 00:32:58 GMT
Author: oching
Date: Thu Oct  9 17:32:57 2008
New Revision: 703301

URL: http://svn.apache.org/viewvc?rev=703301&view=rev
Log:
implemented getAllRepositoryConsumers() and configureRepositoryConsumer() in admin service

Modified:
    archiva/branches/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java
    archiva/branches/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java

Modified: archiva/branches/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java?rev=703301&r1=703300&r2=703301&view=diff
==============================================================================
--- archiva/branches/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java
(original)
+++ archiva/branches/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java
Thu Oct  9 17:32:57 2008
@@ -19,6 +19,7 @@
  * under the License.
  */
 
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.archiva.web.xmlrpc.api.AdministrationService;
@@ -26,6 +27,13 @@
 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
@@ -35,21 +43,72 @@
      */
     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
@@ -70,16 +129,37 @@
         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()
@@ -91,4 +171,36 @@
     {
         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;
+    }    
 }

Modified: archiva/branches/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java?rev=703301&r1=703300&r2=703301&view=diff
==============================================================================
--- archiva/branches/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java
(original)
+++ archiva/branches/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java
Thu Oct  9 17:32:57 2008
@@ -31,6 +31,9 @@
 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;
@@ -53,11 +56,27 @@
     
     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
@@ -73,14 +92,27 @@
         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" );
@@ -92,6 +124,8 @@
         archivaConfigControl.replay();
         configControl.replay();
         
+        
+        
         List<String> dbConsumers = service.getAllDatabaseConsumers(); 
         
         archivaConfigControl.verify();
@@ -102,10 +136,10 @@
         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();
@@ -192,67 +226,62 @@
         }
     }
     
+    */
+    
  // 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" );
+    {   
+        recordRepoConsumerValidation();
         
-        archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
-        configControl.expectAndReturn( config.getRepositoryScanning(), repoScanning );
-        
-        archivaConfigControl.replay();
-        configControl.replay();
-        
-        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 )
@@ -260,14 +289,22 @@
             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 );
@@ -278,24 +315,32 @@
         
         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
     {
@@ -308,7 +353,7 @@
         }
         catch ( Exception e )
         {
-            assertEquals( "Invalid database consumer.", e.getMessage() );
+            assertEquals( "Invalid repository consumer.", e.getMessage() );
         }
     }
 
@@ -567,4 +612,23 @@
         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



Mime
View raw message