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 junit.framework.TestCase;
23 import org.apache.archiva.admin.repository.RepositoryCommonValidator;
24 import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
25 import org.apache.archiva.admin.repository.remote.DefaultRemoteRepositoryAdmin;
26 import org.apache.archiva.audit.AuditEvent;
27 import org.apache.archiva.audit.AuditListener;
28 import org.apache.archiva.metadata.model.ArtifactMetadata;
29 import org.apache.archiva.metadata.repository.MetadataRepository;
30 import org.apache.archiva.metadata.repository.RepositorySession;
31 import org.apache.archiva.metadata.repository.RepositorySessionFactory;
32 import org.apache.archiva.metadata.repository.filter.Filter;
33 import org.apache.archiva.metadata.repository.filter.IncludesFilter;
34 import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
35 import org.apache.archiva.repository.events.RepositoryListener;
36 import org.apache.archiva.repository.scanner.RepositoryContentConsumers;
37 import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler;
38 import org.apache.archiva.scheduler.repository.RepositoryTask;
39 import org.apache.archiva.security.ArchivaRoleConstants;
40 import org.apache.archiva.stagerepository.merge.RepositoryMerger;
41 import org.apache.archiva.web.xmlrpc.api.beans.ManagedRepository;
42 import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository;
43 import org.apache.commons.io.FileUtils;
44 import org.apache.commons.io.filefilter.FileFilterUtils;
45 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
46 import org.apache.maven.archiva.configuration.Configuration;
47 import org.apache.maven.archiva.configuration.FileTypes;
48 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
49 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
50 import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration;
51 import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
52 import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
53 import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
54 import org.apache.maven.archiva.model.ArtifactReference;
55 import org.apache.maven.archiva.repository.RepositoryContentFactory;
56 import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent;
57 import org.apache.maven.archiva.repository.content.ManagedLegacyRepositoryContent;
58 import org.apache.maven.archiva.repository.content.PathParser;
59 import org.apache.maven.archiva.repository.layout.LayoutException;
60 import org.codehaus.plexus.redback.role.RoleManager;
61 import org.codehaus.plexus.registry.Registry;
62 import org.easymock.MockControl;
63 import org.easymock.classextension.MockClassControl;
64 import org.junit.Before;
65 import org.junit.Test;
66 import org.junit.runner.RunWith;
67 import org.springframework.context.ApplicationContext;
68 import org.springframework.test.context.ContextConfiguration;
69 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
72 import java.io.IOException;
73 import java.util.ArrayList;
74 import java.util.Arrays;
75 import java.util.Collections;
76 import java.util.Date;
77 import java.util.HashMap;
78 import java.util.List;
81 import static org.mockito.Mockito.mock;
82 import static org.mockito.Mockito.when;
85 * AdministrationServiceImplTest
87 * @version $Id: AdministrationServiceImplTest.java
89 @RunWith( SpringJUnit4ClassRunner.class )
90 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
91 public class AdministrationServiceImplTest
94 private MockControl archivaConfigControl;
96 private ArchivaConfiguration archivaConfig;
98 private MockControl configControl;
100 private Configuration config;
102 private AdministrationServiceImpl service;
104 private MockControl repositoryTaskSchedulerControl;
106 private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
108 // repository consumers
109 private MockControl repoConsumerUtilsControl;
111 private RepositoryContentConsumers repoConsumersUtil;
113 private MockControl knownContentConsumerControl;
115 private MockControl invalidContentConsumerControl;
117 private KnownRepositoryContentConsumer indexArtifactConsumer;
119 private KnownRepositoryContentConsumer indexPomConsumer;
121 private InvalidRepositoryContentConsumer checkPomConsumer;
123 private InvalidRepositoryContentConsumer checkMetadataConsumer;
126 private MockControl repoFactoryControl;
128 private RepositoryContentFactory repositoryFactory;
130 private MockControl listenerControl;
132 private RepositoryListener listener;
134 private MockControl metadataRepositoryControl;
136 private MetadataRepository metadataRepository;
138 private MockControl repositoryStatisticsManagerControl;
140 private RepositoryStatisticsManager repositoryStatisticsManager;
142 private MockControl repositoryMergerControl;
144 private RepositoryMerger repositoryMerger;
146 private MockControl auditListenerControl;
148 private AuditListener auditListener;
150 private MockControl roleManagerControl;
152 private RoleManager roleManager;
154 private MockControl registryControl;
156 private Registry registry;
158 private static final String STAGE = "-stage";
160 private DefaultManagedRepositoryAdmin managedRepositoryAdmin;
162 private DefaultRemoteRepositoryAdmin remoteRepositoryAdmin;
164 private ApplicationContext applicationContext;
172 archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class );
173 archivaConfig = (ArchivaConfiguration) archivaConfigControl.getMock();
175 configControl = MockClassControl.createControl( Configuration.class );
176 config = (Configuration) configControl.getMock();
178 repositoryTaskSchedulerControl = MockClassControl.createControl( RepositoryArchivaTaskScheduler.class );
179 repositoryTaskScheduler = (RepositoryArchivaTaskScheduler) repositoryTaskSchedulerControl.getMock();
182 repoConsumerUtilsControl = MockClassControl.createControl( RepositoryContentConsumers.class );
183 repoConsumersUtil = (RepositoryContentConsumers) repoConsumerUtilsControl.getMock();
185 knownContentConsumerControl = MockControl.createControl( KnownRepositoryContentConsumer.class );
186 indexArtifactConsumer = (KnownRepositoryContentConsumer) knownContentConsumerControl.getMock();
187 indexPomConsumer = (KnownRepositoryContentConsumer) knownContentConsumerControl.getMock();
189 invalidContentConsumerControl = MockControl.createControl( InvalidRepositoryContentConsumer.class );
190 checkPomConsumer = (InvalidRepositoryContentConsumer) invalidContentConsumerControl.getMock();
191 checkMetadataConsumer = (InvalidRepositoryContentConsumer) invalidContentConsumerControl.getMock();
194 repoFactoryControl = MockClassControl.createControl( RepositoryContentFactory.class );
195 repositoryFactory = (RepositoryContentFactory) repoFactoryControl.getMock();
197 metadataRepositoryControl = MockControl.createControl( MetadataRepository.class );
198 metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock();
200 RepositorySession repositorySession = mock( RepositorySession.class );
201 when( repositorySession.getRepository() ).thenReturn( metadataRepository );
203 RepositorySessionFactory repositorySessionFactory = mock( RepositorySessionFactory.class );
204 when( repositorySessionFactory.createSession() ).thenReturn( repositorySession );
206 listenerControl = MockControl.createControl( RepositoryListener.class );
207 listener = (RepositoryListener) listenerControl.getMock();
209 roleManagerControl = MockControl.createControl( RoleManager.class );
210 roleManager = (RoleManager) roleManagerControl.getMock();
212 repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class );
213 repositoryStatisticsManager = (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock();
215 repositoryMergerControl = MockControl.createControl( RepositoryMerger.class );
216 repositoryMerger = (RepositoryMerger) repositoryMergerControl.getMock();
218 auditListenerControl = MockControl.createControl( AuditListener.class );
219 auditListener = (AuditListener) auditListenerControl.getMock();
221 registryControl = MockControl.createControl( Registry.class );
222 registry = (Registry) registryControl.getMock();
224 managedRepositoryAdmin = new DefaultManagedRepositoryAdmin();
225 managedRepositoryAdmin.setArchivaConfiguration( archivaConfig );
226 managedRepositoryAdmin.setRegistry( registry );
227 managedRepositoryAdmin.setRepositoryStatisticsManager( repositoryStatisticsManager );
228 managedRepositoryAdmin.setRepositoryTaskScheduler( repositoryTaskScheduler );
229 managedRepositoryAdmin.setRepositorySessionFactory( repositorySessionFactory );
230 managedRepositoryAdmin.setAuditListeners( Arrays.asList( auditListener ) );
231 managedRepositoryAdmin.setRoleManager( roleManager );
233 RepositoryCommonValidator repositoryCommonValidator = new RepositoryCommonValidator();
234 repositoryCommonValidator.setArchivaConfiguration( archivaConfig );
235 repositoryCommonValidator.setRegistry( registry );
237 managedRepositoryAdmin.setRepositoryCommonValidator( repositoryCommonValidator );
239 remoteRepositoryAdmin = new DefaultRemoteRepositoryAdmin();
240 remoteRepositoryAdmin.setArchivaConfiguration( archivaConfig );
241 remoteRepositoryAdmin.setAuditListeners( Arrays.asList( auditListener ) );
243 remoteRepositoryAdmin.setRepositoryCommonValidator( repositoryCommonValidator );
245 service = new AdministrationServiceImpl( archivaConfig, repoConsumersUtil, repositoryFactory,
246 repositorySessionFactory, repositoryTaskScheduler,
247 Collections.singletonList( listener ), repositoryStatisticsManager,
248 repositoryMerger, auditListener, managedRepositoryAdmin,
249 remoteRepositoryAdmin );
252 /* Tests for repository consumers */
254 public void testGetAllRepoConsumers()
257 recordRepoConsumers();
259 repoConsumerUtilsControl.replay();
260 knownContentConsumerControl.replay();
261 invalidContentConsumerControl.replay();
263 List<String> repoConsumers = service.getAllRepositoryConsumers();
265 repoConsumerUtilsControl.verify();
266 knownContentConsumerControl.verify();
267 invalidContentConsumerControl.verify();
269 assertNotNull( repoConsumers );
270 assertEquals( 4, repoConsumers.size() );
271 assertTrue( repoConsumers.contains( "index-artifact" ) );
272 assertTrue( repoConsumers.contains( "index-pom" ) );
273 assertTrue( repoConsumers.contains( "check-pom" ) );
274 assertTrue( repoConsumers.contains( "check-metadata" ) );
278 public void testConfigureValidRepositoryConsumer()
281 RepositoryScanningConfiguration repoScanning = new RepositoryScanningConfiguration();
282 repoScanning.addKnownContentConsumer( "index-artifact" );
283 repoScanning.addKnownContentConsumer( "index-pom" );
284 repoScanning.addInvalidContentConsumer( "check-pom" );
286 // test enable "check-metadata" consumer
287 recordRepoConsumers();
289 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
290 configControl.expectAndReturn( config.getRepositoryScanning(), repoScanning );
292 config.setRepositoryScanning( repoScanning );
293 configControl.setMatcher( MockControl.ALWAYS_MATCHER );
294 configControl.setVoidCallable();
296 archivaConfig.save( config );
297 archivaConfigControl.setVoidCallable();
299 repoConsumerUtilsControl.replay();
300 knownContentConsumerControl.replay();
301 invalidContentConsumerControl.replay();
302 archivaConfigControl.replay();
303 configControl.replay();
307 boolean success = service.configureRepositoryConsumer( null, "check-metadata", true );
308 assertTrue( success );
310 catch ( Exception e )
312 fail( "An exception should not have been thrown." );
315 repoConsumerUtilsControl.verify();
316 knownContentConsumerControl.verify();
317 invalidContentConsumerControl.verify();
318 archivaConfigControl.verify();
319 configControl.verify();
321 // test disable "check-metadata" consumer
322 repoConsumerUtilsControl.reset();
323 knownContentConsumerControl.reset();
324 invalidContentConsumerControl.reset();
325 archivaConfigControl.reset();
326 configControl.reset();
328 repoScanning.addInvalidContentConsumer( "check-metadata" );
330 recordRepoConsumers();
332 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
333 configControl.expectAndReturn( config.getRepositoryScanning(), repoScanning );
335 config.setRepositoryScanning( repoScanning );
336 configControl.setMatcher( MockControl.ALWAYS_MATCHER );
337 configControl.setVoidCallable();
339 archivaConfig.save( config );
340 archivaConfigControl.setVoidCallable();
342 repoConsumerUtilsControl.replay();
343 knownContentConsumerControl.replay();
344 invalidContentConsumerControl.replay();
345 archivaConfigControl.replay();
346 configControl.replay();
350 boolean success = service.configureRepositoryConsumer( null, "check-metadata", false );
352 repoConsumerUtilsControl.verify();
353 knownContentConsumerControl.verify();
354 invalidContentConsumerControl.verify();
355 archivaConfigControl.verify();
356 configControl.verify();
358 assertTrue( success );
360 catch ( Exception e )
362 fail( "An excecption should not have been thrown." );
367 public void testConfigureInvalidRepositoryConsumer()
370 recordRepoConsumers();
372 repoConsumerUtilsControl.replay();
373 knownContentConsumerControl.replay();
374 invalidContentConsumerControl.replay();
378 service.configureRepositoryConsumer( null, "invalid-consumer", true );
379 fail( "An exception should have been thrown." );
381 catch ( Exception e )
383 assertEquals( "Invalid repository consumer.", e.getMessage() );
386 repoConsumerUtilsControl.verify();
387 knownContentConsumerControl.verify();
388 invalidContentConsumerControl.verify();
391 /* Tests for delete artifact */
393 public void testDeleteM2ArtifactArtifactExists()
396 ManagedRepositoryConfiguration managedRepo = createManagedRepo( "default", "default-repo" );
398 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
399 configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), managedRepo );
401 ManagedDefaultRepositoryContent repoContent = new ManagedDefaultRepositoryContent();
402 repoContent.setRepository( managedRepo );
404 repoFactoryControl.expectAndReturn( repositoryFactory.getManagedRepositoryContent( "internal" ), repoContent );
406 List<ArtifactMetadata> artifacts = getArtifacts();
407 ArtifactMetadata artifact = artifacts.get( 0 );
409 metadataRepositoryControl.expectAndReturn(
410 metadataRepository.getArtifacts( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
411 artifact.getVersion() ), artifacts );
412 metadataRepository.removeArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
413 artifact.getVersion(), artifact.getId() );
415 listener.deleteArtifact( metadataRepository, repoContent.getId(), artifact.getNamespace(),
416 artifact.getProject(), artifact.getVersion(), artifact.getId() );
417 listenerControl.setVoidCallable( 1 );
419 archivaConfigControl.replay();
420 configControl.replay();
421 repoFactoryControl.replay();
422 metadataRepositoryControl.replay();
423 listenerControl.replay();
425 boolean success = service.deleteArtifact( "internal", "org.apache.archiva", "archiva-test", "1.0" );
426 assertTrue( success );
428 archivaConfigControl.verify();
429 configControl.verify();
430 repoFactoryControl.verify();
431 metadataRepositoryControl.verify();
432 listenerControl.verify();
434 assertFalse( new File( managedRepo.getLocation(), "org/apache/archiva/archiva-test/1.0" ).exists() );
435 assertTrue( new File( managedRepo.getLocation(), "org/apache/archiva/archiva-test/1.1" ).exists() );
439 public void testDeleteM1ArtifactArtifactExists()
442 MockControl fileTypesControl = MockClassControl.createControl( FileTypes.class );
443 FileTypes fileTypes = (FileTypes) fileTypesControl.getMock();
445 MockControl pathParserControl = MockClassControl.createControl( PathParser.class );
446 PathParser parser = (PathParser) pathParserControl.getMock();
448 ManagedRepositoryConfiguration managedRepo = createManagedRepo( "legacy", "legacy-repo" );
450 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
451 configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), managedRepo );
453 ManagedLegacyRepositoryContent repoContent = new ManagedLegacyRepositoryContent();
454 repoContent.setRepository( managedRepo );
455 repoContent.setFileTypes( fileTypes );
456 repoContent.setLegacyPathParser( parser );
458 repoFactoryControl.expectAndReturn( repositoryFactory.getManagedRepositoryContent( "internal" ), repoContent );
460 recordInManagedLegacyRepoContent( fileTypesControl, fileTypes, pathParserControl, parser );
462 List<ArtifactMetadata> artifacts = getArtifacts();
463 ArtifactMetadata artifact = artifacts.get( 0 );
465 metadataRepositoryControl.expectAndReturn(
466 metadataRepository.getArtifacts( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
467 artifact.getVersion() ), artifacts );
468 metadataRepository.removeArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
469 artifact.getVersion(), artifact.getId() );
471 listener.deleteArtifact( metadataRepository, repoContent.getId(), artifact.getNamespace(),
472 artifact.getProject(), artifact.getVersion(), artifact.getId() );
473 listenerControl.setVoidCallable( 1 );
475 archivaConfigControl.replay();
476 configControl.replay();
477 repoFactoryControl.replay();
478 metadataRepositoryControl.replay();
479 listenerControl.replay();
480 fileTypesControl.replay();
481 pathParserControl.replay();
483 boolean success = service.deleteArtifact( "internal", "org.apache.archiva", "archiva-test", "1.0" );
484 assertTrue( success );
486 archivaConfigControl.verify();
487 configControl.verify();
488 repoFactoryControl.verify();
489 metadataRepositoryControl.verify();
490 listenerControl.verify();
491 fileTypesControl.verify();
492 pathParserControl.verify();
494 File repo = new File( managedRepo.getLocation() );
495 assertFalse( new File( repo, "org.apache.archiva/jars/archiva-test-1.0.jar" ).exists() );
496 assertFalse( new File( repo, "org.apache.archiva/poms/archiva-test-1.0.pom" ).exists() );
498 assertTrue( new File( repo, "org.apache.archiva/jars/archiva-test-1.1.jar" ).exists() );
499 assertTrue( new File( repo, "org.apache.archiva/jars/archiva-diff-1.0.jar" ).exists() );
500 assertTrue( new File( repo, "org.apache.archiva/poms/archiva-test-1.1.pom" ).exists() );
501 assertTrue( new File( repo, "org.apache.archiva/poms/archiva-diff-1.0.pom" ).exists() );
505 public void testDeleteArtifactArtifactDoesNotExist()
508 ManagedRepositoryConfiguration managedRepo = createManagedRepo( "default", "default-repo" );
510 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
511 configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), managedRepo );
513 ManagedDefaultRepositoryContent repoContent = new ManagedDefaultRepositoryContent();
514 repoContent.setRepository( managedRepo );
516 repoFactoryControl.expectAndReturn( repositoryFactory.getManagedRepositoryContent( "internal" ), repoContent );
518 archivaConfigControl.replay();
519 configControl.replay();
520 repoFactoryControl.replay();
524 service.deleteArtifact( "internal", "org.apache.archiva", "archiva-non-existing", "1.0" );
525 fail( "An exception should have been thrown." );
527 catch ( Exception e )
529 assertEquals( "Artifact does not exist.", e.getMessage() );
532 archivaConfigControl.verify();
533 configControl.verify();
534 repoFactoryControl.verify();
537 private ManagedRepositoryConfiguration createManagedRepo( String layout, String directory )
540 File srcDir = new File( "src/test/repositories/" + directory );
542 File repoDir = new File( "target/test-repos/" + directory );
544 FileUtils.deleteDirectory( repoDir );
546 FileUtils.copyDirectory( srcDir, repoDir, FileFilterUtils.makeSVNAware( null ) );
548 ManagedRepositoryConfiguration managedRepo =
549 createManagedRepo( "internal", layout, "Internal Repository", true, false );
550 managedRepo.setLocation( repoDir.getAbsolutePath() );
555 public void testDeleteArtifacRepositoryDoesNotExist()
558 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
559 configControl.expectAndReturn( config.findManagedRepositoryById( "non-existing-repo" ), null );
561 archivaConfigControl.replay();
562 configControl.replay();
566 service.deleteArtifact( "non-existing-repo", "org.apache.archiva", "archiva-test", "1.0" );
567 fail( "An exception should have been thrown." );
569 catch ( Exception e )
571 assertEquals( "Repository does not exist.", e.getMessage() );
574 archivaConfigControl.verify();
575 configControl.verify();
578 /* Tests for repository scanning */
580 public void testExecuteRepoScannerRepoExistsAndNotBeingScanned()
583 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
584 configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ),
585 createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
587 RepositoryTask task = new RepositoryTask();
589 repositoryTaskSchedulerControl.expectAndReturn(
590 repositoryTaskScheduler.isProcessingRepositoryTask( "internal" ), false );
592 repositoryTaskScheduler.queueTask( task );
593 repositoryTaskSchedulerControl.setMatcher( MockControl.ALWAYS_MATCHER );
594 repositoryTaskSchedulerControl.setVoidCallable();
596 archivaConfigControl.replay();
597 configControl.replay();
598 repositoryTaskSchedulerControl.replay();
602 boolean success = service.executeRepositoryScanner( "internal" );
603 assertTrue( success );
605 catch ( Exception e )
607 fail( "An exception should not have been thrown." );
610 archivaConfigControl.verify();
611 configControl.verify();
612 repositoryTaskSchedulerControl.verify();
616 public void testExecuteRepoScannerRepoExistsButBeingScanned()
619 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
620 configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ),
621 createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
623 repositoryTaskSchedulerControl.expectAndReturn(
624 repositoryTaskScheduler.isProcessingRepositoryTask( "internal" ), true );
626 archivaConfigControl.replay();
627 configControl.replay();
628 repositoryTaskSchedulerControl.replay();
632 boolean success = service.executeRepositoryScanner( "internal" );
633 assertFalse( success );
635 catch ( Exception e )
637 fail( "An exception should not have been thrown." );
640 archivaConfigControl.verify();
641 configControl.verify();
642 repositoryTaskSchedulerControl.verify();
646 public void testExecuteRepoScannerRepoDoesNotExist()
649 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
650 configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), null );
652 archivaConfigControl.replay();
653 configControl.replay();
657 service.executeRepositoryScanner( "internal" );
658 fail( "An exception should have been thrown." );
660 catch ( Exception e )
662 assertEquals( "Repository does not exist.", e.getMessage() );
665 archivaConfigControl.verify();
666 configControl.verify();
669 /* Tests for querying repositories */
671 public void testGetAllManagedRepositories()
674 List<ManagedRepositoryConfiguration> managedRepos = new ArrayList<ManagedRepositoryConfiguration>();
675 managedRepos.add( createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
676 managedRepos.add( createManagedRepo( "snapshots", "default", "Snapshots Repository", false, true ) );
678 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
679 configControl.expectAndReturn( config.getManagedRepositories(), managedRepos );
681 archivaConfigControl.replay();
682 configControl.replay();
684 List<ManagedRepository> repos = service.getAllManagedRepositories();
686 archivaConfigControl.verify();
687 configControl.verify();
689 assertNotNull( repos );
690 assertEquals( 2, repos.size() );
692 assertManagedRepo( repos.get( 0 ), managedRepos.get( 0 ) );
693 assertManagedRepo( repos.get( 1 ), managedRepos.get( 1 ) );
697 public void testGetAllRemoteRepositories()
700 List<RemoteRepositoryConfiguration> remoteRepos = new ArrayList<RemoteRepositoryConfiguration>();
702 createRemoteRepository( "central", "Central Repository", "default", "http://repo1.maven.org/maven2" ) );
704 createRemoteRepository( "dummy", "Dummy Remote Repository", "legacy", "http://dummy.com/dummy" ) );
706 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
707 configControl.expectAndReturn( config.getRemoteRepositories(), remoteRepos );
709 archivaConfigControl.replay();
710 configControl.replay();
712 List<RemoteRepository> repos = service.getAllRemoteRepositories();
714 archivaConfigControl.verify();
715 configControl.verify();
717 assertNotNull( repos );
718 assertEquals( 2, repos.size() );
720 assertRemoteRepo( repos.get( 0 ), remoteRepos.get( 0 ) );
721 assertRemoteRepo( repos.get( 1 ), remoteRepos.get( 1 ) );
725 public void testDeleteInvalidRepositoryContent()
727 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
728 configControl.expectAndReturn( config.findManagedRepositoryById( "invalid" ), null );
730 archivaConfigControl.replay();
731 configControl.replay();
735 service.deleteManagedRepositoryContent( "invalid" );
737 catch ( Exception e )
739 assertEquals( "Repository Id : invalid not found.", e.getMessage() );
742 archivaConfigControl.verify();
743 configControl.verify();
747 public void testDeleteRepositoryContent()
750 ManagedRepositoryConfiguration managedRepo = createManagedRepo( "default", "default-repo" );
751 assertTrue( new File( managedRepo.getLocation(), "org" ).exists() );
753 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
754 configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), managedRepo );
755 metadataRepository.removeRepository( "internal" );
757 archivaConfigControl.replay();
758 configControl.replay();
759 metadataRepositoryControl.replay();
761 boolean success = service.deleteManagedRepositoryContent( "internal" );
762 assertTrue( success );
764 archivaConfigControl.verify();
765 configControl.verify();
766 metadataRepositoryControl.verify();
768 assertFalse( new File( managedRepo.getLocation(), "org" ).exists() );
769 assertTrue( new File( managedRepo.getLocation() ).exists() );
774 public void testMergeRepositoryWithInvalidRepository()
777 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
778 configControl.expectAndReturn( config.findManagedRepositoryById( "invalid" ), null );
780 archivaConfigControl.replay();
781 configControl.replay();
785 service.merge( "invalid", true );
787 catch ( Exception e )
789 assertEquals( "Repository Id : invalid not found.", e.getMessage() );
792 archivaConfigControl.verify();
793 configControl.verify();
797 public void testMergeWithNoStagingRepository()
800 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
801 configControl.expectAndReturn( config.findManagedRepositoryById( "repo" ),
802 createManagedRepo( "repo", "default", "repo", true, false ) );
803 configControl.expectAndReturn( config.findManagedRepositoryById( "repo-stage" ), null );
805 archivaConfigControl.replay();
806 configControl.replay();
810 service.merge( "repo", true );
812 catch ( Exception e )
814 assertEquals( "Staging Id : repo-stage not found.", e.getMessage() );
817 archivaConfigControl.verify();
818 configControl.verify();
822 public void testMergeRepositoriesAndScan()
825 List<ArtifactMetadata> sources = new ArrayList<ArtifactMetadata>();
827 ArtifactMetadata artifact = new ArtifactMetadata();
828 artifact.setId( "artifact" );
829 artifact.setFileLastModified( System.currentTimeMillis() );
831 sources.add( artifact );
833 ManagedRepositoryConfiguration merge = createManagedRepo( "merge", "default", "merge", true, true );
834 merge.setLocation( "target/test-repository/merge" );
835 ManagedRepositoryConfiguration staging = createStagingRepo( merge );
837 RepositoryTask task = new RepositoryTask();
838 task.setScanAll( true );
840 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
841 configControl.expectAndReturn( config.findManagedRepositoryById( "merge" ), merge );
842 configControl.expectAndReturn( config.findManagedRepositoryById( "merge-stage" ), staging );
844 metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( staging.getId() ), sources );
845 repositoryMergerControl.expectAndDefaultReturn(
846 repositoryMerger.getConflictingArtifacts( metadataRepository, staging.getId(), merge.getId() ), sources );
847 repositoryMerger.merge( metadataRepository, staging.getId(), merge.getId() );
848 repositoryMergerControl.setVoidCallable();
849 repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( "merge" ),
852 // scanning after merge
853 repositoryTaskScheduler.queueTask( task );
854 repositoryTaskSchedulerControl.setMatcher( MockControl.ALWAYS_MATCHER );
855 repositoryTaskSchedulerControl.setVoidCallable();
858 metadataRepository.addMetadataFacet( merge.getId(), createAuditEvent( merge ) );
859 metadataRepositoryControl.setMatcher( MockControl.ALWAYS_MATCHER );
860 metadataRepositoryControl.setVoidCallable();
862 archivaConfigControl.replay();
863 metadataRepositoryControl.replay();
864 configControl.replay();
865 repositoryMergerControl.replay();
866 repositoryTaskSchedulerControl.replay();
868 boolean a = service.merge( "merge", false );
871 archivaConfigControl.verify();
872 configControl.verify();
873 configControl.verify();
874 metadataRepositoryControl.verify();
875 repositoryMergerControl.verify();
876 repositoryTaskSchedulerControl.verify();
880 public void testMergeRepositoriesWithConflictsAndScan()
883 List<ArtifactMetadata> sources = new ArrayList<ArtifactMetadata>();
884 ArtifactMetadata one = new ArtifactMetadata();
886 one.setVersion( "1.0" );
888 ArtifactMetadata two = new ArtifactMetadata();
890 two.setVersion( "1.0-SNAPSHOT" );
895 List<ArtifactMetadata> conflicts = new ArrayList<ArtifactMetadata>();
896 conflicts.add( one );
898 sources.removeAll( conflicts );
900 Filter<ArtifactMetadata> artifactsWithOutConflicts = new IncludesFilter<ArtifactMetadata>( sources );
902 RepositoryTask task = new RepositoryTask();
903 task.setScanAll( true );
905 ManagedRepositoryConfiguration repo = createManagedRepo( "repo", "default", "repo", true, true );
906 repo.setLocation( "target/test-repository/one" );
907 ManagedRepositoryConfiguration staging = createStagingRepo( repo );
909 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
910 configControl.expectAndReturn( config.findManagedRepositoryById( "repo" ), repo );
911 configControl.expectAndReturn( config.findManagedRepositoryById( "repo-stage" ), staging );
913 metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( staging.getId() ), sources );
914 repositoryMergerControl.expectAndDefaultReturn(
915 repositoryMerger.getConflictingArtifacts( metadataRepository, staging.getId(), repo.getId() ), conflicts );
916 repositoryMerger.merge( metadataRepository, staging.getId(), repo.getId(), artifactsWithOutConflicts );
917 repositoryMergerControl.setMatcher( MockControl.ALWAYS_MATCHER );
918 repositoryMergerControl.setVoidCallable();
919 repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( "repo" ),
921 repositoryTaskScheduler.queueTask( task );
922 repositoryTaskSchedulerControl.setMatcher( MockControl.ALWAYS_MATCHER );
923 repositoryTaskSchedulerControl.setVoidCallable();
926 metadataRepository.addMetadataFacet( repo.getId(), createAuditEvent( repo ) );
927 metadataRepositoryControl.setMatcher( MockControl.ALWAYS_MATCHER );
928 metadataRepositoryControl.setVoidCallable();
930 archivaConfigControl.replay();
931 metadataRepositoryControl.replay();
932 configControl.replay();
933 repositoryMergerControl.replay();
934 repositoryTaskSchedulerControl.replay();
936 boolean a = service.merge( "repo", true );
939 archivaConfigControl.verify();
940 configControl.verify();
941 configControl.verify();
942 metadataRepositoryControl.verify();
943 repositoryMergerControl.verify();
944 repositoryTaskSchedulerControl.verify();
948 public void testAddManagedRepository()
951 String projId = "org.apache.archiva";
952 String repoId = projId + ".releases";
953 String layout = "default";
954 String name = projId + " Releases";
955 String releaseLocation = "target/test-repository/" + projId + ".releases";
956 String stageLocation = releaseLocation + "-stage";
957 String appserverBase = "target";
959 ManagedRepositoryConfiguration managedRepo = createManagedRepo( "repo1", "default", "repo", true, false );
960 RemoteRepositoryConfiguration remoteRepo =
961 createRemoteRepository( "central", "Central Repository", "default", "http://repo1.maven.org/maven2" );
962 List<String> repositories = new ArrayList<String>();
963 repositories.add( managedRepo.getName() );
964 RepositoryGroupConfiguration repoGroup = createRepoGroupConfig( "repoGroup", repositories );
965 Map<String, ManagedRepositoryConfiguration> managedRepoMap =
966 new HashMap<String, ManagedRepositoryConfiguration>();
967 Map<String, RemoteRepositoryConfiguration> remoteRepoMap = new HashMap<String, RemoteRepositoryConfiguration>();
968 Map<String, RepositoryGroupConfiguration> repoGroupMap = new HashMap<String, RepositoryGroupConfiguration>();
969 managedRepoMap.put( "repo1", managedRepo );
970 remoteRepoMap.put( "repo1", remoteRepo );
971 repoGroupMap.put( "repo1", repoGroup );
973 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
975 configControl.expectAndReturn( config.getManagedRepositoriesAsMap(), managedRepoMap );
976 configControl.expectAndReturn( config.getRemoteRepositoriesAsMap(), remoteRepoMap );
977 configControl.expectAndReturn( config.getRepositoryGroupsAsMap(), repoGroupMap );
979 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
980 roleManagerControl.setReturnValue( false );
981 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
982 roleManagerControl.setVoidCallable();
983 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
984 roleManagerControl.setReturnValue( false );
985 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
986 roleManagerControl.setVoidCallable();
988 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId + "-stage" );
989 roleManagerControl.setReturnValue( false );
990 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId + "-stage" );
991 roleManagerControl.setVoidCallable();
992 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId + "-stage" );
993 roleManagerControl.setReturnValue( false );
994 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId + "-stage" );
995 roleManagerControl.setVoidCallable();
997 roleManagerControl.replay();
999 registryControl.expectAndReturn( registry.getString( "appserver.base", "${appserver.base}" ), appserverBase );
1000 registryControl.expectAndReturn( registry.getString( "appserver.home", "${appserver.home}" ), appserverBase );
1001 config.addManagedRepository( managedRepo );
1002 configControl.setMatcher( MockControl.ALWAYS_MATCHER );
1003 configControl.setVoidCallable();
1004 config.addManagedRepository( managedRepo );
1005 configControl.setMatcher( MockControl.ALWAYS_MATCHER );
1006 configControl.setVoidCallable();
1007 archivaConfig.save( config );
1008 archivaConfigControl.setVoidCallable();
1011 repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( repoId ),
1014 RepositoryTask task = new RepositoryTask();
1015 task.setRepositoryId( repoId );
1016 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
1018 configControl.expectAndReturn( config.findManagedRepositoryById( repoId ), managedRepo );
1019 repositoryTaskScheduler.queueTask( task );
1020 repositoryTaskSchedulerControl.setVoidCallable();
1023 repositoryTaskSchedulerControl.expectAndReturn(
1024 repositoryTaskScheduler.isProcessingRepositoryTask( repoId + STAGE ), false );
1025 task = new RepositoryTask();
1026 task.setRepositoryId( repoId + STAGE );
1027 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
1029 configControl.expectAndReturn( config.findManagedRepositoryById( repoId + STAGE ), managedRepo );
1030 repositoryTaskScheduler.queueTask( task );
1031 repositoryTaskSchedulerControl.setVoidCallable();
1033 archivaConfigControl.replay();
1034 configControl.replay();
1035 registryControl.replay();
1036 repositoryTaskSchedulerControl.replay();
1037 assertFalse( new File( releaseLocation ).isDirectory() );
1038 assertFalse( new File( stageLocation ).isDirectory() );
1039 boolean success = service.addManagedRepository( repoId, layout, name,
1040 "${appserver.base}/test-repository/" + projId + ".releases",
1041 true, true, false, true, "0 15 3 * * ? *", 1, 1, true );
1042 assertTrue( success );
1043 assertTrue( new File( releaseLocation ).isDirectory() );
1044 assertTrue( new File( stageLocation ).isDirectory() );
1045 new File( releaseLocation ).delete();
1046 new File( stageLocation ).delete();
1048 registryControl.verify();
1052 public void testAddManagedRepositoryInvalidId()
1055 String projId = "org.apache.archiva";
1056 String repoId = projId + "<script>alert('xss')</script>";
1057 String layout = "default";
1058 String name = projId + " Releases";
1060 ManagedRepositoryConfiguration managedRepo = createManagedRepo( "repo1", "default", "repo", true, false );
1061 RemoteRepositoryConfiguration remoteRepo =
1062 createRemoteRepository( "central", "Central Repository", "default", "http://repo1.maven.org/maven2" );
1063 List<String> repositories = new ArrayList<String>();
1064 repositories.add( managedRepo.getName() );
1065 RepositoryGroupConfiguration repoGroup = createRepoGroupConfig( "repoGroup", repositories );
1066 Map<String, ManagedRepositoryConfiguration> managedRepoMap =
1067 new HashMap<String, ManagedRepositoryConfiguration>();
1068 Map<String, RemoteRepositoryConfiguration> remoteRepoMap = new HashMap<String, RemoteRepositoryConfiguration>();
1069 Map<String, RepositoryGroupConfiguration> repoGroupMap = new HashMap<String, RepositoryGroupConfiguration>();
1070 managedRepoMap.put( "repo1", managedRepo );
1071 remoteRepoMap.put( "repo1", remoteRepo );
1072 repoGroupMap.put( "repo1", repoGroup );
1074 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
1076 configControl.expectAndReturn( config.getManagedRepositoriesAsMap(), managedRepoMap );
1077 configControl.expectAndReturn( config.getRemoteRepositoriesAsMap(), remoteRepoMap );
1078 configControl.expectAndReturn( config.getRepositoryGroupsAsMap(), repoGroupMap );
1080 archivaConfigControl.replay();
1081 configControl.replay();
1085 service.addManagedRepository( repoId, layout, name,
1086 "${appserver.base}/test-repository/" + projId + ".releases", true, true,
1087 false, true, "0 15 3 * * ? *", 1, 1, true );
1088 fail( "An exception should have been thrown! Repository ID is not valid." );
1090 catch ( Exception e )
1093 "Invalid repository ID. Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-).",
1099 public void testAddManagedRepositoryInvalidName()
1102 String projId = "org.apache.archiva";
1103 String repoId = projId + ".releases";
1104 String layout = "default";
1105 String name = projId + " <script>alert('xss')</script>";
1107 ManagedRepositoryConfiguration managedRepo = createManagedRepo( "repo1", "default", "repo", true, false );
1108 RemoteRepositoryConfiguration remoteRepo =
1109 createRemoteRepository( "central", "Central Repository", "default", "http://repo1.maven.org/maven2" );
1110 List<String> repositories = new ArrayList<String>();
1111 repositories.add( managedRepo.getName() );
1112 RepositoryGroupConfiguration repoGroup = createRepoGroupConfig( "repoGroup", repositories );
1113 Map<String, ManagedRepositoryConfiguration> managedRepoMap =
1114 new HashMap<String, ManagedRepositoryConfiguration>();
1115 Map<String, RemoteRepositoryConfiguration> remoteRepoMap = new HashMap<String, RemoteRepositoryConfiguration>();
1116 Map<String, RepositoryGroupConfiguration> repoGroupMap = new HashMap<String, RepositoryGroupConfiguration>();
1117 managedRepoMap.put( "repo1", managedRepo );
1118 remoteRepoMap.put( "repo1", remoteRepo );
1119 repoGroupMap.put( "repo1", repoGroup );
1121 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
1123 configControl.expectAndReturn( config.getManagedRepositoriesAsMap(), managedRepoMap );
1124 configControl.expectAndReturn( config.getRemoteRepositoriesAsMap(), remoteRepoMap );
1125 configControl.expectAndReturn( config.getRepositoryGroupsAsMap(), repoGroupMap );
1127 archivaConfigControl.replay();
1128 configControl.replay();
1132 service.addManagedRepository( repoId, layout, name,
1133 "${appserver.base}/test-repository/" + projId + ".releases", true, true,
1134 false, true, "0 15 3 * * ? *", 1, 1, true );
1135 fail( "An exception should have been thrown! Repository name is not valid." );
1137 catch ( Exception e )
1140 "Invalid repository name. Repository Name must only contain alphanumeric characters, white-spaces(' '), "
1141 + "forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-).",
1147 public void testAddManagedRepositoryInvalidLocation()
1150 String projId = "org.apache.archiva";
1151 String repoId = projId + ".releases";
1152 String layout = "default";
1153 String name = projId + " Releases";
1154 String appserverBase = "target";
1156 ManagedRepositoryConfiguration managedRepo = createManagedRepo( "repo1", "default", "repo", true, false );
1157 RemoteRepositoryConfiguration remoteRepo =
1158 createRemoteRepository( "central", "Central Repository", "default", "http://repo1.maven.org/maven2" );
1159 List<String> repositories = new ArrayList<String>();
1160 repositories.add( managedRepo.getName() );
1161 RepositoryGroupConfiguration repoGroup = createRepoGroupConfig( "repoGroup", repositories );
1162 Map<String, ManagedRepositoryConfiguration> managedRepoMap =
1163 new HashMap<String, ManagedRepositoryConfiguration>();
1164 Map<String, RemoteRepositoryConfiguration> remoteRepoMap = new HashMap<String, RemoteRepositoryConfiguration>();
1165 Map<String, RepositoryGroupConfiguration> repoGroupMap = new HashMap<String, RepositoryGroupConfiguration>();
1166 managedRepoMap.put( "repo1", managedRepo );
1167 remoteRepoMap.put( "repo1", remoteRepo );
1168 repoGroupMap.put( "repo1", repoGroup );
1170 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
1171 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
1173 configControl.expectAndReturn( config.getManagedRepositoriesAsMap(), managedRepoMap );
1174 configControl.expectAndReturn( config.getRemoteRepositoriesAsMap(), remoteRepoMap );
1175 configControl.expectAndReturn( config.getRepositoryGroupsAsMap(), repoGroupMap );
1176 registryControl.expectAndReturn( registry.getString( "appserver.base", "${appserver.base}" ), appserverBase );
1177 registryControl.expectAndReturn( registry.getString( "appserver.home", "${appserver.home}" ), appserverBase );
1179 archivaConfigControl.replay();
1180 configControl.replay();
1181 registryControl.replay();
1185 service.addManagedRepository( repoId, layout, name,
1186 "${appserver.base}/<script>alert('xss')</script>" + projId + ".releases",
1187 true, true, false, true, "0 15 3 * * ? *", 1, 1, true );
1188 fail( "An exception should have been thrown! Repository location is not valid." );
1190 catch ( Exception e )
1192 assertEquals( "message found " + e.getMessage(),
1193 "Invalid repository location. Directory must only contain alphanumeric characters, equals(=), question-marks(?), "
1194 + "exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-).",
1198 registryControl.verify();
1201 /* private methods */
1203 private void assertRemoteRepo( RemoteRepository remoteRepo, RemoteRepositoryConfiguration expectedRepoConfig )
1205 assertEquals( expectedRepoConfig.getId(), remoteRepo.getId() );
1206 assertEquals( expectedRepoConfig.getLayout(), remoteRepo.getLayout() );
1207 assertEquals( expectedRepoConfig.getName(), remoteRepo.getName() );
1208 assertEquals( expectedRepoConfig.getUrl(), remoteRepo.getUrl() );
1211 private RemoteRepositoryConfiguration createRemoteRepository( String id, String name, String layout, String url )
1213 RemoteRepositoryConfiguration remoteConfig = new RemoteRepositoryConfiguration();
1214 remoteConfig.setId( id );
1215 remoteConfig.setName( name );
1216 remoteConfig.setLayout( layout );
1217 remoteConfig.setUrl( url );
1219 return remoteConfig;
1222 private void assertManagedRepo( ManagedRepository managedRepo, ManagedRepositoryConfiguration expectedRepoConfig )
1224 assertEquals( expectedRepoConfig.getId(), managedRepo.getId() );
1225 assertEquals( expectedRepoConfig.getLayout(), managedRepo.getLayout() );
1226 assertEquals( expectedRepoConfig.getName(), managedRepo.getName() );
1228 // TODO enable assert once fixed in AdministrationServiceImpl!
1229 // assertEquals( "http://localhost:8080/archiva/repository/" + expectedRepoConfig.getId(), managedRepo.getUrl()
1231 assertEquals( expectedRepoConfig.isReleases(), managedRepo.isReleases() );
1232 assertEquals( expectedRepoConfig.isSnapshots(), managedRepo.isSnapshots() );
1235 private ManagedRepositoryConfiguration createManagedRepo( String id, String layout, String name,
1236 boolean hasReleases, boolean hasSnapshots )
1238 ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
1239 repoConfig.setId( id );
1240 repoConfig.setLayout( layout );
1241 repoConfig.setName( name );
1242 repoConfig.setReleases( hasReleases );
1243 repoConfig.setSnapshots( hasSnapshots );
1248 private ManagedRepositoryConfiguration createStagingRepo( ManagedRepositoryConfiguration repoConfig )
1250 ManagedRepositoryConfiguration stagingRepo = new ManagedRepositoryConfiguration();
1251 stagingRepo.setId( repoConfig.getId() + STAGE );
1252 stagingRepo.setLayout( repoConfig.getLayout() );
1253 stagingRepo.setName( repoConfig + STAGE );
1254 stagingRepo.setReleases( repoConfig.isReleases() );
1255 stagingRepo.setSnapshots( repoConfig.isSnapshots() );
1256 stagingRepo.setLocation( repoConfig.getLocation() );
1261 private AuditEvent createAuditEvent( ManagedRepositoryConfiguration repoConfig )
1263 AuditEvent auditEvent = new AuditEvent();
1265 auditEvent.setAction( AuditEvent.MERGE_REPO_REMOTE );
1266 auditEvent.setRepositoryId( repoConfig.getId() );
1267 auditEvent.setResource( repoConfig.getLocation() );
1268 auditEvent.setTimestamp( new Date() );
1273 private void recordRepoConsumers()
1275 List<KnownRepositoryContentConsumer> availableKnownConsumers = new ArrayList<KnownRepositoryContentConsumer>();
1276 availableKnownConsumers.add( indexArtifactConsumer );
1277 availableKnownConsumers.add( indexPomConsumer );
1279 List<InvalidRepositoryContentConsumer> availableInvalidConsumers =
1280 new ArrayList<InvalidRepositoryContentConsumer>();
1281 availableInvalidConsumers.add( checkPomConsumer );
1282 availableInvalidConsumers.add( checkMetadataConsumer );
1284 repoConsumerUtilsControl.expectAndReturn( repoConsumersUtil.getAvailableKnownConsumers(),
1285 availableKnownConsumers );
1286 knownContentConsumerControl.expectAndReturn( indexArtifactConsumer.getId(), "index-artifact" );
1287 knownContentConsumerControl.expectAndReturn( indexPomConsumer.getId(), "index-pom" );
1289 repoConsumerUtilsControl.expectAndReturn( repoConsumersUtil.getAvailableInvalidConsumers(),
1290 availableInvalidConsumers );
1291 invalidContentConsumerControl.expectAndReturn( checkPomConsumer.getId(), "check-pom" );
1292 invalidContentConsumerControl.expectAndReturn( checkMetadataConsumer.getId(), "check-metadata" );
1295 private void recordInManagedLegacyRepoContent( MockControl fileTypesControl, FileTypes fileTypes,
1296 MockControl pathParserControl, PathParser parser )
1297 throws LayoutException
1299 String sep = File.separator;
1300 String ad10p = "org.apache.archiva" + sep + "poms" + sep + "archiva-diff-1.0.pom";
1301 String at10p = "org.apache.archiva" + sep + "poms" + sep + "archiva-test-1.0.pom";
1302 String at11p = "org.apache.archiva" + sep + "poms" + sep + "archiva-test-1.1.pom";
1303 String ad10j = "org.apache.archiva" + sep + "jars" + sep + "archiva-diff-1.0.jar";
1304 String at10j = "org.apache.archiva" + sep + "jars" + sep + "archiva-test-1.0.jar";
1305 String at11j = "org.apache.archiva" + sep + "jars" + sep + "archiva-test-1.1.jar";
1307 fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( at10p ), true );
1308 fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( at11p ), true );
1309 fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( ad10p ), true );
1310 fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( ad10j ), true );
1311 fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( at10j ), true );
1312 fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( at11j ), true );
1314 ArtifactReference aRef = createArtifactReference( "archiva-test", "org.apache.archiva", "1.1", "pom" );
1315 pathParserControl.expectAndReturn( parser.toArtifactReference( at11p ), aRef );
1317 aRef = createArtifactReference( "archiva-test", "org.apache.archiva", "1.0", "pom" );
1318 pathParserControl.expectAndReturn( parser.toArtifactReference( at10p ), aRef );
1320 aRef = createArtifactReference( "archiva-diff", "org.apache.archiva", "1.0", "pom" );
1321 pathParserControl.expectAndReturn( parser.toArtifactReference( ad10p ), aRef );
1323 aRef = createArtifactReference( "archiva-diff", "org.apache.archiva", "1.0", "jar" );
1324 pathParserControl.expectAndReturn( parser.toArtifactReference( ad10j ), aRef );
1326 aRef = createArtifactReference( "archiva-test", "org.apache.archiva", "1.0", "jar" );
1327 pathParserControl.expectAndReturn( parser.toArtifactReference( at10j ), aRef );
1329 aRef = createArtifactReference( "archiva-test", "org.apache.archiva", "1.1", "jar" );
1330 pathParserControl.expectAndReturn( parser.toArtifactReference( at11j ), aRef );
1333 private List<ArtifactMetadata> getArtifacts()
1335 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>();
1337 ArtifactMetadata artifact = new ArtifactMetadata();
1338 artifact.setId( "archiva-test-1.0.jar" );
1339 artifact.setProject( "archiva-test" );
1340 artifact.setVersion( "1.0" );
1341 artifact.setProjectVersion( "1.0" );
1342 artifact.setNamespace( "org.apache.archiva" );
1343 artifact.setRepositoryId( "internal" );
1344 artifacts.add( artifact );
1348 private ArtifactReference createArtifactReference( String artifactId, String groupId, String version, String type )
1350 ArtifactReference aRef = new ArtifactReference();
1351 aRef.setArtifactId( artifactId );
1352 aRef.setGroupId( groupId );
1353 aRef.setType( type );
1354 aRef.setVersion( version );
1359 private RepositoryGroupConfiguration createRepoGroupConfig( String id, List<String> repositories )
1361 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
1362 repoGroup.setId( id );
1363 repoGroup.setRepositories( repositories );