1 package org.apache.archiva.web.xmlrpc.services;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import org.apache.archiva.metadata.model.ArtifactMetadata;
23 import org.apache.archiva.metadata.repository.MetadataRepository;
24 import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
25 import org.apache.archiva.repository.events.RepositoryListener;
26 import org.apache.archiva.repository.scanner.RepositoryContentConsumers;
27 import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler;
28 import org.apache.archiva.scheduler.repository.RepositoryTask;
29 import org.apache.archiva.web.xmlrpc.api.beans.ManagedRepository;
30 import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository;
31 import org.apache.commons.io.FileUtils;
32 import org.apache.commons.io.filefilter.FileFilterUtils;
33 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
34 import org.apache.maven.archiva.configuration.Configuration;
35 import org.apache.maven.archiva.configuration.FileTypes;
36 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
37 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
38 import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
39 import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
40 import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
41 import org.apache.maven.archiva.model.ArtifactReference;
42 import org.apache.maven.archiva.repository.RepositoryContentFactory;
43 import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent;
44 import org.apache.maven.archiva.repository.content.ManagedLegacyRepositoryContent;
45 import org.apache.maven.archiva.repository.content.PathParser;
46 import org.apache.maven.archiva.repository.layout.LayoutException;
47 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
48 import org.easymock.MockControl;
49 import org.easymock.classextension.MockClassControl;
52 import java.io.IOException;
53 import java.util.ArrayList;
54 import java.util.Collections;
55 import java.util.List;
58 * AdministrationServiceImplTest
60 * @version $Id: AdministrationServiceImplTest.java
62 public class AdministrationServiceImplTest
63 extends PlexusInSpringTestCase
65 private MockControl archivaConfigControl;
67 private ArchivaConfiguration archivaConfig;
69 private MockControl configControl;
71 private Configuration config;
73 private AdministrationServiceImpl service;
75 private MockControl repositoryTaskSchedulerControl;
77 private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
79 // repository consumers
80 private MockControl repoConsumerUtilsControl;
82 private RepositoryContentConsumers repoConsumersUtil;
84 private MockControl knownContentConsumerControl;
86 private MockControl invalidContentConsumerControl;
88 private KnownRepositoryContentConsumer indexArtifactConsumer;
90 private KnownRepositoryContentConsumer indexPomConsumer;
92 private InvalidRepositoryContentConsumer checkPomConsumer;
94 private InvalidRepositoryContentConsumer checkMetadataConsumer;
97 private MockControl repoFactoryControl;
99 private RepositoryContentFactory repositoryFactory;
101 private MockControl listenerControl;
103 private RepositoryListener listener;
105 private MockControl metadataRepositoryControl;
107 private MetadataRepository metadataRepository;
109 private MockControl repositoryStatisticsManagerControl;
111 private RepositoryStatisticsManager repositoryStatisticsManager;
113 protected void setUp()
118 archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class );
119 archivaConfig = ( ArchivaConfiguration ) archivaConfigControl.getMock();
121 configControl = MockClassControl.createControl( Configuration.class );
122 config = ( Configuration ) configControl.getMock();
124 repositoryTaskSchedulerControl = MockClassControl.createControl( RepositoryArchivaTaskScheduler.class );
125 repositoryTaskScheduler = (RepositoryArchivaTaskScheduler) repositoryTaskSchedulerControl.getMock();
128 repoConsumerUtilsControl = MockClassControl.createControl( RepositoryContentConsumers.class );
129 repoConsumersUtil = ( RepositoryContentConsumers ) repoConsumerUtilsControl.getMock();
131 knownContentConsumerControl = MockControl.createControl( KnownRepositoryContentConsumer.class );
132 indexArtifactConsumer = ( KnownRepositoryContentConsumer ) knownContentConsumerControl.getMock();
133 indexPomConsumer = ( KnownRepositoryContentConsumer ) knownContentConsumerControl.getMock();
135 invalidContentConsumerControl = MockControl.createControl( InvalidRepositoryContentConsumer.class );
136 checkPomConsumer = ( InvalidRepositoryContentConsumer ) invalidContentConsumerControl.getMock();
137 checkMetadataConsumer = ( InvalidRepositoryContentConsumer ) invalidContentConsumerControl.getMock();
140 repoFactoryControl = MockClassControl.createControl( RepositoryContentFactory.class );
141 repositoryFactory = ( RepositoryContentFactory ) repoFactoryControl.getMock();
143 metadataRepositoryControl = MockControl.createControl( MetadataRepository.class );
144 metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock();
146 listenerControl = MockControl.createControl( RepositoryListener.class );
147 listener = (RepositoryListener) listenerControl.getMock();
149 repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class );
150 repositoryStatisticsManager = (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock();
154 new AdministrationServiceImpl( archivaConfig, repoConsumersUtil, repositoryFactory,
155 metadataRepository, repositoryTaskScheduler,
156 Collections.singletonList( listener ), repositoryStatisticsManager );
159 /* Tests for repository consumers */
161 public void testGetAllRepoConsumers()
164 recordRepoConsumers();
166 repoConsumerUtilsControl.replay();
167 knownContentConsumerControl.replay();
168 invalidContentConsumerControl.replay();
170 List<String> repoConsumers = service.getAllRepositoryConsumers();
172 repoConsumerUtilsControl.verify();
173 knownContentConsumerControl.verify();
174 invalidContentConsumerControl.verify();
176 assertNotNull( repoConsumers );
177 assertEquals( 4, repoConsumers.size() );
178 assertTrue( repoConsumers.contains( "index-artifact" ) );
179 assertTrue( repoConsumers.contains( "index-pom" ) );
180 assertTrue( repoConsumers.contains( "check-pom" ) );
181 assertTrue( repoConsumers.contains( "check-metadata" ) );
184 public void testConfigureValidRepositoryConsumer()
187 RepositoryScanningConfiguration repoScanning = new RepositoryScanningConfiguration();
188 repoScanning.addKnownContentConsumer( "index-artifact" );
189 repoScanning.addKnownContentConsumer( "index-pom" );
190 repoScanning.addInvalidContentConsumer( "check-pom" );
192 // test enable "check-metadata" consumer
193 recordRepoConsumers();
195 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
196 configControl.expectAndReturn( config.getRepositoryScanning(), repoScanning );
198 config.setRepositoryScanning( repoScanning );
199 configControl.setMatcher( MockControl.ALWAYS_MATCHER );
200 configControl.setVoidCallable();
202 archivaConfig.save( config );
203 archivaConfigControl.setVoidCallable();
205 repoConsumerUtilsControl.replay();
206 knownContentConsumerControl.replay();
207 invalidContentConsumerControl.replay();
208 archivaConfigControl.replay();
209 configControl.replay();
213 boolean success = service.configureRepositoryConsumer( null, "check-metadata", true );
214 assertTrue( success );
216 catch ( Exception e )
218 fail( "An exception should not have been thrown." );
221 repoConsumerUtilsControl.verify();
222 knownContentConsumerControl.verify();
223 invalidContentConsumerControl.verify();
224 archivaConfigControl.verify();
225 configControl.verify();
227 // test disable "check-metadata" consumer
228 repoConsumerUtilsControl.reset();
229 knownContentConsumerControl.reset();
230 invalidContentConsumerControl.reset();
231 archivaConfigControl.reset();
232 configControl.reset();
234 repoScanning.addInvalidContentConsumer( "check-metadata" );
236 recordRepoConsumers();
238 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
239 configControl.expectAndReturn( config.getRepositoryScanning(), repoScanning );
241 config.setRepositoryScanning( repoScanning );
242 configControl.setMatcher( MockControl.ALWAYS_MATCHER );
243 configControl.setVoidCallable();
245 archivaConfig.save( config );
246 archivaConfigControl.setVoidCallable();
248 repoConsumerUtilsControl.replay();
249 knownContentConsumerControl.replay();
250 invalidContentConsumerControl.replay();
251 archivaConfigControl.replay();
252 configControl.replay();
256 boolean success = service.configureRepositoryConsumer( null, "check-metadata", false );
258 repoConsumerUtilsControl.verify();
259 knownContentConsumerControl.verify();
260 invalidContentConsumerControl.verify();
261 archivaConfigControl.verify();
262 configControl.verify();
264 assertTrue( success );
266 catch ( Exception e )
268 fail( "An excecption should not have been thrown." );
273 public void testConfigureInvalidRepositoryConsumer()
276 recordRepoConsumers();
278 repoConsumerUtilsControl.replay();
279 knownContentConsumerControl.replay();
280 invalidContentConsumerControl.replay();
284 service.configureRepositoryConsumer( null, "invalid-consumer", true );
285 fail( "An exception should have been thrown." );
287 catch ( Exception e )
289 assertEquals( "Invalid repository consumer.", e.getMessage() );
292 repoConsumerUtilsControl.verify();
293 knownContentConsumerControl.verify();
294 invalidContentConsumerControl.verify();
297 /* Tests for delete artifact */
299 public void testDeleteM2ArtifactArtifactExists()
302 ManagedRepositoryConfiguration managedRepo = createManagedRepo("default", "default-repo");
304 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
305 configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), managedRepo );
307 ManagedDefaultRepositoryContent repoContent = new ManagedDefaultRepositoryContent();
308 repoContent.setRepository( managedRepo );
310 repoFactoryControl.expectAndReturn( repositoryFactory.getManagedRepositoryContent( "internal" ), repoContent );
312 List<ArtifactMetadata> artifacts = getArtifacts();
313 ArtifactMetadata artifact = artifacts.get( 0 );
315 metadataRepositoryControl.expectAndReturn(
316 metadataRepository.getArtifacts( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
317 artifact.getVersion() ), artifacts );
318 metadataRepository.deleteArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
319 artifact.getVersion(), artifact.getId() );
321 listener.deleteArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
322 artifact.getVersion(), artifact.getId() );
323 listenerControl.setVoidCallable( 1 );
325 archivaConfigControl.replay();
326 configControl.replay();
327 repoFactoryControl.replay();
328 metadataRepositoryControl.replay();
329 listenerControl.replay();
331 boolean success = service.deleteArtifact( "internal", "org.apache.archiva", "archiva-test", "1.0" );
332 assertTrue( success );
334 archivaConfigControl.verify();
335 configControl.verify();
336 repoFactoryControl.verify();
337 metadataRepositoryControl.verify();
338 listenerControl.verify();
340 assertFalse( new File( managedRepo.getLocation(), "org/apache/archiva/archiva-test/1.0" ).exists() );
341 assertTrue( new File( managedRepo.getLocation(), "org/apache/archiva/archiva-test/1.1" ).exists() );
344 public void testDeleteM1ArtifactArtifactExists()
347 MockControl fileTypesControl = MockClassControl.createControl( FileTypes.class );
348 FileTypes fileTypes = ( FileTypes ) fileTypesControl.getMock();
350 MockControl pathParserControl = MockClassControl.createControl( PathParser.class );
351 PathParser parser = ( PathParser ) pathParserControl.getMock();
353 ManagedRepositoryConfiguration managedRepo = createManagedRepo( "legacy", "legacy-repo" );
355 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
356 configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), managedRepo );
358 ManagedLegacyRepositoryContent repoContent = new ManagedLegacyRepositoryContent();
359 repoContent.setRepository( managedRepo );
360 repoContent.setFileTypes( fileTypes );
361 repoContent.setLegacyPathParser( parser );
363 repoFactoryControl.expectAndReturn( repositoryFactory.getManagedRepositoryContent( "internal" ), repoContent );
365 recordInManagedLegacyRepoContent( fileTypesControl, fileTypes, pathParserControl, parser );
367 List<ArtifactMetadata> artifacts = getArtifacts();
368 ArtifactMetadata artifact = artifacts.get( 0 );
370 metadataRepositoryControl.expectAndReturn(
371 metadataRepository.getArtifacts( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
372 artifact.getVersion() ), artifacts );
373 metadataRepository.deleteArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
374 artifact.getVersion(), artifact.getId() );
376 listener.deleteArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
377 artifact.getVersion(), artifact.getId() );
378 listenerControl.setVoidCallable( 1 );
380 archivaConfigControl.replay();
381 configControl.replay();
382 repoFactoryControl.replay();
383 metadataRepositoryControl.replay();
384 listenerControl.replay();
385 fileTypesControl.replay();
386 pathParserControl.replay();
388 boolean success = service.deleteArtifact( "internal", "org.apache.archiva", "archiva-test", "1.0" );
389 assertTrue( success );
391 archivaConfigControl.verify();
392 configControl.verify();
393 repoFactoryControl.verify();
394 metadataRepositoryControl.verify();
395 listenerControl.verify();
396 fileTypesControl.verify();
397 pathParserControl.verify();
399 File repo = new File( managedRepo.getLocation() );
400 assertFalse( new File( repo, "org.apache.archiva/jars/archiva-test-1.0.jar" ).exists() );
401 assertFalse( new File( repo, "org.apache.archiva/poms/archiva-test-1.0.pom" ).exists() );
403 assertTrue( new File( repo, "org.apache.archiva/jars/archiva-test-1.1.jar" ).exists() );
404 assertTrue( new File( repo, "org.apache.archiva/jars/archiva-diff-1.0.jar" ).exists() );
405 assertTrue( new File( repo, "org.apache.archiva/poms/archiva-test-1.1.pom" ).exists() );
406 assertTrue( new File( repo, "org.apache.archiva/poms/archiva-diff-1.0.pom" ).exists() );
409 public void testDeleteArtifactArtifactDoesNotExist()
412 ManagedRepositoryConfiguration managedRepo = createManagedRepo("default", "default-repo");
414 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
415 configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), managedRepo );
417 ManagedDefaultRepositoryContent repoContent = new ManagedDefaultRepositoryContent();
418 repoContent.setRepository( managedRepo );
420 repoFactoryControl.expectAndReturn( repositoryFactory.getManagedRepositoryContent( "internal" ), repoContent );
422 archivaConfigControl.replay();
423 configControl.replay();
424 repoFactoryControl.replay();
428 service.deleteArtifact( "internal", "org.apache.archiva", "archiva-non-existing", "1.0" );
429 fail( "An exception should have been thrown." );
431 catch ( Exception e )
433 assertEquals( "Artifact does not exist.", e.getMessage() );
436 archivaConfigControl.verify();
437 configControl.verify();
438 repoFactoryControl.verify();
441 private ManagedRepositoryConfiguration createManagedRepo(String layout, String directory)
444 File srcDir = new File( getBasedir(), "src/test/repositories/"+ directory );
446 File repoDir = getTestFile( "target/test-repos/" + directory );
448 FileUtils.deleteDirectory( repoDir );
450 FileUtils.copyDirectory( srcDir, repoDir, FileFilterUtils.makeSVNAware( null ) );
452 ManagedRepositoryConfiguration managedRepo =
453 createManagedRepo( "internal", layout, "Internal Repository", true, false );
454 managedRepo.setLocation( repoDir.getAbsolutePath() );
458 public void testDeleteArtifacRepositoryDoesNotExist()
461 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
462 configControl.expectAndReturn( config.findManagedRepositoryById( "non-existing-repo" ), null );
464 archivaConfigControl.replay();
465 configControl.replay();
469 service.deleteArtifact( "non-existing-repo", "org.apache.archiva", "archiva-test", "1.0" );
470 fail( "An exception should have been thrown." );
472 catch ( Exception e )
474 assertEquals( "Repository does not exist.", e.getMessage() );
477 archivaConfigControl.verify();
478 configControl.verify();
481 /* Tests for repository scanning */
483 public void testExecuteRepoScannerRepoExistsAndNotBeingScanned()
486 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
487 configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ),
488 createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
490 RepositoryTask task = new RepositoryTask();
492 repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( "internal" ), false );
494 repositoryTaskScheduler.queueTask( task );
495 repositoryTaskSchedulerControl.setMatcher( MockControl.ALWAYS_MATCHER );
496 repositoryTaskSchedulerControl.setVoidCallable();
498 archivaConfigControl.replay();
499 configControl.replay();
500 repositoryTaskSchedulerControl.replay();
504 boolean success = service.executeRepositoryScanner( "internal" );
505 assertTrue( success );
507 catch ( Exception e )
509 fail( "An exception should not have been thrown." );
512 archivaConfigControl.verify();
513 configControl.verify();
514 repositoryTaskSchedulerControl.verify();
517 public void testExecuteRepoScannerRepoExistsButBeingScanned()
520 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
521 configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ),
522 createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
524 repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( "internal" ), true);
526 archivaConfigControl.replay();
527 configControl.replay();
528 repositoryTaskSchedulerControl.replay();
532 boolean success = service.executeRepositoryScanner( "internal" );
533 assertFalse( success );
535 catch ( Exception e )
537 fail( "An exception should not have been thrown." );
540 archivaConfigControl.verify();
541 configControl.verify();
542 repositoryTaskSchedulerControl.verify();
545 public void testExecuteRepoScannerRepoDoesNotExist()
548 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
549 configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), null );
551 archivaConfigControl.replay();
552 configControl.replay();
556 service.executeRepositoryScanner( "internal" );
557 fail( "An exception should have been thrown." );
559 catch ( Exception e )
561 assertEquals( "Repository does not exist.", e.getMessage() );
564 archivaConfigControl.verify();
565 configControl.verify();
568 /* Tests for querying repositories */
570 public void testGetAllManagedRepositories()
573 List<ManagedRepositoryConfiguration> managedRepos = new ArrayList<ManagedRepositoryConfiguration>();
574 managedRepos.add( createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
575 managedRepos.add( createManagedRepo( "snapshots", "default", "Snapshots Repository", false, true ) );
577 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
578 configControl.expectAndReturn( config.getManagedRepositories(), managedRepos );
580 archivaConfigControl.replay();
581 configControl.replay();
583 List<ManagedRepository> repos = service.getAllManagedRepositories();
585 archivaConfigControl.verify();
586 configControl.verify();
588 assertNotNull( repos );
589 assertEquals( 2, repos.size() );
591 assertManagedRepo( repos.get( 0 ), managedRepos.get( 0 ) );
592 assertManagedRepo( repos.get( 1 ), managedRepos.get( 1 ) );
595 public void testGetAllRemoteRepositories()
598 List<RemoteRepositoryConfiguration> remoteRepos = new ArrayList<RemoteRepositoryConfiguration>();
599 remoteRepos.add( createRemoteRepository( "central", "Central Repository", "default", "http://repo1.maven.org/maven2") );
600 remoteRepos.add( createRemoteRepository( "dummy", "Dummy Remote Repository", "legacy", "http://dummy.com/dummy") );
602 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
603 configControl.expectAndReturn( config.getRemoteRepositories(), remoteRepos );
605 archivaConfigControl.replay();
606 configControl.replay();
608 List<RemoteRepository> repos = service.getAllRemoteRepositories();
610 archivaConfigControl.verify();
611 configControl.verify();
613 assertNotNull( repos );
614 assertEquals( 2, repos.size() );
616 assertRemoteRepo( repos.get( 0 ), remoteRepos.get( 0 ) );
617 assertRemoteRepo( repos.get( 1 ), remoteRepos.get( 1 ) );
620 /* private methods */
622 private void assertRemoteRepo( RemoteRepository remoteRepo, RemoteRepositoryConfiguration expectedRepoConfig )
624 assertEquals( expectedRepoConfig.getId(), remoteRepo.getId() );
625 assertEquals( expectedRepoConfig.getLayout(), remoteRepo.getLayout() );
626 assertEquals( expectedRepoConfig.getName(), remoteRepo.getName() );
627 assertEquals( expectedRepoConfig.getUrl(), remoteRepo.getUrl() );
630 private RemoteRepositoryConfiguration createRemoteRepository(String id, String name, String layout, String url)
632 RemoteRepositoryConfiguration remoteConfig = new RemoteRepositoryConfiguration();
633 remoteConfig.setId( id );
634 remoteConfig.setName( name );
635 remoteConfig.setLayout( layout );
636 remoteConfig.setUrl( url );
641 private void assertManagedRepo( ManagedRepository managedRepo, ManagedRepositoryConfiguration expectedRepoConfig )
643 assertEquals( expectedRepoConfig.getId(), managedRepo.getId() );
644 assertEquals( expectedRepoConfig.getLayout(), managedRepo.getLayout() );
645 assertEquals( expectedRepoConfig.getName(), managedRepo.getName() );
647 //TODO enable assert once fixed in AdministrationServiceImpl!
648 //assertEquals( "http://localhost:8080/archiva/repository/" + expectedRepoConfig.getId(), managedRepo.getUrl() );
649 assertEquals( expectedRepoConfig.isReleases(), managedRepo.isReleases() );
650 assertEquals( expectedRepoConfig.isSnapshots(), managedRepo.isSnapshots() );
653 private ManagedRepositoryConfiguration createManagedRepo( String id, String layout, String name,
654 boolean hasReleases, boolean hasSnapshots )
656 ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
657 repoConfig.setId( id );
658 repoConfig.setLayout( layout );
659 repoConfig.setName( name );
660 repoConfig.setReleases( hasReleases );
661 repoConfig.setSnapshots( hasSnapshots );
666 private void recordRepoConsumers()
668 List<KnownRepositoryContentConsumer> availableKnownConsumers = new ArrayList<KnownRepositoryContentConsumer>();
669 availableKnownConsumers.add( indexArtifactConsumer );
670 availableKnownConsumers.add( indexPomConsumer );
672 List<InvalidRepositoryContentConsumer> availableInvalidConsumers = new ArrayList<InvalidRepositoryContentConsumer>();
673 availableInvalidConsumers.add( checkPomConsumer );
674 availableInvalidConsumers.add( checkMetadataConsumer );
676 repoConsumerUtilsControl.expectAndReturn( repoConsumersUtil.getAvailableKnownConsumers(), availableKnownConsumers );
677 knownContentConsumerControl.expectAndReturn( indexArtifactConsumer.getId(), "index-artifact" );
678 knownContentConsumerControl.expectAndReturn( indexPomConsumer.getId(), "index-pom" );
680 repoConsumerUtilsControl.expectAndReturn( repoConsumersUtil.getAvailableInvalidConsumers(), availableInvalidConsumers );
681 invalidContentConsumerControl.expectAndReturn( checkPomConsumer.getId(), "check-pom" );
682 invalidContentConsumerControl.expectAndReturn( checkMetadataConsumer.getId(), "check-metadata" );
685 private void recordInManagedLegacyRepoContent( MockControl fileTypesControl, FileTypes fileTypes,
686 MockControl pathParserControl, PathParser parser )
687 throws LayoutException
689 String sep = File.separator;
690 String ad10p = "org.apache.archiva" + sep + "poms" + sep + "archiva-diff-1.0.pom";
691 String at10p = "org.apache.archiva" + sep + "poms" + sep + "archiva-test-1.0.pom";
692 String at11p = "org.apache.archiva" + sep + "poms" + sep + "archiva-test-1.1.pom";
693 String ad10j = "org.apache.archiva" + sep + "jars" + sep + "archiva-diff-1.0.jar";
694 String at10j = "org.apache.archiva" + sep + "jars" + sep + "archiva-test-1.0.jar";
695 String at11j = "org.apache.archiva" + sep + "jars" + sep + "archiva-test-1.1.jar";
697 fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( at10p ), true );
698 fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( at11p ), true );
699 fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( ad10p ), true );
700 fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( ad10j ), true );
701 fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( at10j ), true );
702 fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( at11j ), true );
704 ArtifactReference aRef = createArtifactReference("archiva-test", "org.apache.archiva", "1.1", "pom");
705 pathParserControl.expectAndReturn( parser.toArtifactReference( at11p ), aRef );
707 aRef = createArtifactReference("archiva-test", "org.apache.archiva", "1.0", "pom");
708 pathParserControl.expectAndReturn( parser.toArtifactReference( at10p ), aRef );
710 aRef = createArtifactReference("archiva-diff", "org.apache.archiva", "1.0", "pom");
711 pathParserControl.expectAndReturn( parser.toArtifactReference( ad10p ), aRef );
713 aRef = createArtifactReference("archiva-diff", "org.apache.archiva", "1.0", "jar");
714 pathParserControl.expectAndReturn( parser.toArtifactReference( ad10j ), aRef );
716 aRef = createArtifactReference("archiva-test", "org.apache.archiva", "1.0", "jar");
717 pathParserControl.expectAndReturn( parser.toArtifactReference( at10j ), aRef );
719 aRef = createArtifactReference("archiva-test", "org.apache.archiva", "1.1", "jar");
720 pathParserControl.expectAndReturn( parser.toArtifactReference( at11j ), aRef );
723 private List<ArtifactMetadata> getArtifacts()
725 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>();
727 ArtifactMetadata artifact = new ArtifactMetadata();
728 artifact.setId( "archiva-test-1.0.jar" );
729 artifact.setProject( "archiva-test" );
730 artifact.setVersion( "1.0" );
731 artifact.setProjectVersion( "1.0" );
732 artifact.setNamespace( "org.apache.archiva" );
733 artifact.setRepositoryId( "internal" );
734 artifacts.add( artifact );
738 private ArtifactReference createArtifactReference( String artifactId, String groupId, String version, String type )
740 ArtifactReference aRef = new ArtifactReference();
741 aRef.setArtifactId( artifactId );
742 aRef.setGroupId( groupId );
743 aRef.setType( type );
744 aRef.setVersion( version );