1 package org.apache.archiva.rest.services;
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
11 * 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
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;
28 import java.nio.file.Files;
29 import java.nio.file.Path;
30 import java.nio.file.Paths;
31 import java.util.List;
33 import static org.assertj.core.api.Assertions.assertThat;
36 * @author Olivier Lamy
38 public class MergeRepositoriesServiceTest
39 extends AbstractArchivaRestTest
42 private static final String TEST_REPOSITORY = "test-repository";
43 private static final String TEST_REPOSITORY_STAGE = TEST_REPOSITORY + "-stage";
45 private Path repo = getAppserverBase().resolve("data/repositories").resolve( "test-repository" );
47 private Path repoStage = getAppserverBase().resolve("data/repositories").resolve( "test-repository-stage" );
49 private int maxChecks = 10;
50 private int checkWaitMs = 500;
53 public void getMergeConflictedArtifacts()
56 MergeRepositoriesService service = getMergeRepositoriesService( authorizationHeader );
58 waitForScanToComplete( TEST_REPOSITORY );
59 waitForScanToComplete( TEST_REPOSITORY_STAGE );
62 int checks = maxChecks;
66 log.info("Test Try " + checks);
67 List<Artifact> artifactMetadatas = service.getMergeConflictedArtifacts( TEST_REPOSITORY_STAGE,
69 log.info("conflicts: {}", artifactMetadatas);
71 assertThat(artifactMetadatas).isNotNull().isNotEmpty().hasSize(8);
73 } catch (Throwable e) {
76 Thread.currentThread().sleep(checkWaitMs);
78 if (ex!=null && ex instanceof AssertionError) {
79 throw (AssertionError)ex;
81 throw new Exception(ex);
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";
95 assertTrue( Files.exists(repoStage.resolve(mergedArtifactPath)) );
96 assertTrue( Files.exists(repoStage.resolve(mergedArtifactPomPath)) );
98 waitForScanToComplete( TEST_REPOSITORY );
99 waitForScanToComplete( TEST_REPOSITORY_STAGE );
101 MergeRepositoriesService service = getMergeRepositoriesService( authorizationHeader );
103 int checks = maxChecks;
107 log.info("Test Try " + checks);
108 service.mergeRepositories(TEST_REPOSITORY_STAGE, TEST_REPOSITORY, true);
110 assertTrue(Files.exists(repo.resolve(mergedArtifactPath)));
111 assertTrue(Files.exists(repo.resolve(mergedArtifactPomPath)));
113 } catch (Throwable e) {
114 log.info("Exception {}, {}", e.getMessage(), e.getClass());
117 Thread.currentThread().sleep(checkWaitMs);
119 if (ex!=null && ex instanceof AssertionError) {
120 throw (AssertionError)ex;
121 } else if (ex!=null) {
122 throw new Exception(ex);
128 public void deleteStageRepo()
131 waitForScanToComplete( TEST_REPOSITORY );
132 waitForScanToComplete( TEST_REPOSITORY_STAGE );
134 deleteTestRepo( TEST_REPOSITORY );
136 org.apache.archiva.common.utils.FileUtils.deleteDirectory( repo );
137 org.apache.archiva.common.utils.FileUtils.deleteDirectory( repoStage );
141 public void createStageRepo()
144 // FileUtils.copyDirectory( Paths.get( System.getProperty( "basedir" ), "src/test/repo-with-osgi" ).toFile(), repo.toFile() );
146 Path srcRepo = getProjectDirectory().resolve( "src/test/repo-with-osgi" );
147 createStagedNeededRepo( TEST_REPOSITORY, srcRepo , true );
148 FileUtils.copyDirectory( getProjectDirectory().resolve("src/test/repo-with-osgi-stage" ).toFile(),
149 repoStage.toFile() );