View Javadoc
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 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   * @author Olivier Lamy
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 }