1 package org.apache.archiva.stagerepository.merge.repomerge;
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 static org.junit.Assert.assertNotNull;
23 import org.junit.Before;
24 import org.junit.Test;
25 import static org.mockito.Mockito.stub;
27 import static org.mockito.Mockito.verify;
28 import org.mockito.MockitoAnnotations;
29 import static org.mockito.Mockito.*;
30 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
31 import org.apache.maven.archiva.repository.RepositoryContentFactory;
32 import org.apache.maven.archiva.repository.ManagedRepositoryContent;
33 import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent;
34 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
35 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
36 import org.apache.maven.archiva.configuration.Configuration;
37 import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
38 import org.apache.maven.archiva.model.ArchivaArtifact;
39 import org.apache.archiva.stagerepository.merge.repodetails.SourceAritfacts;
40 import org.apache.archiva.metadata.model.ArtifactMetadata;
41 import org.apache.archiva.metadata.repository.MetadataResolver;
42 //import com.sun.xml.internal.ws.api.wsdl.parser.MetaDataResolver;
44 import java.util.ArrayList;
45 import java.util.Collection;
46 import java.util.List;
49 public class ArtifactsMergerTest
50 extends PlexusInSpringTestCase
53 private static final String SOURCE_REPOSITORY_ID = "test-repository";
55 private static final String TARGET_REPOSITORY_ID = "target-repo";
57 // private static final String TARGET_REPOSITORY_ID = "target-repo";
59 private Configuration config;
61 @MockitoAnnotations.Mock
62 private MetadataResolver metadataResolver;
64 private RepositoryContentFactory repositoryFactory;
66 private ArchivaConfiguration configuration;
68 private SourceAritfacts sourceArtifacts;
70 private ArtifactsMerger merger;
75 MockitoAnnotations.initMocks( this );
76 metadataResolver = mock( MetadataResolver.class );
77 repositoryFactory = mock( RepositoryContentFactory.class );
78 configuration = mock( ArchivaConfiguration.class );
79 sourceArtifacts = mock( SourceAritfacts.class );
80 sourceArtifacts.setRepoId( SOURCE_REPOSITORY_ID );
81 sourceArtifacts.setMetadataResolver( metadataResolver );
82 setRepositoryConfigurations();
83 merger = new ArtifactsMerger( TARGET_REPOSITORY_ID, SOURCE_REPOSITORY_ID );
84 merger.setConfiguration( configuration );
85 merger.setRepositoryFactory( repositoryFactory );
86 merger.setMetadataResolver( metadataResolver );
91 public void setSourceArtifacts()
93 when( sourceArtifacts.getSourceArtifactList() ).thenReturn( getArtifacts() );
94 merger.setSourceArtifacts( sourceArtifacts );
95 verify( sourceArtifacts ).getSourceArtifactList();
99 public void testDomerge()
102 ManagedRepositoryContent sourceRepoContent = new ManagedDefaultRepositoryContent();
103 sourceRepoContent.setRepository( config.findManagedRepositoryById( SOURCE_REPOSITORY_ID ) );
105 ManagedRepositoryContent targetRepoContent = new ManagedDefaultRepositoryContent();
106 sourceRepoContent.setRepository( config.findManagedRepositoryById( TARGET_REPOSITORY_ID ) );
108 when( configuration.getConfiguration() ).thenReturn( config );
109 when( repositoryFactory.getManagedRepositoryContent( SOURCE_REPOSITORY_ID ) ).thenReturn( sourceRepoContent );
110 when( repositoryFactory.getManagedRepositoryContent( TARGET_REPOSITORY_ID ) ).thenReturn( targetRepoContent );
111 when( sourceArtifacts.getSourceArtifactList() ).thenReturn( getArtifacts() );
112 when( metadataResolver.getArtifacts( TARGET_REPOSITORY_ID, "archiva", "archiva", "1.2.1" ) ).thenReturn( getMetaDataList() );
115 // verify(configuration);
116 // verify(repositoryFactory);
117 // verify(repositoryFactory);
118 // verify(sourceArtifacts);
119 verify( configuration ).getConfiguration();
120 verify( repositoryFactory ).getManagedRepositoryContent( SOURCE_REPOSITORY_ID );
121 verify( repositoryFactory ).getManagedRepositoryContent( TARGET_REPOSITORY_ID );
122 verify( sourceArtifacts ).getSourceArtifactList();
123 verify( metadataResolver ).getArtifacts( TARGET_REPOSITORY_ID, "org.apache.archiva", "archiva", "1.2.1" );
126 public Collection<ArchivaArtifact> getArtifacts()
129 new ArchivaArtifact( "org.apache.archiva", "archiva", "1.2.1", "", "jar", SOURCE_REPOSITORY_ID );
131 new ArchivaArtifact( "org.apache.archiva", "archiva", "1.5", "", "jar", SOURCE_REPOSITORY_ID );
132 ArrayList<ArchivaArtifact> list = new ArrayList<ArchivaArtifact>();
138 public Collection<ArtifactMetadata> getMetaDataList()
140 ArtifactMetadata m1 = new ArtifactMetadata();
141 m1.setNamespace( "org.apache.archiva" );
142 m1.setProject( "archiva" );
143 m1.setVersion( "1.2.1" );
144 ArrayList<ArtifactMetadata> list = new ArrayList<ArtifactMetadata>();
149 public void setRepositoryConfigurations()
151 File sourceRepoFile = new File( getBasedir(), "src/test/resources/test-repository" );
152 File targetRepoFile = new File( getBasedir(), "src/test/resources/target-repo" );
153 // sourceRepoFile.mkdirs();
154 // targetRepoFile.mkdirs();
156 assertTrue( sourceRepoFile.exists() );
157 this.config = new Configuration();
158 RepositoryScanningConfiguration repoScanConfig = new RepositoryScanningConfiguration();
159 List<String> knownContentConsumers = new ArrayList<String>();
160 knownContentConsumers.add( "metadata-updater12" );
161 repoScanConfig.setKnownContentConsumers( knownContentConsumers );
162 config.setRepositoryScanning( repoScanConfig );
163 // config.setManagedRepositories();
164 ManagedRepositoryConfiguration sourceRepoConfig = new ManagedRepositoryConfiguration();
165 sourceRepoConfig.setId( SOURCE_REPOSITORY_ID );
166 sourceRepoConfig.setLayout( "default" );
167 sourceRepoConfig.setLocation( sourceRepoFile.getPath() );
168 sourceRepoConfig.setName( SOURCE_REPOSITORY_ID );
169 sourceRepoConfig.setBlockRedeployments( true );
171 ManagedRepositoryConfiguration targetRepoConfig = new ManagedRepositoryConfiguration();
172 targetRepoConfig.setId( TARGET_REPOSITORY_ID );
173 targetRepoConfig.setLayout( "default" );
174 targetRepoConfig.setLocation( targetRepoFile.getPath() );
175 targetRepoConfig.setName( TARGET_REPOSITORY_ID );
176 targetRepoConfig.setBlockRedeployments( true );
178 this.config.addManagedRepository( sourceRepoConfig );
179 this.config.addManagedRepository( targetRepoConfig );