]> source.dussan.org Git - archiva.git/blob
0a9b3085990f96ba68d4ed5d6655e1243459b071
[archiva.git] /
1 package org.apache.archiva.web.xmlrpc.services;
2
3 /*
4  * Licensed to the Apache Software Foundation (ASF) under one
5  * or more contributor license agreements.  See the NOTICE file
6  * distributed with this work for additional information
7  * regarding copyright ownership.  The ASF licenses this file
8  * to you under the Apache License, Version 2.0 (the
9  * "License"); you may not use this file except in compliance
10  * with the License.  You may obtain a copy of the License at
11  *
12  *   http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied.  See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  */
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import org.apache.archiva.web.xmlrpc.api.beans.ManagedRepository;
26 import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository;
27 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
28 import org.apache.maven.archiva.configuration.Configuration;
29 import org.apache.maven.archiva.configuration.DatabaseScanningConfiguration;
30 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
31 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
32 import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
33 import org.apache.maven.archiva.consumers.DatabaseCleanupConsumer;
34 import org.apache.maven.archiva.consumers.DatabaseUnprocessedArtifactConsumer;
35 import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
36 import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
37 import org.apache.maven.archiva.database.updater.DatabaseConsumers;
38 import org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers;
39 import org.apache.maven.archiva.scheduled.ArchivaTaskScheduler;
40 import org.apache.maven.archiva.scheduled.tasks.DatabaseTask;
41 import org.apache.maven.archiva.scheduled.tasks.RepositoryTask;
42 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
43 import org.easymock.MockControl;
44 import org.easymock.classextension.MockClassControl;
45
46 /**
47  * AdministrationServiceImplTest
48  * 
49  * @version $Id: AdministrationServiceImplTest.java
50  */
51 public class AdministrationServiceImplTest
52     extends PlexusInSpringTestCase
53 {    
54     private MockControl archivaConfigControl;
55     
56     private ArchivaConfiguration archivaConfig;
57     
58     private MockControl configControl;
59     
60     private Configuration config;
61     
62     private AdministrationServiceImpl service;
63     
64     private MockControl taskSchedulerControl;
65     
66     private ArchivaTaskScheduler taskScheduler;
67     
68     // repository consumers
69     private MockControl repoConsumerUtilsControl;
70     
71     private RepositoryContentConsumers repoConsumersUtil;
72     
73     private MockControl knownContentConsumerControl;
74
75     private MockControl invalidContentConsumerControl;
76
77     private KnownRepositoryContentConsumer indexArtifactConsumer;
78
79     private KnownRepositoryContentConsumer indexPomConsumer;
80
81     private InvalidRepositoryContentConsumer checkPomConsumer;
82
83     private InvalidRepositoryContentConsumer checkMetadataConsumer;
84     
85     // database consumers
86     private MockControl dbConsumersUtilControl;
87     
88     private DatabaseConsumers dbConsumersUtil;
89     
90     private MockControl unprocessedConsumersControl;
91     
92     private MockControl cleanupConsumersControl;
93     
94     private DatabaseUnprocessedArtifactConsumer processArtifactConsumer;
95     
96     private DatabaseUnprocessedArtifactConsumer processPomConsumer;
97     
98     private DatabaseCleanupConsumer cleanupIndexConsumer;
99     
100     private DatabaseCleanupConsumer cleanupDbConsumer;
101         
102     protected void setUp()
103         throws Exception
104     {
105         super.setUp();
106         
107         archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class );
108         archivaConfig = ( ArchivaConfiguration ) archivaConfigControl.getMock();
109         
110         configControl = MockClassControl.createControl( Configuration.class );
111         config = ( Configuration ) configControl.getMock();      
112         
113         taskSchedulerControl = MockControl.createControl( ArchivaTaskScheduler.class );
114         taskScheduler = ( ArchivaTaskScheduler ) taskSchedulerControl.getMock();
115         
116         // repo consumers
117         repoConsumerUtilsControl = MockClassControl.createControl( RepositoryContentConsumers.class );
118         repoConsumersUtil = ( RepositoryContentConsumers ) repoConsumerUtilsControl.getMock();
119         
120         knownContentConsumerControl = MockControl.createControl( KnownRepositoryContentConsumer.class );
121         indexArtifactConsumer = ( KnownRepositoryContentConsumer ) knownContentConsumerControl.getMock();
122         indexPomConsumer = ( KnownRepositoryContentConsumer ) knownContentConsumerControl.getMock();
123         
124         invalidContentConsumerControl = MockControl.createControl( InvalidRepositoryContentConsumer.class );
125         checkPomConsumer = ( InvalidRepositoryContentConsumer ) invalidContentConsumerControl.getMock();
126         checkMetadataConsumer = ( InvalidRepositoryContentConsumer ) invalidContentConsumerControl.getMock();
127         
128         // db consumers
129         dbConsumersUtilControl = MockClassControl.createControl( DatabaseConsumers.class );
130         dbConsumersUtil = ( DatabaseConsumers ) dbConsumersUtilControl.getMock();
131                 
132         cleanupConsumersControl = MockControl.createControl( DatabaseCleanupConsumer.class );
133         cleanupIndexConsumer = ( DatabaseCleanupConsumer ) cleanupConsumersControl.getMock();
134         cleanupDbConsumer = ( DatabaseCleanupConsumer ) cleanupConsumersControl.getMock();
135         
136         unprocessedConsumersControl = MockControl.createControl( DatabaseUnprocessedArtifactConsumer.class );
137         processArtifactConsumer = ( DatabaseUnprocessedArtifactConsumer ) unprocessedConsumersControl.getMock();
138         processPomConsumer = ( DatabaseUnprocessedArtifactConsumer ) unprocessedConsumersControl.getMock();
139         
140         service = new AdministrationServiceImpl();
141         service.setArchivaConfiguration( archivaConfig );
142         service.setRepoConsumersUtil( repoConsumersUtil );     
143         service.setDbConsumersUtil( dbConsumersUtil );
144         service.setTaskScheduler( taskScheduler );
145     }
146   
147 /* Tests for database consumers  */
148     
149     public void testGetAllDbConsumers()
150         throws Exception
151     {   
152         recordDbConsumers();
153         
154         dbConsumersUtilControl.replay();
155         cleanupConsumersControl.replay();
156         unprocessedConsumersControl.replay();
157         
158         List<String> dbConsumers = service.getAllDatabaseConsumers();
159         
160         dbConsumersUtilControl.verify();
161         cleanupConsumersControl.verify();
162         unprocessedConsumersControl.verify();
163         
164         assertNotNull( dbConsumers );
165         assertEquals( 4, dbConsumers.size() );
166         assertTrue( dbConsumers.contains( "cleanup-index" ) );
167         assertTrue( dbConsumers.contains( "cleanup-database" ) );
168         assertTrue( dbConsumers.contains( "process-artifact" ) );
169         assertTrue( dbConsumers.contains( "process-pom" ) );
170     }
171     
172     public void testConfigureValidDatabaseConsumer()
173         throws Exception
174     {
175         DatabaseScanningConfiguration dbScanning = new DatabaseScanningConfiguration();
176         dbScanning.addCleanupConsumer( "cleanup-index" );
177         dbScanning.addCleanupConsumer( "cleanup-database" );
178         dbScanning.addUnprocessedConsumer( "process-artifact" );
179         
180         recordDbConsumers();
181         
182      // test enable "process-pom" db consumer
183         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
184         configControl.expectAndReturn( config.getDatabaseScanning(), dbScanning );
185         
186         config.setDatabaseScanning( dbScanning );
187         configControl.setMatcher( MockControl.ALWAYS_MATCHER );
188         configControl.setVoidCallable();
189         
190         archivaConfig.save( config );
191         archivaConfigControl.setVoidCallable();
192         
193         dbConsumersUtilControl.replay();
194         cleanupConsumersControl.replay();
195         unprocessedConsumersControl.replay();
196         archivaConfigControl.replay();
197         configControl.replay();
198         
199         try
200         {
201             boolean success = service.configureDatabaseConsumer( "process-pom", true );
202             assertTrue( success );
203         }
204         catch ( Exception e )
205         {
206             fail( "An exception should not have been thrown." );
207         }
208         
209         dbConsumersUtilControl.verify();
210         cleanupConsumersControl.verify();
211         unprocessedConsumersControl.verify();
212         archivaConfigControl.verify();
213         configControl.verify();
214                 
215       // test disable "process-pom" db consumer        
216         dbConsumersUtilControl.reset();
217         cleanupConsumersControl.reset();
218         unprocessedConsumersControl.reset();
219         archivaConfigControl.reset();
220         configControl.reset();
221                 
222         dbScanning.addUnprocessedConsumer( "process-pom" );
223         
224         recordDbConsumers();
225         
226         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
227         configControl.expectAndReturn( config.getDatabaseScanning(), dbScanning );
228         
229         config.setDatabaseScanning( dbScanning );
230         configControl.setMatcher( MockControl.ALWAYS_MATCHER );
231         configControl.setVoidCallable();
232         
233         archivaConfig.save( config );
234         archivaConfigControl.setVoidCallable();
235         
236         dbConsumersUtilControl.replay();
237         cleanupConsumersControl.replay();
238         unprocessedConsumersControl.replay();
239         archivaConfigControl.replay();
240         configControl.replay();
241         
242         try
243         {
244             boolean success = service.configureDatabaseConsumer( "process-pom", false );
245             assertTrue( success );
246         }
247         catch ( Exception e )
248         {
249             fail( "An exception should not have been thrown." );
250         }
251         
252         dbConsumersUtilControl.verify();
253         cleanupConsumersControl.verify();
254         unprocessedConsumersControl.verify();
255         archivaConfigControl.verify();
256         configControl.verify();
257     }
258     
259     public void testConfigureInvalidDatabaseConsumer()
260         throws Exception
261     {
262         recordDbConsumers();
263         
264         dbConsumersUtilControl.replay();
265         cleanupConsumersControl.replay();
266         unprocessedConsumersControl.replay();
267         
268         try
269         {
270             service.configureDatabaseConsumer( "invalid-consumer", true );
271             fail( "An exception should have been thrown." );
272         }
273         catch ( Exception e )
274         {
275             assertEquals( "Invalid database consumer.", e.getMessage() );
276         }
277         
278         dbConsumersUtilControl.verify();
279         cleanupConsumersControl.verify();
280         unprocessedConsumersControl.verify();
281     }
282         
283 /* Tests for repository consumers  */
284     
285     public void testGetAllRepoConsumers()
286         throws Exception
287     {   
288         recordRepoConsumers();
289         
290         repoConsumerUtilsControl.replay();
291         knownContentConsumerControl.replay();
292         invalidContentConsumerControl.replay();
293                 
294         List<String> repoConsumers = service.getAllRepositoryConsumers(); 
295         
296         repoConsumerUtilsControl.verify();
297         knownContentConsumerControl.verify();
298         invalidContentConsumerControl.verify();
299                         
300         assertNotNull( repoConsumers );
301         assertEquals( 4, repoConsumers.size() );
302         assertTrue( repoConsumers.contains( "index-artifact" ) );
303         assertTrue( repoConsumers.contains( "index-pom" ) );
304         assertTrue( repoConsumers.contains( "check-pom" ) );
305         assertTrue( repoConsumers.contains( "check-metadata" ) );
306     }
307     
308     public void testConfigureValidRepositoryConsumer()
309         throws Exception
310     {   
311         RepositoryScanningConfiguration repoScanning = new RepositoryScanningConfiguration();
312         repoScanning.addKnownContentConsumer( "index-artifact" );
313         repoScanning.addKnownContentConsumer( "index-pom" );
314         repoScanning.addInvalidContentConsumer( "check-pom" );        
315         
316      // test enable "check-metadata" consumer
317         recordRepoConsumers();
318         
319         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
320         configControl.expectAndReturn( config.getRepositoryScanning(), repoScanning );
321         
322         config.setRepositoryScanning( repoScanning );                
323         configControl.setMatcher( MockControl.ALWAYS_MATCHER );
324         configControl.setVoidCallable();
325         
326         archivaConfig.save( config );
327         archivaConfigControl.setVoidCallable();
328                 
329         repoConsumerUtilsControl.replay();
330         knownContentConsumerControl.replay();
331         invalidContentConsumerControl.replay();
332         archivaConfigControl.replay();
333         configControl.replay();        
334         
335         try
336         {
337             boolean success = service.configureRepositoryConsumer( null, "check-metadata", true );
338             assertTrue( success );
339         }
340         catch ( Exception e )
341         {
342             fail( "An exception should not have been thrown." );
343         }
344         
345         repoConsumerUtilsControl.verify();
346         knownContentConsumerControl.verify();
347         invalidContentConsumerControl.verify();        
348         archivaConfigControl.verify();
349         configControl.verify();
350                 
351      // test disable "check-metadata" consumer 
352         repoConsumerUtilsControl.reset();
353         knownContentConsumerControl.reset();
354         invalidContentConsumerControl.reset();        
355         archivaConfigControl.reset();
356         configControl.reset();
357         
358         repoScanning.addInvalidContentConsumer( "check-metadata" );
359
360         recordRepoConsumers();
361         
362         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
363         configControl.expectAndReturn( config.getRepositoryScanning(), repoScanning );
364         
365         config.setRepositoryScanning( repoScanning );
366         configControl.setMatcher( MockControl.ALWAYS_MATCHER );
367         configControl.setVoidCallable();
368         
369         archivaConfig.save( config );
370         archivaConfigControl.setVoidCallable();
371                 
372         repoConsumerUtilsControl.replay();
373         knownContentConsumerControl.replay();
374         invalidContentConsumerControl.replay();
375         archivaConfigControl.replay();
376         configControl.replay();
377         
378         try
379         {
380             boolean success = service.configureRepositoryConsumer( null, "check-metadata", false );
381             
382             repoConsumerUtilsControl.verify();
383             knownContentConsumerControl.verify();
384             invalidContentConsumerControl.verify();        
385             archivaConfigControl.verify();
386             configControl.verify();
387             
388             assertTrue( success );
389         }
390         catch ( Exception e )
391         {
392             fail( "An excecption should not have been thrown." );
393         }     
394     }
395  
396     
397     public void testConfigureInvalidRepositoryConsumer()
398         throws Exception
399     {
400         recordRepoConsumers();
401         
402         repoConsumerUtilsControl.replay();
403         knownContentConsumerControl.replay();
404         invalidContentConsumerControl.replay();
405         
406         try
407         {
408             service.configureRepositoryConsumer( null, "invalid-consumer", true );
409             fail( "An exception should have been thrown." );
410         }
411         catch ( Exception e )
412         {
413             assertEquals( "Invalid repository consumer.", e.getMessage() );
414         }
415         
416         repoConsumerUtilsControl.verify();
417         knownContentConsumerControl.verify();
418         invalidContentConsumerControl.verify(); 
419     }
420
421 /* Tests for delete artifact  */
422     
423     /*   public void testDeleteArtifactArtifactExists()
424         throws Exception
425     {
426         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
427         configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ),
428                                        createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
429         
430         // TODO 
431         // - mock checking of artifact existence in the repo
432         // - mock artifact delete
433         
434         archivaConfigControl.replay();
435         configControl.replay();
436        
437         try
438         {
439             boolean success = service.deleteArtifact( "internal", "org.apache.archiva", "archiva-test", "1.0" );
440             assertTrue( success ); 
441         }
442         catch ( Exception e )
443         {
444             fail( "An exception should not have been thrown." );
445         }
446         
447         archivaConfigControl.verify();
448         configControl.verify();
449     }
450     
451     public void testDeleteArtifactArtifactDoesNotExist()
452         throws Exception
453     {
454         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
455         configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ),
456                                        createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
457         
458         // TODO mock checking of artifact existence in the repo
459         
460         archivaConfigControl.replay();
461         configControl.replay();
462        
463         try
464         {
465             service.deleteArtifact( "internal", "org.apache.archiva", "archiva-test", "1.0" );
466             fail( "An exception should have been thrown." );
467         }
468         catch ( Exception e )
469         {
470             assertEquals( "Artifact does not exist.", e.getMessage() );
471         }
472         
473         archivaConfigControl.verify();
474         configControl.verify();
475     }
476     
477     public void testDeleteArtifacRepositoryDoesNotExist()
478         throws Exception
479     {
480         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
481         configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), null );
482         
483         archivaConfigControl.replay();
484         configControl.replay();
485        
486         try
487         {
488             service.deleteArtifact( "internal", "org.apache.archiva", "archiva-test", "1.0" );
489             fail( "An exception should have been thrown." );
490         }
491         catch ( Exception e )
492         {
493             assertEquals( "Repository does not exist.", e.getMessage() );
494         }
495         
496         archivaConfigControl.verify();
497         configControl.verify();
498     }
499     */
500     
501 /* Tests for repository scanning  */
502     
503     public void testExecuteRepoScannerRepoExistsAndNotBeingScanned()
504         throws Exception
505     {        
506         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
507         configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ),
508                                        createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
509         
510         RepositoryTask task = new RepositoryTask();
511         
512         taskSchedulerControl.expectAndReturn( taskScheduler.isProcessingAnyRepositoryTask(), true );
513         taskSchedulerControl.expectAndReturn( taskScheduler.isProcessingRepositoryTask( "internal" ), false );
514         
515         taskScheduler.queueRepositoryTask( task );
516         taskSchedulerControl.setMatcher( MockControl.ALWAYS_MATCHER );
517         taskSchedulerControl.setVoidCallable();
518         
519         archivaConfigControl.replay();
520         configControl.replay();
521         taskSchedulerControl.replay();
522
523         try
524         {
525             boolean success = service.executeRepositoryScanner( "internal" );
526             assertTrue( success );
527         }
528         catch ( Exception e )
529         {
530             fail( "An exception should not have been thrown." );
531         }
532         
533         archivaConfigControl.verify();
534         configControl.verify();
535         taskSchedulerControl.verify();
536     }
537     
538     public void testExecuteRepoScannerRepoExistsButBeingScanned()
539         throws Exception
540     {        
541         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
542         configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ),
543                                        createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
544         
545         taskSchedulerControl.expectAndReturn( taskScheduler.isProcessingAnyRepositoryTask(), true );
546         taskSchedulerControl.expectAndReturn( taskScheduler.isProcessingRepositoryTask( "internal" ), true);
547         
548         archivaConfigControl.replay();
549         configControl.replay();
550         taskSchedulerControl.replay();
551     
552         try
553         {
554             boolean success = service.executeRepositoryScanner( "internal" );
555             assertFalse( success );
556         }
557         catch ( Exception e )
558         {
559             fail( "An exception should not have been thrown." );
560         }
561         
562         archivaConfigControl.verify();
563         configControl.verify();
564         taskSchedulerControl.verify();
565     }
566     
567     public void testExecuteRepoScannerRepoDoesNotExist()
568         throws Exception
569     {
570         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
571         configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), null );
572         
573         archivaConfigControl.replay();
574         configControl.replay();
575        
576         try
577         {
578             service.executeRepositoryScanner( "internal" );
579             fail( "An exception should have been thrown." );
580         }
581         catch ( Exception e )
582         {
583             assertEquals( "Repository does not exist.", e.getMessage() );
584         }
585         
586         archivaConfigControl.verify();
587         configControl.verify();
588     }
589     
590 /* Tests for db scanning  */
591     
592     public void testExecuteDbScannerDbNotBeingScanned()
593         throws Exception
594     {
595         DatabaseTask task = new DatabaseTask();
596         
597         taskSchedulerControl.expectAndReturn( taskScheduler.isProcessingDatabaseTask(), false );
598                 
599         taskScheduler.queueDatabaseTask( task );
600         taskSchedulerControl.setMatcher( MockControl.ALWAYS_MATCHER );
601         taskSchedulerControl.setVoidCallable();
602         
603         taskSchedulerControl.replay();
604
605         boolean success = service.executeDatabaseScanner();
606         
607         taskSchedulerControl.verify();        
608         
609         assertTrue( success );
610     }
611     
612     public void testExecuteDbScannerDbIsBeingScanned()
613         throws Exception
614     {        
615         taskSchedulerControl.expectAndReturn( taskScheduler.isProcessingDatabaseTask(), true );
616                 
617         taskSchedulerControl.replay();
618
619         boolean success = service.executeDatabaseScanner();
620         
621         taskSchedulerControl.verify();        
622         
623         assertFalse( success );
624     }
625      
626 /* Tests for querying repositories  */
627     
628     public void testGetAllManagedRepositories()
629         throws Exception
630     {
631         List<ManagedRepositoryConfiguration> managedRepos = new ArrayList<ManagedRepositoryConfiguration>();        
632         managedRepos.add( createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
633         managedRepos.add( createManagedRepo( "snapshots", "default", "Snapshots Repository", false, true ) );
634         
635         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
636         configControl.expectAndReturn( config.getManagedRepositories(), managedRepos );
637         
638         archivaConfigControl.replay();
639         configControl.replay();
640         
641         List<ManagedRepository> repos = service.getAllManagedRepositories(); 
642         
643         archivaConfigControl.verify();
644         configControl.verify();
645         
646         assertNotNull( repos );
647         assertEquals( 2, repos.size() );
648                 
649         assertManagedRepo( ( ManagedRepository ) repos.get( 0 ), managedRepos.get( 0 ) );
650         assertManagedRepo( ( ManagedRepository ) repos.get( 1 ), managedRepos.get( 1 ) );
651     }
652
653     public void testGetAllRemoteRepositories()
654         throws Exception
655     {
656         List<RemoteRepositoryConfiguration> remoteRepos = new ArrayList<RemoteRepositoryConfiguration>(); 
657         remoteRepos.add( createRemoteRepository( "central", "Central Repository", "default", "http://repo1.maven.org/maven2") );
658         remoteRepos.add( createRemoteRepository( "dummy", "Dummy Remote Repository", "legacy", "http://dummy.com/dummy") );
659         
660         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
661         configControl.expectAndReturn( config.getRemoteRepositories(), remoteRepos );
662         
663         archivaConfigControl.replay();
664         configControl.replay();
665         
666         List<RemoteRepository> repos = service.getAllRemoteRepositories(); 
667         
668         archivaConfigControl.verify();
669         configControl.verify();
670         
671         assertNotNull( repos );
672         assertEquals( 2, repos.size() );
673          
674         assertRemoteRepo( (RemoteRepository) repos.get( 0 ), remoteRepos.get( 0 ) );
675         assertRemoteRepo( (RemoteRepository) repos.get( 1 ), remoteRepos.get( 1 ) );        
676     }
677     
678 /* private methods  */
679     
680     private void assertRemoteRepo( RemoteRepository remoteRepo, RemoteRepositoryConfiguration expectedRepoConfig )
681     {
682         assertEquals( expectedRepoConfig.getId(), remoteRepo.getId() );
683         assertEquals( expectedRepoConfig.getLayout(), remoteRepo.getLayout() );
684         assertEquals( expectedRepoConfig.getName(), remoteRepo.getName() );
685         assertEquals( expectedRepoConfig.getUrl(), remoteRepo.getUrl() );       
686     }
687     
688     private RemoteRepositoryConfiguration createRemoteRepository(String id, String name, String layout, String url)
689     {
690         RemoteRepositoryConfiguration remoteConfig = new RemoteRepositoryConfiguration();
691         remoteConfig.setId( id );
692         remoteConfig.setName( name );
693         remoteConfig.setLayout( layout );
694         remoteConfig.setUrl( url );
695         
696         return remoteConfig;
697     }
698     
699     private void assertManagedRepo( ManagedRepository managedRepo, ManagedRepositoryConfiguration expectedRepoConfig )
700     {
701         assertEquals( expectedRepoConfig.getId(), managedRepo.getId() );
702         assertEquals( expectedRepoConfig.getLayout(), managedRepo.getLayout() );
703         assertEquals( expectedRepoConfig.getName(), managedRepo.getName() );
704         //assertEquals( "http://localhost:8080/archiva/repository/" + expectedRepoConfig.getId(), managedRepo.getUrl() );
705         assertEquals( expectedRepoConfig.isReleases(), managedRepo.isReleases() );
706         assertEquals( expectedRepoConfig.isSnapshots(), managedRepo.isSnapshots() );
707     }
708
709     private ManagedRepositoryConfiguration createManagedRepo( String id, String layout, String name,
710                                                               boolean hasReleases, boolean hasSnapshots )
711     {
712         ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
713         repoConfig.setId( id );
714         repoConfig.setLayout( layout );
715         repoConfig.setName( name );
716         repoConfig.setReleases( hasReleases );
717         repoConfig.setSnapshots( hasSnapshots );
718         
719         return repoConfig;
720     }
721     
722     private void recordRepoConsumers()
723     {
724         List<KnownRepositoryContentConsumer> availableKnownConsumers = new ArrayList<KnownRepositoryContentConsumer>();
725         availableKnownConsumers.add( indexArtifactConsumer );
726         availableKnownConsumers.add( indexPomConsumer );
727         
728         List<InvalidRepositoryContentConsumer> availableInvalidConsumers = new ArrayList<InvalidRepositoryContentConsumer>();
729         availableInvalidConsumers.add( checkPomConsumer );
730         availableInvalidConsumers.add( checkMetadataConsumer );
731         
732         repoConsumerUtilsControl.expectAndReturn( repoConsumersUtil.getAvailableKnownConsumers(), availableKnownConsumers );
733         knownContentConsumerControl.expectAndReturn( indexArtifactConsumer.getId(), "index-artifact" );
734         knownContentConsumerControl.expectAndReturn( indexPomConsumer.getId(), "index-pom" );
735         
736         repoConsumerUtilsControl.expectAndReturn( repoConsumersUtil.getAvailableInvalidConsumers(), availableInvalidConsumers );
737         invalidContentConsumerControl.expectAndReturn( checkPomConsumer.getId(), "check-pom" );
738         invalidContentConsumerControl.expectAndReturn( checkMetadataConsumer.getId(), "check-metadata" );
739     }
740     
741     private void recordDbConsumers()
742     {
743         List<DatabaseCleanupConsumer> cleanupConsumers = new ArrayList<DatabaseCleanupConsumer>();
744         cleanupConsumers.add( cleanupIndexConsumer );
745         cleanupConsumers.add( cleanupDbConsumer );
746         
747         List<DatabaseUnprocessedArtifactConsumer> unprocessedConsumers =
748             new ArrayList<DatabaseUnprocessedArtifactConsumer>();
749         unprocessedConsumers.add( processArtifactConsumer );
750         unprocessedConsumers.add( processPomConsumer );
751         
752         dbConsumersUtilControl.expectAndReturn( dbConsumersUtil.getAvailableCleanupConsumers(), cleanupConsumers );
753         cleanupConsumersControl.expectAndReturn( cleanupIndexConsumer.getId(), "cleanup-index" );
754         cleanupConsumersControl.expectAndReturn( cleanupDbConsumer.getId(), "cleanup-database" );
755         
756         dbConsumersUtilControl.expectAndReturn( dbConsumersUtil.getAvailableUnprocessedConsumers(), unprocessedConsumers );
757         unprocessedConsumersControl.expectAndReturn( processArtifactConsumer.getId(), "process-artifact" );
758         unprocessedConsumersControl.expectAndReturn( processPomConsumer.getId(), "process-pom" );
759     }    
760 }