]> source.dussan.org Git - archiva.git/blob
4f39b0ea2eabd3340be3bd049d891b8899f5676b
[archiva.git] /
1 package org.apache.archiva.stagerepository.merge.repomerge;
2
3 /*
4  * Licensed to the Apache Software Foundation (ASF) under one
5  * or more contributor license agreements.  See the NOTICE file
6  * distributed with this work for additional information
7  * regarding copyright ownership.  The ASF licenses this file
8  * to you under the Apache License, Version 2.0 (the
9  * "License"); you may not use this file except in compliance
10  * with the License.  You may obtain a copy of the License at
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied.  See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  */
21
22 import static org.junit.Assert.assertNotNull;
23 import org.junit.Before;
24 import org.junit.Test;
25 import static org.mockito.Mockito.stub;
26
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;
43
44 import java.util.ArrayList;
45 import java.util.Collection;
46 import java.util.List;
47 import java.io.File;
48
49 public class ArtifactsMergerTest
50     extends PlexusInSpringTestCase
51 {
52
53     private static final String SOURCE_REPOSITORY_ID = "test-repository";
54
55     private static final String TARGET_REPOSITORY_ID = "target-repo";
56
57     // private static final String TARGET_REPOSITORY_ID = "target-repo";
58
59     private Configuration config;
60
61     @MockitoAnnotations.Mock
62     private MetadataResolver metadataResolver;
63
64     private RepositoryContentFactory repositoryFactory;
65
66     private ArchivaConfiguration configuration;
67
68     private SourceAritfacts sourceArtifacts;
69
70     private ArtifactsMerger merger;
71
72     @Before
73     public void setUp()
74     {
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 );
87         setSourceArtifacts();
88     }
89
90     @Test
91     public void setSourceArtifacts()
92     {
93         when( sourceArtifacts.getSourceArtifactList() ).thenReturn( getArtifacts() );
94         merger.setSourceArtifacts( sourceArtifacts );
95         verify( sourceArtifacts ).getSourceArtifactList();
96     }
97
98     @Test
99     public void testDomerge()
100         throws Exception
101     {
102         ManagedRepositoryContent sourceRepoContent = new ManagedDefaultRepositoryContent();
103         sourceRepoContent.setRepository( config.findManagedRepositoryById( SOURCE_REPOSITORY_ID ) );
104
105         ManagedRepositoryContent targetRepoContent = new ManagedDefaultRepositoryContent();
106         sourceRepoContent.setRepository( config.findManagedRepositoryById( TARGET_REPOSITORY_ID ) );
107
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() );
113         merger.doMerge();
114
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" );
124     }
125
126     public Collection<ArchivaArtifact> getArtifacts()
127     {
128         ArchivaArtifact a1 =
129             new ArchivaArtifact( "org.apache.archiva", "archiva", "1.2.1", "", "jar", SOURCE_REPOSITORY_ID );
130         ArchivaArtifact a2 =
131             new ArchivaArtifact( "org.apache.archiva", "archiva", "1.5", "", "jar", SOURCE_REPOSITORY_ID );
132         ArrayList<ArchivaArtifact> list = new ArrayList<ArchivaArtifact>();
133         list.add( a1 );
134         // list.add(a2) ;
135         return list;
136     }
137
138     public Collection<ArtifactMetadata> getMetaDataList()
139     {
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>();
145         list.add( m1 );
146         return list;
147     }
148
149     public void setRepositoryConfigurations()
150     {
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();
155
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 );
170
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 );
177
178         this.config.addManagedRepository( sourceRepoConfig );
179         this.config.addManagedRepository( targetRepoConfig );
180     }
181 }