]> source.dussan.org Git - archiva.git/blob
5c0f58f2c6fe53c67757f7152285f3a973d0487c
[archiva.git] /
1 package org.apache.archiva.repository.maven.metadata.storage;
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  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  */
20
21 import junit.framework.TestCase;
22 import org.apache.archiva.configuration.ArchivaConfiguration;
23 import org.apache.archiva.configuration.Configuration;
24 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
25 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
26 import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
27 import org.apache.archiva.configuration.RepositoryGroupConfiguration;
28 import org.apache.archiva.filter.AllFilter;
29 import org.apache.archiva.filter.Filter;
30 import org.apache.archiva.metadata.model.ArtifactMetadata;
31 import org.apache.archiva.metadata.model.Dependency;
32 import org.apache.archiva.metadata.model.License;
33 import org.apache.archiva.metadata.model.MailingList;
34 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
35 import org.apache.archiva.metadata.repository.storage.ReadMetadataRequest;
36 import org.apache.archiva.maven.proxy.WagonFactory;
37 import org.apache.archiva.maven.proxy.WagonFactoryRequest;
38 import org.apache.archiva.repository.RepositoryRegistry;
39 import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
40 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
41 import org.apache.commons.io.FileUtils;
42 import org.apache.maven.wagon.Wagon;
43 import org.junit.Before;
44 import org.junit.Test;
45 import org.junit.runner.RunWith;
46 import org.springframework.test.context.ContextConfiguration;
47
48 import javax.inject.Inject;
49 import javax.inject.Named;
50 import java.io.IOException;
51 import java.nio.file.Files;
52 import java.nio.file.Path;
53 import java.nio.file.Paths;
54 import java.util.ArrayList;
55 import java.util.Arrays;
56 import java.util.List;
57
58 import static org.mockito.Mockito.mock;
59 import static org.mockito.Mockito.when;
60
61
62 @RunWith ( ArchivaSpringJUnit4ClassRunner.class )
63 @ContextConfiguration ( { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
64 public class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest
65     extends TestCase
66 {
67     private static final Filter<String> ALL = new AllFilter<String>();
68
69     @Inject
70     @Named ( "repositoryStorage#maven2")
71     private Maven2RepositoryStorage storage;
72
73     private static final String TEST_REPO_ID = "test";
74
75     private static final String TEST_SNAP_REPO_ID = "tests";
76
77     private static final String TEST_REPO_GROUP_ID = "testrg";
78
79     private static final String TEST_REMOTE_REPO_ID = "central";
80
81     private static final String ASF_SCM_CONN_BASE = "scm:svn:http://svn.apache.org/repos/asf/";
82
83     private static final String ASF_SCM_DEV_CONN_BASE = "scm:svn:https://svn.apache.org/repos/asf/";
84
85     private static final String ASF_SCM_VIEWVC_BASE = "http://svn.apache.org/viewvc/";
86
87     private static final String TEST_SCM_CONN_BASE = "scm:svn:http://svn.example.com/repos/";
88
89     private static final String TEST_SCM_DEV_CONN_BASE = "scm:svn:https://svn.example.com/repos/";
90
91     private static final String TEST_SCM_URL_BASE = "http://svn.example.com/repos/";
92
93     private static final String EMPTY_MD5 = "d41d8cd98f00b204e9800998ecf8427e";
94
95     private static final String EMPTY_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
96
97     @Inject
98     @Named ( "archivaConfiguration#default" )
99     private ArchivaConfiguration configuration;
100
101     @Inject
102     RepositoryRegistry repositoryRegistry;
103
104     @SuppressWarnings( "unused" )
105     @Inject
106     RepositoryHandlerDependencies repositoryHandlerDependencies;
107
108
109     private WagonFactory wagonFactory;
110
111     ManagedRepositoryConfiguration testRepo;
112
113     ManagedRepositoryConfiguration testRepoS;
114
115     Configuration c;
116
117     @Before
118     @Override
119     public void setUp()
120         throws Exception
121     {
122         super.setUp();
123
124         c = new Configuration();
125
126         testRepo = new ManagedRepositoryConfiguration();
127         testRepo.setId( TEST_REPO_ID );
128         testRepo.setLocation( Paths.get( "target/test-repository" ).toAbsolutePath().toString() );
129         testRepo.setReleases( true );
130         testRepo.setSnapshots( false );
131         c.addManagedRepository( testRepo );
132
133         testRepoS = new ManagedRepositoryConfiguration();
134         testRepoS.setId( TEST_SNAP_REPO_ID );
135         testRepoS.setLocation( Paths.get( "target/test-repositorys" ).toAbsolutePath().toString() );
136         testRepoS.setReleases( false );
137         testRepoS.setSnapshots( true );
138         c.addManagedRepository( testRepoS );
139
140         RemoteRepositoryConfiguration testRemoteRepo = new RemoteRepositoryConfiguration();
141         testRemoteRepo.setId( TEST_REMOTE_REPO_ID );
142         testRemoteRepo.setLayout( "default" );
143         testRemoteRepo.setName( "Central Repository" );
144         testRemoteRepo.setUrl( "http://central.repo.com/maven2" );
145         testRemoteRepo.setTimeout( 10 );
146         c.addRemoteRepository( testRemoteRepo );
147
148         ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
149         proxyConnector.setSourceRepoId( TEST_REPO_ID );
150         proxyConnector.setTargetRepoId( TEST_REMOTE_REPO_ID );
151         proxyConnector.setDisabled( false );
152         c.addProxyConnector( proxyConnector );
153
154         ProxyConnectorConfiguration proxyConnectors = new ProxyConnectorConfiguration();
155         proxyConnectors.setSourceRepoId( TEST_SNAP_REPO_ID );
156         proxyConnectors.setTargetRepoId( TEST_REMOTE_REPO_ID );
157         proxyConnectors.setDisabled( false );
158         c.addProxyConnector( proxyConnectors );
159
160         List<String> repos = new ArrayList<>();
161         repos.add( TEST_REPO_ID );
162         repos.add( TEST_SNAP_REPO_ID );
163
164         RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
165         repoGroup.setId( TEST_REPO_GROUP_ID );
166         repoGroup.setRepositories( repos );
167         c.addRepositoryGroup( repoGroup );
168
169         configuration.save( c );
170         repositoryRegistry.reload();
171
172         assertFalse( c.getManagedRepositories().get( 0 ).isSnapshots() );
173         assertTrue( c.getManagedRepositories().get( 0 ).isReleases() );
174
175         assertTrue( c.getManagedRepositories().get( 1 ).isSnapshots() );
176         assertFalse( c.getManagedRepositories().get( 1 ).isReleases() );
177
178         wagonFactory = mock( WagonFactory.class );
179
180         storage.setWagonFactory( wagonFactory );
181
182         Wagon wagon = new MockWagon();
183         when( wagonFactory.getWagon( new WagonFactoryRequest().protocol( "wagon#http" ) ) ).thenReturn( wagon );
184     }
185
186     // Tests for MRM-1411 - START
187     @Test
188     public void testGetProjectVersionMetadataWithParentSuccessful()
189         throws Exception
190     {
191         copyTestArtifactWithParent( "src/test/resources/com/example/test/test-artifact-module-a",
192                                     "target/test-repository/com/example/test/test-artifact-module-a" );
193         copyTestArtifactWithParent( "src/test/resources/com/example/test/test-artifact-root",
194                 "target/test-repository/com/example/test/test-artifact-root" );
195         copyTestArtifactWithParent( "src/test/resources/com/example/test/test-artifact-parent",
196                 "target/test-repository/com/example/test/test-artifact-parent" );
197
198         ReadMetadataRequest readMetadataRequest =
199             new ReadMetadataRequest().repositoryId( TEST_REPO_ID ).namespace( "com.example.test" ).projectId(
200                 "test-artifact-module-a" ).projectVersion( "1.0" );
201         ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( readMetadataRequest );
202
203         MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
204         assertEquals( "jar", facet.getPackaging() );
205         assertEquals( "http://maven.apache.org", metadata.getUrl() );
206         assertEquals( "com.example.test", facet.getParent().getGroupId() );
207         assertEquals( "test-artifact-root", facet.getParent().getArtifactId() );
208         assertEquals( "1.0", facet.getParent().getVersion() );
209         assertEquals( "test-artifact-module-a", facet.getArtifactId() );
210         assertEquals( "com.example.test", facet.getGroupId() );
211         assertNull( metadata.getCiManagement() );
212         assertNotNull( metadata.getDescription() );
213
214         checkApacheLicense( metadata );
215
216         assertEquals( "1.0", metadata.getId() );
217         assertEquals( "Test Artifact :: Module A", metadata.getName() );
218         String path = "test-artifact/trunk/test-artifact-module-a";
219         assertEquals( TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
220         assertEquals( TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
221         assertEquals( TEST_SCM_URL_BASE + path, metadata.getScm().getUrl() );
222
223         List<Dependency> dependencies = metadata.getDependencies();
224         assertEquals( 2, dependencies.size() );
225         assertDependency( dependencies.get( 0 ), "commons-io", "commons-io", "1.4" );
226         assertDependency( dependencies.get( 1 ), "junit", "junit", "3.8.1", "test" );
227
228         List<String> paths = new ArrayList<>();
229         paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
230         paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
231         paths.add( "target/test-repository/com/example/test/test-artifact-root" );
232
233         deleteTestArtifactWithParent( paths );
234     }
235
236     @Test
237     public void testGetProjectVersionMetadataWithParentNoRemoteReposConfigured()
238         throws Exception
239     {
240         // remove configuration
241         Configuration config = configuration.getConfiguration();
242         RemoteRepositoryConfiguration remoteRepo = config.findRemoteRepositoryById( TEST_REMOTE_REPO_ID );
243         config.removeRemoteRepository( remoteRepo );
244
245         configuration.save( config );
246
247         copyTestArtifactWithParent( "src/test/resources/com/example/test/test-artifact-module-a",
248                                     "target/test-repository/com/example/test/test-artifact-module-a" );
249         copyTestArtifactWithParent( "src/test/resources/com/example/test/test-artifact-root",
250                 "target/test-repository/com/example/test/test-artifact-root" );
251         copyTestArtifactWithParent( "src/test/resources/com/example/test/test-artifact-parent",
252                 "target/test-repository/com/example/test/test-artifact-parent" );
253
254         ReadMetadataRequest readMetadataRequest =
255             new ReadMetadataRequest().repositoryId( TEST_REPO_ID ).namespace( "com.example.test" ).projectId(
256                 "test-artifact-module-a" ).projectVersion( "1.0" );
257         ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( readMetadataRequest );
258         assertEquals( "1.0", metadata.getId() );
259
260         MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
261         assertNotNull( facet );
262         assertEquals( "com.example.test", facet.getGroupId() );
263         assertEquals( "test-artifact-module-a", facet.getArtifactId() );
264         assertEquals( "jar", facet.getPackaging() );
265
266         List<String> paths = new ArrayList<>();
267         paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
268         paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
269         paths.add( "target/test-repository/com/example/test/test-artifact-root" );
270
271         deleteTestArtifactWithParent( paths );
272     }
273
274     @Test
275     public void testGetProjectVersionMetadataWithParentNotInAnyRemoteRepo()
276         throws Exception
277     {
278         copyTestArtifactWithParent( "src/test/resources/com/example/test/test-artifact-module-a",
279                                     "target/test-repository/com/example/test/test-artifact-module-a" );
280
281         ReadMetadataRequest readMetadataRequest =
282             new ReadMetadataRequest().repositoryId( TEST_REPO_ID ).namespace( "com.example.test" ).projectId(
283                 "missing-parent" ).projectVersion( "1.1" );
284
285         ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( readMetadataRequest );
286
287         assertEquals( "1.1", metadata.getId() );
288
289         MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
290         assertNotNull( facet );
291         assertEquals( "com.example.test", facet.getGroupId() );
292         assertEquals( "missing-parent", facet.getArtifactId() );
293         assertEquals( "jar", facet.getPackaging() );
294
295         List<String> paths = new ArrayList<>();
296         paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
297         paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
298         paths.add( "target/test-repository/com/example/test/test-artifact-root" );
299
300         deleteTestArtifactWithParent( paths );
301     }
302
303     @Test
304     public void testGetProjectVersionMetadataWithParentSnapshotVersion()
305         throws Exception
306     {
307         copyTestArtifactWithParent( "target/test-classes/com/example/test/test-snapshot-artifact-module-a",
308                                     "target/test-repositorys/com/example/test/test-snapshot-artifact-module-a" );
309         copyTestArtifactWithParent( "target/test-classes/com/example/test/test-snapshot-artifact-root",
310                                     "target/test-repositorys/com/example/test/test-snapshot-artifact-root" );
311         copyTestArtifactWithParent( "src/test/resources/com/example/test/test-artifact-parent",
312                 "target/test-repositorys/com/example/test/test-artifact-parent" );
313
314         ReadMetadataRequest readMetadataRequest =
315             new ReadMetadataRequest( TEST_SNAP_REPO_ID, "com.example.test", "test-snapshot-artifact-module-a",
316                                      "1.1-SNAPSHOT" );
317
318         ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( readMetadataRequest );
319
320         MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
321         assertEquals( "jar", facet.getPackaging() );
322         assertEquals( "com.example.test", facet.getParent().getGroupId() );
323         assertEquals( "test-snapshot-artifact-root", facet.getParent().getArtifactId() );
324         assertEquals( "1.1-SNAPSHOT", facet.getParent().getVersion() );
325         assertEquals( "test-snapshot-artifact-module-a", facet.getArtifactId() );
326         assertEquals( "com.example.test", facet.getGroupId() );
327         assertNull( metadata.getCiManagement() );
328         assertNotNull( metadata.getDescription() );
329
330         checkApacheLicense( metadata );
331
332         assertEquals( "1.1-SNAPSHOT", metadata.getId() );
333         assertEquals( "Test Snapshot Artifact :: Module A", metadata.getName() );
334         String path = "test-snapshot-artifact/trunk/test-snapshot-artifact-module-a";
335         assertEquals( TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
336         assertEquals( TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
337         assertEquals( TEST_SCM_URL_BASE + path, metadata.getScm().getUrl() );
338
339         List<Dependency> dependencies = metadata.getDependencies();
340         assertEquals( 2, dependencies.size() );
341         assertDependency( dependencies.get( 0 ), "commons-io", "commons-io", "1.4" );
342         assertDependency( dependencies.get( 1 ), "junit", "junit", "3.8.1", "test" );
343
344         List<String> paths = new ArrayList<>();
345         paths.add( "target/test-repositorys/com/example/test/test-snapshot-artifact-module-a" );
346         paths.add( "target/test-repositorys/com/example/test/test-snapshot-artifact-root" );
347         deleteTestArtifactWithParent( paths );
348     }
349
350     @Test
351     public void testGetProjectVersionMetadataWithParentSnapshotVersionAndSnapNotAllowed()
352         throws Exception
353     {
354         copyTestArtifactWithParent( "target/test-classes/com/example/test/test-snapshot-artifact-module-a",
355                                     "target/test-repositorys/com/example/test/test-snapshot-artifact-module-a" );
356         copyTestArtifactWithParent( "src/test/resources/com/example/test/test-artifact-parent",
357                 "target/test-repositorys/com/example/test/test-artifact-parent" );
358         copyTestArtifactWithParent( "src/test/resources/com/example/test/test-snapshot-artifact-root",
359                 "target/test-repositorys/com/example/test/test-snapshot-artifact-root" );
360
361         ReadMetadataRequest readMetadataRequest =
362             new ReadMetadataRequest().repositoryId( TEST_SNAP_REPO_ID ).namespace( "com.example.test" ).projectId(
363                 "test-snapshot-artifact-module-a" ).projectVersion( "1.1-SNAPSHOT" );
364         ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( readMetadataRequest );
365
366         MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
367         assertEquals( "jar", facet.getPackaging() );
368         assertEquals( "com.example.test", facet.getParent().getGroupId() );
369         assertEquals( "test-snapshot-artifact-root", facet.getParent().getArtifactId() );
370         assertEquals( "1.1-SNAPSHOT", facet.getParent().getVersion() );
371         assertEquals( "test-snapshot-artifact-module-a", facet.getArtifactId() );
372         assertEquals( "com.example.test", facet.getGroupId() );
373         assertNull( metadata.getCiManagement() );
374         assertNotNull( metadata.getDescription() );
375
376         checkApacheLicense( metadata );
377
378         assertEquals( "1.1-SNAPSHOT", metadata.getId() );
379         assertEquals( "Test Snapshot Artifact :: Module A", metadata.getName() );
380         String path = "test-snapshot-artifact/trunk/test-snapshot-artifact-module-a";
381         assertEquals( TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
382         assertEquals( TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
383         assertEquals( TEST_SCM_URL_BASE + path, metadata.getScm().getUrl() );
384
385         List<Dependency> dependencies = metadata.getDependencies();
386         assertEquals( 2, dependencies.size() );
387         assertDependency( dependencies.get( 0 ), "commons-io", "commons-io", "1.4" );
388         assertDependency( dependencies.get( 1 ), "junit", "junit", "3.8.1", "test" );
389
390         List<String> paths = new ArrayList<>();
391         paths.add( "target/test-repositorys/com/example/test/test-snapshot-artifact-module-a" );
392         paths.add( "target/test-repositorys/com/example/test/test-snapshot-artifact-root" );
393
394         deleteTestArtifactWithParent( paths );
395     }
396
397     @Test
398     public void testGetProjectVersionMetadataWithParentSnapshotVersionAndSnapNotAllowed2()
399         throws Exception
400     {
401         copyTestArtifactWithParent( "src/test/resources/com/example/test/test-artifact-module-b",
402                                     "target/test-repository/com/example/test/test-artifact-module-b" );
403         copyTestArtifactWithParent( "src/test/resources/com/example/test/test-artifact-parent",
404                 "target/test-repository/com/example/test/test-artifact-parent" );
405         copyTestArtifactWithParent( "src/test/resources/com/example/test/test-snapshot-artifact-root",
406                 "target/test-repository/com/example/test/test-snapshot-artifact-root" );
407
408         ReadMetadataRequest readMetadataRequest =
409             new ReadMetadataRequest().repositoryId( TEST_REPO_ID ).namespace( "com.example.test" ).projectId(
410                 "test-artifact-module-b" ).projectVersion( "1.0" );
411
412         ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( readMetadataRequest );
413
414         MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
415         assertEquals( "jar", facet.getPackaging() );
416         assertEquals( "com.example.test", facet.getParent().getGroupId() );
417         assertEquals( "test-snapshot-artifact-root", facet.getParent().getArtifactId() );
418         assertEquals( "1.1-SNAPSHOT", facet.getParent().getVersion() );
419         assertEquals( "test-artifact-module-b", facet.getArtifactId() );
420         assertEquals( "com.example.test", facet.getGroupId() );
421         assertNull( metadata.getCiManagement() );
422         assertNotNull( metadata.getDescription() );
423
424         checkApacheLicense( metadata );
425
426         assertEquals( "1.0", metadata.getId() );
427         assertEquals( "Test Artifact :: Module B", metadata.getName() );
428         String path = "test-snapshot-artifact/trunk/test-artifact-module-b";
429         assertEquals( TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
430         assertEquals( TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
431         assertEquals( TEST_SCM_URL_BASE + path, metadata.getScm().getUrl() );
432
433         List<Dependency> dependencies = metadata.getDependencies();
434         assertEquals( 2, dependencies.size() );
435         assertDependency( dependencies.get( 0 ), "commons-io", "commons-io", "1.4" );
436         assertDependency( dependencies.get( 1 ), "junit", "junit", "3.8.1", "test" );
437
438         List<String> paths = new ArrayList<>();
439         paths.add( "target/test-repository/com/example/test/test-artifact-module-b" );
440         paths.add( "target/test-repository/com/example/test/test-snapshot-artifact-root" );
441
442         deleteTestArtifactWithParent( paths );
443     }
444     // Tests for MRM-1411 - END
445
446     private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )
447     {
448         assertDependency( dependency, groupId, artifactId, version, "compile" );
449     }
450
451     private void assertDependency( Dependency dependency, String groupId, String artifactId, String version,
452                                    String scope )
453     {
454         assertEquals( artifactId, dependency.getArtifactId() );
455         assertEquals( "jar", dependency.getType() );
456         assertEquals( version, dependency.getVersion() );
457         assertEquals( groupId, dependency.getNamespace() );
458         assertEquals( scope, dependency.getScope() );
459         assertNull( dependency.getClassifier() );
460         assertNull( dependency.getSystemPath() );
461     }
462
463     private void assertArtifact( ArtifactMetadata artifact, String id, int size, String sha1, String md5 )
464     {
465         assertEquals( id, artifact.getId() );
466         assertEquals( md5, artifact.getMd5() );
467         assertEquals( sha1, artifact.getSha1() );
468         assertEquals( size, artifact.getSize() );
469         assertEquals( "org.codehaus.plexus", artifact.getNamespace() );
470         assertEquals( "plexus-spring", artifact.getProject() );
471         assertEquals( "1.2", artifact.getVersion() );
472         assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
473     }
474
475     private void assertMailingList( MailingList mailingList, String name, String archive, String post, String subscribe,
476                                     String unsubscribe, List<String> otherArchives, boolean allowPost )
477     {
478         assertEquals( archive, mailingList.getMainArchiveUrl() );
479         if ( allowPost )
480         {
481             assertEquals( post, mailingList.getPostAddress() );
482         }
483         else
484         {
485             assertNull( mailingList.getPostAddress() );
486         }
487         assertEquals( subscribe, mailingList.getSubscribeAddress() );
488         assertEquals( unsubscribe, mailingList.getUnsubscribeAddress() );
489         assertEquals( name, mailingList.getName() );
490         assertEquals( otherArchives, mailingList.getOtherArchives() );
491     }
492
493     private void assertMailingList( String prefix, MailingList mailingList, String name, boolean allowPost,
494                                     String nabbleUrl )
495     {
496         List<String> otherArchives = new ArrayList<>();
497         otherArchives.add( "http://www.mail-archive.com/" + prefix + "@archiva.apache.org" );
498         if ( nabbleUrl != null )
499         {
500             otherArchives.add( nabbleUrl );
501         }
502         otherArchives.add( "http://markmail.org/list/org.apache.archiva." + prefix );
503         assertMailingList( mailingList, name, "http://mail-archives.apache.org/mod_mbox/archiva-" + prefix + "/",
504                            prefix + "@archiva.apache.org", prefix + "-subscribe@archiva.apache.org",
505                            prefix + "-unsubscribe@archiva.apache.org", otherArchives, allowPost );
506     }
507
508     private void checkApacheLicense( ProjectVersionMetadata metadata )
509     {
510         assertEquals( Arrays.asList( new License( "The Apache Software License, Version 2.0",
511                                                   "http://www.apache.org/licenses/LICENSE-2.0.txt" ) ),
512                       metadata.getLicenses() );
513     }
514
515     private void checkOrganizationApache( ProjectVersionMetadata metadata )
516     {
517         assertEquals( "The Apache Software Foundation", metadata.getOrganization().getName() );
518         assertEquals( "http://www.apache.org/", metadata.getOrganization().getUrl() );
519     }
520
521     private void deleteTestArtifactWithParent( List<String> pathsToBeDeleted )
522         throws IOException
523     {
524         for ( String path : pathsToBeDeleted )
525         {
526             Path dir = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), path );
527             org.apache.archiva.common.utils.FileUtils.deleteDirectory( dir );
528
529             assertFalse( Files.exists(dir) );
530         }
531         Path dest = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repository/com/example/test/test-artifact-module-a" );
532         Path parentPom = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repository/com/example/test/test-artifact-parent" );
533         Path rootPom = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repository/com/example/test/test-artifact-root" );
534
535         org.apache.archiva.common.utils.FileUtils.deleteDirectory( dest );
536         org.apache.archiva.common.utils.FileUtils.deleteDirectory( parentPom );
537         org.apache.archiva.common.utils.FileUtils.deleteDirectory( rootPom );
538
539         assertFalse( Files.exists(dest) );
540         assertFalse( Files.exists(parentPom) );
541         assertFalse( Files.exists(rootPom) );
542     }
543
544     private Path copyTestArtifactWithParent( String srcPath, String destPath )
545         throws IOException
546     {
547         Path src = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), srcPath );
548         Path dest = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), destPath );
549
550         FileUtils.copyDirectory( src.toFile(), dest.toFile() );
551         assertTrue( Files.exists(dest) );
552         return dest;
553     }
554
555 }