1 package org.apache.archiva.rest.services;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import org.apache.archiva.maven2.model.Artifact;
22 import org.apache.archiva.rest.api.services.MergeRepositoriesService;
23 import org.apache.commons.io.FileUtils;
24 import static org.assertj.core.api.Assertions.assertThat;
25 import org.junit.After;
26 import org.junit.Before;
27 import org.junit.Test;
28
29 import java.io.File;
30 import java.util.List;
31
32
33
34
35 public class MergeRepositoriesServiceTest
36 extends AbstractArchivaRestTest
37 {
38
39 private static final String TEST_REPOSITORY = "test-repository";
40
41 private File repo = new File( System.getProperty( "builddir" ), "test-repository" );
42
43 private File repoStage = new File( System.getProperty( "builddir" ), "test-repository-stage" );
44
45 @Test
46 public void getMergeConflictedArtifacts()
47 throws Exception
48 {
49 MergeRepositoriesService service = getMergeRepositoriesService( authorizationHeader );
50
51 List<Artifact> artifactMetadatas = service.getMergeConflictedArtifacts( TEST_REPOSITORY + "-stage",
52 TEST_REPOSITORY );
53
54 log.info( "conflicts: {}", artifactMetadatas );
55
56 assertThat( artifactMetadatas ).isNotNull().isNotEmpty().hasSize( 8 );
57 }
58
59 @Test
60 public void merge()
61 throws Exception
62 {
63 String mergedArtifactPath =
64 "org/apache/felix/org.apache.felix.bundlerepository/1.6.4/org.apache.felix.bundlerepository-1.6.4.jar";
65 String mergedArtifactPomPath =
66 "org/apache/felix/org.apache.felix.bundlerepository/1.6.4/org.apache.felix.bundlerepository-1.6.4.pom";
67
68 assertTrue( new File( repoStage, mergedArtifactPath ).exists() );
69 assertTrue( new File( repoStage, mergedArtifactPomPath ).exists() );
70
71 MergeRepositoriesService service = getMergeRepositoriesService( authorizationHeader );
72
73 service.mergeRepositories( TEST_REPOSITORY + "-stage", TEST_REPOSITORY, true );
74
75 assertTrue( new File( repo, mergedArtifactPath ).exists() );
76 assertTrue( new File( repo, mergedArtifactPomPath ).exists() );
77 }
78
79 @After
80 public void deleteStageRepo()
81 throws Exception
82 {
83 waitForScanToComplete( TEST_REPOSITORY );
84
85 deleteTestRepo( TEST_REPOSITORY );
86
87 FileUtils.deleteDirectory( repo );
88 FileUtils.deleteDirectory( repoStage );
89 }
90
91 @Before
92 public void createStageRepo()
93 throws Exception
94 {
95 FileUtils.copyDirectory( new File( System.getProperty( "basedir" ), "src/test/repo-with-osgi" ), repo );
96 FileUtils.copyDirectory( new File( System.getProperty( "basedir" ), "src/test/repo-with-osgi-stage" ),
97 repoStage );
98
99 createStagedNeededRepo( TEST_REPOSITORY, repo.getAbsolutePath(), true );
100 }
101 }