You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MergeRepositoriesServiceTest.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. import org.apache.archiva.maven2.model.Artifact;
  21. import org.apache.archiva.rest.api.services.MergeRepositoriesService;
  22. import org.apache.commons.io.FileUtils;
  23. import org.junit.After;
  24. import org.junit.Before;
  25. import org.junit.Test;
  26. import java.nio.file.Files;
  27. import java.nio.file.Path;
  28. import java.nio.file.Paths;
  29. import java.util.List;
  30. import static org.assertj.core.api.Assertions.assertThat;
  31. /**
  32. * @author Olivier Lamy
  33. */
  34. public class MergeRepositoriesServiceTest
  35. extends AbstractArchivaRestTest
  36. {
  37. private static final String TEST_REPOSITORY = "test-repository";
  38. private Path repo = Paths.get( System.getProperty( "basedir" ),"target","repositories-merge", "test-repository" );
  39. private Path repoStage = Paths.get( System.getProperty( "basedir" ),"target","repositories-merge", "test-repository-stage" );
  40. @Test
  41. public void getMergeConflictedArtifacts()
  42. throws Exception
  43. {
  44. MergeRepositoriesService service = getMergeRepositoriesService( authorizationHeader );
  45. List<Artifact> artifactMetadatas = service.getMergeConflictedArtifacts( TEST_REPOSITORY + "-stage",
  46. TEST_REPOSITORY );
  47. log.info( "conflicts: {}", artifactMetadatas );
  48. assertThat( artifactMetadatas ).isNotNull().isNotEmpty().hasSize( 8 );
  49. }
  50. @Test
  51. public void merge()
  52. throws Exception
  53. {
  54. String mergedArtifactPath =
  55. "org/apache/felix/org.apache.felix.bundlerepository/1.6.4/org.apache.felix.bundlerepository-1.6.4.jar";
  56. String mergedArtifactPomPath =
  57. "org/apache/felix/org.apache.felix.bundlerepository/1.6.4/org.apache.felix.bundlerepository-1.6.4.pom";
  58. assertTrue( Files.exists(repoStage.resolve(mergedArtifactPath)) );
  59. assertTrue( Files.exists(repoStage.resolve(mergedArtifactPomPath)) );
  60. MergeRepositoriesService service = getMergeRepositoriesService( authorizationHeader );
  61. service.mergeRepositories( TEST_REPOSITORY + "-stage", TEST_REPOSITORY, true );
  62. assertTrue( Files.exists(repo.resolve(mergedArtifactPath)) );
  63. assertTrue( Files.exists(repo.resolve(mergedArtifactPomPath)) );
  64. }
  65. @After
  66. public void deleteStageRepo()
  67. throws Exception
  68. {
  69. waitForScanToComplete( TEST_REPOSITORY );
  70. deleteTestRepo( TEST_REPOSITORY );
  71. org.apache.archiva.common.utils.FileUtils.deleteDirectory( repo );
  72. org.apache.archiva.common.utils.FileUtils.deleteDirectory( repoStage );
  73. }
  74. @Before
  75. public void createStageRepo()
  76. throws Exception
  77. {
  78. // FileUtils.copyDirectory( Paths.get( System.getProperty( "basedir" ), "src/test/repo-with-osgi" ).toFile(), repo.toFile() );
  79. Path srcRepo = Paths.get( System.getProperty( "basedir" ), "src/test/repo-with-osgi" );
  80. createStagedNeededRepo( TEST_REPOSITORY, srcRepo.toAbsolutePath().toString(), true );
  81. FileUtils.copyDirectory( getBasedir().resolve("src/test/repo-with-osgi-stage" ).toFile(),
  82. repoStage.toFile() );
  83. }
  84. }