1 package org.apache.archiva.stagerepository.merge;
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.codehaus.plexus.spring.PlexusInSpringTestCase;
23 import org.apache.maven.archiva.configuration.Configuration;
24 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
25 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
26 import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
27 import org.apache.maven.archiva.repository.RepositoryContentFactory;
28 import org.apache.archiva.metadata.repository.MetadataRepository;
29 import org.apache.archiva.metadata.model.ArtifactMetadata;
31 import static org.mockito.Mockito.mock;
32 import static org.mockito.Mockito.when;
33 import static org.mockito.Mockito.verify;
34 import org.junit.Before;
36 import java.util.List;
37 import java.util.ArrayList;
39 public class Maven2RepositoryMergerTest
40 extends PlexusInSpringTestCase
43 private static final String TEST_REPO_ID = "test";
45 private static final String TARGET_REPOSITORY_ID = "target-repo";
47 private Configuration config;
49 @MockitoAnnotations.Mock
50 private MetadataRepository metadataResolver;
52 private RepositoryContentFactory repositoryFactory;
54 private ArchivaConfiguration configuration;
56 private Maven2RepositoryMerger repositoryMerger;
58 private MetadataRepository metadataRepository;
65 MockitoAnnotations.initMocks( this );
66 metadataRepository = mock( MetadataRepository.class );
68 ArchivaConfiguration configuration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
69 Configuration c = new Configuration();
70 ManagedRepositoryConfiguration testRepo = new ManagedRepositoryConfiguration();
71 testRepo.setId( TEST_REPO_ID );
72 testRepo.setLocation( getTestPath( "target/test-repository" ) );
74 RepositoryScanningConfiguration repoScanConfig = new RepositoryScanningConfiguration();
75 List<String> knownContentConsumers = new ArrayList<String>();
76 knownContentConsumers.add( "metadata-updater12" );
77 repoScanConfig.setKnownContentConsumers( knownContentConsumers );
78 c.setRepositoryScanning( repoScanConfig );
80 ManagedRepositoryConfiguration targetRepo = new ManagedRepositoryConfiguration();
81 targetRepo.setId( "target-rep" );
82 targetRepo.setLocation( getTestPath( "target" ) );
83 c.addManagedRepository( testRepo );
84 c.addManagedRepository( targetRepo );
85 configuration.save( c );
87 repositoryMerger = (Maven2RepositoryMerger) lookup( RepositoryMerger.class, "maven2" );
88 repositoryMerger.setMetadataRepository( metadataRepository );
91 private List<ArtifactMetadata> getArtifacts()
93 List<ArtifactMetadata> metadata = new ArrayList<ArtifactMetadata>();
94 ArtifactMetadata artifact1 = new ArtifactMetadata();
95 artifact1.setNamespace( "com.example.test" );
96 artifact1.setProject( "test-artifact" );
97 artifact1.setVersion( "1.0-SNAPSHOT" );
98 artifact1.setProjectVersion( "1.0-SNAPSHOT" );
99 artifact1.setId( "test-artifact-1.0-20100308.230825-1.jar" );
101 metadata.add( artifact1 );
105 public void testMerge()
108 when( metadataRepository.getArtifacts( TEST_REPO_ID ) ).thenReturn( getArtifacts() );
109 repositoryMerger.merge( TEST_REPO_ID, "target-rep" );
110 verify( metadataRepository ).getArtifacts( TEST_REPO_ID );