]> source.dussan.org Git - archiva.git/blob
54746fc1d0459602c4b1f755d93683ab3b30b372
[archiva.git] /
1 package org.apache.archiva.rest.services;
2 /*
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
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 org.apache.archiva.maven2.model.Artifact;
22 import org.apache.archiva.rest.api.services.MergeRepositoriesService;
23 import org.apache.commons.io.FileUtils;
24 import org.fest.assertions.api.Assertions;
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  * @author Olivier Lamy
34  */
35 public class MergeRepositoriesServiceTest
36     extends AbstractArchivaRestTest
37 {
38
39     private File repo = new File( System.getProperty( "builddir" ), "test-repository" );
40
41     private File repoStage = new File( System.getProperty( "builddir" ), "test-repository-stage" );
42
43     @Override
44     @Before
45     public void startServer()
46         throws Exception
47     {
48
49         FileUtils.copyDirectory( new File( System.getProperty( "basedir" ), "src/test/repo-with-osgi" ), repo );
50         FileUtils.copyDirectory( new File( System.getProperty( "basedir" ), "src/test/repo-with-osgi-stage" ),
51                                  repoStage );
52         super.startServer();
53
54     }
55
56     @Override
57     @After
58     public void stopServer()
59         throws Exception
60     {
61         // TODO delete repositories
62         super.stopServer();
63         FileUtils.deleteDirectory( repo );
64         FileUtils.deleteDirectory( repoStage );
65     }
66
67     @Test
68     public void getMergeConflictedArtifacts()
69         throws Exception
70     {
71         String testRepoId = "test-repository";
72         try
73         {
74
75             createStagedNeededRepo( testRepoId, repo.getAbsolutePath(), true );
76
77             MergeRepositoriesService service = getMergeRepositoriesService( authorizationHeader );
78
79             List<Artifact> artifactMetadatas = service.getMergeConflictedArtifacts( testRepoId + "-stage", testRepoId );
80
81             log.info( "conflicts: {}", artifactMetadatas );
82
83             Assertions.assertThat( artifactMetadatas ).isNotNull().isNotEmpty().hasSize( 8 );
84
85
86         }
87         catch ( Exception e )
88         {
89             log.error( e.getMessage(), e );
90             throw e;
91         }
92         finally
93         {
94             deleteTestRepo( testRepoId );
95         }
96     }
97
98     @Test
99     public void merge()
100         throws Exception
101     {
102         String testRepoId = "test-repository";
103         try
104         {
105             createStagedNeededRepo( testRepoId, repo.getAbsolutePath(), true );
106
107             String mergedArtifactPath =
108                 "org/apache/felix/org.apache.felix.bundlerepository/1.6.4/org.apache.felix.bundlerepository-1.6.4.jar";
109             String mergedArtifactPomPath =
110                 "org/apache/felix/org.apache.felix.bundlerepository/1.6.4/org.apache.felix.bundlerepository-1.6.4.pom";
111
112             assertTrue( new File( repoStage, mergedArtifactPath ).exists() );
113             assertTrue( new File( repoStage, mergedArtifactPomPath ).exists() );
114
115             MergeRepositoriesService service = getMergeRepositoriesService( authorizationHeader );
116
117             service.mergeRepositories( testRepoId + "-stage", testRepoId, true );
118
119             assertTrue( new File( repo, mergedArtifactPath ).exists() );
120             assertTrue( new File( repo, mergedArtifactPomPath ).exists() );
121
122         }
123         catch ( Exception e )
124         {
125             log.error( e.getMessage(), e );
126             throw e;
127         }
128         finally
129         {
130             deleteTestRepo( testRepoId );
131         }
132     }
133 }