]> source.dussan.org Git - archiva.git/blob
60b4b51168844866530e521e2bb0ead30a4f7252
[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.junit.After;
25 import org.junit.Before;
26 import org.junit.Test;
27
28 import java.nio.file.Files;
29 import java.nio.file.Path;
30 import java.nio.file.Paths;
31 import java.util.List;
32
33 import static org.assertj.core.api.Assertions.assertThat;
34
35 /**
36  * @author Olivier Lamy
37  */
38 public class MergeRepositoriesServiceTest
39     extends AbstractArchivaRestTest
40 {
41
42     private static final String TEST_REPOSITORY = "test-repository";
43     private static final String TEST_REPOSITORY_STAGE = TEST_REPOSITORY + "-stage";
44
45     private Path repo = getAppserverBase().resolve("data/repositories").resolve( "test-repository" );
46
47     private Path repoStage = getAppserverBase().resolve("data/repositories").resolve( "test-repository-stage" );
48
49     private int maxChecks = 10;
50     private int checkWaitMs = 500;
51
52     @Test
53     public void getMergeConflictedArtifacts()
54         throws Exception
55     {
56         MergeRepositoriesService service = getMergeRepositoriesService( authorizationHeader );
57
58         waitForScanToComplete( TEST_REPOSITORY );
59         waitForScanToComplete( TEST_REPOSITORY_STAGE );
60
61
62         int checks = maxChecks;
63         Throwable ex = null;
64         while(checks-->0) {
65             try {
66                 log.info("Test Try " + checks);
67                 List<Artifact> artifactMetadatas = service.getMergeConflictedArtifacts( TEST_REPOSITORY_STAGE,
68                         TEST_REPOSITORY );
69                 log.info("conflicts: {}", artifactMetadatas);
70
71                 assertThat(artifactMetadatas).isNotNull().isNotEmpty().hasSize(8);
72                 return;
73             } catch (Throwable e) {
74                 ex = e;
75             }
76             Thread.currentThread().sleep(checkWaitMs);
77         }
78         if (ex!=null && ex instanceof AssertionError) {
79             throw (AssertionError)ex;
80         } else {
81             throw new Exception(ex);
82         }
83
84     }
85
86     @Test
87     public void merge()
88         throws Exception
89     {
90         String mergedArtifactPath =
91             "org/apache/felix/org.apache.felix.bundlerepository/1.6.4/org.apache.felix.bundlerepository-1.6.4.jar";
92         String mergedArtifactPomPath =
93             "org/apache/felix/org.apache.felix.bundlerepository/1.6.4/org.apache.felix.bundlerepository-1.6.4.pom";
94
95         assertTrue( Files.exists(repoStage.resolve(mergedArtifactPath)) );
96         assertTrue( Files.exists(repoStage.resolve(mergedArtifactPomPath)) );
97
98         waitForScanToComplete( TEST_REPOSITORY );
99         waitForScanToComplete( TEST_REPOSITORY_STAGE );
100
101         MergeRepositoriesService service = getMergeRepositoriesService( authorizationHeader );
102
103         int checks = maxChecks;
104         Throwable ex = null;
105         while(checks-->0) {
106             try {
107                 log.info("Test Try " + checks);
108                 service.mergeRepositories(TEST_REPOSITORY_STAGE, TEST_REPOSITORY, true);
109
110                 assertTrue(Files.exists(repo.resolve(mergedArtifactPath)));
111                 assertTrue(Files.exists(repo.resolve(mergedArtifactPomPath)));
112                 return;
113             } catch (Throwable e) {
114                 log.info("Exception {}, {}", e.getMessage(), e.getClass());
115                 ex = e;
116             }
117             Thread.currentThread().sleep(checkWaitMs);
118         }
119         if (ex!=null && ex instanceof AssertionError) {
120             throw (AssertionError)ex;
121         } else if (ex!=null) {
122             throw new Exception(ex);
123         }
124
125     }
126
127     @After
128     public void deleteStageRepo()
129         throws Exception
130     {
131         waitForScanToComplete( TEST_REPOSITORY );
132         waitForScanToComplete( TEST_REPOSITORY_STAGE );
133
134         deleteTestRepo( TEST_REPOSITORY );
135
136         org.apache.archiva.common.utils.FileUtils.deleteDirectory( repo );
137         org.apache.archiva.common.utils.FileUtils.deleteDirectory( repoStage );
138     }
139
140     @Before
141     public void createStageRepo()
142         throws Exception
143     {
144         // FileUtils.copyDirectory( Paths.get( System.getProperty( "basedir" ), "src/test/repo-with-osgi" ).toFile(), repo.toFile() );
145
146         Path srcRepo = getProjectDirectory().resolve(  "src/test/repo-with-osgi" );
147         createStagedNeededRepo( TEST_REPOSITORY, srcRepo , getProjectDirectory().resolve("src/test/repo-with-osgi-stage" ),  true );
148
149     }
150 }