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.

CopyArtifactTest.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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.rest.api.model.ArtifactTransferRequest;
  21. import org.apache.archiva.rest.api.services.RepositoriesService;
  22. import org.junit.Ignore;
  23. import org.junit.Test;
  24. import javax.ws.rs.InternalServerErrorException;
  25. import java.nio.file.Files;
  26. import java.nio.file.Path;
  27. import java.nio.file.Paths;
  28. /**
  29. * @author Olivier Lamy
  30. */
  31. public class CopyArtifactTest
  32. extends AbstractArchivaRestTest
  33. {
  34. @Test
  35. public void copyToAnEmptyRepo()
  36. throws Exception
  37. {
  38. try
  39. {
  40. initSourceTargetRepo();
  41. // START SNIPPET: copy-artifact
  42. // configure the artifact you want to copy
  43. // if package ommited default will be jar
  44. ArtifactTransferRequest artifactTransferRequest = new ArtifactTransferRequest();
  45. artifactTransferRequest.setGroupId( "org.apache.karaf.features" );
  46. artifactTransferRequest.setArtifactId( "org.apache.karaf.features.core" );
  47. artifactTransferRequest.setVersion( "2.2.2" );
  48. artifactTransferRequest.setRepositoryId( SOURCE_REPO_ID );
  49. artifactTransferRequest.setTargetRepositoryId( TARGET_REPO_ID );
  50. // retrieve the service
  51. RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader );
  52. // copy the artifact
  53. Boolean res = repositoriesService.copyArtifact( artifactTransferRequest );
  54. // END SNIPPET: copy-artifact
  55. assertTrue( res );
  56. String targetRepoPath = getManagedRepositoriesService( authorizationHeader ).getManagedRepository(
  57. TARGET_REPO_ID ).getLocation();
  58. Path artifact = Paths.get( targetRepoPath,
  59. "/org/apache/karaf/features/org.apache.karaf.features.core/2.2.2/org.apache.karaf.features.core-2.2.2.jar" );
  60. assertTrue( Files.exists(artifact) );
  61. Path pom = Paths.get( targetRepoPath,
  62. "/org/apache/karaf/features/org.apache.karaf.features.core/2.2.2/org.apache.karaf.features.core-2.2.2.pom" );
  63. assertTrue( "not exists " + pom, Files.exists(pom) );
  64. // TODO find a way to force metadata generation and test it !!
  65. }
  66. finally
  67. {
  68. cleanRepos();
  69. }
  70. }
  71. @Test( expected = InternalServerErrorException.class )
  72. public void copyNonExistingArtifact()
  73. throws Throwable
  74. {
  75. try
  76. {
  77. initSourceTargetRepo();
  78. ArtifactTransferRequest artifactTransferRequest = new ArtifactTransferRequest();
  79. artifactTransferRequest.setGroupId( "org.apache.karaf.features" );
  80. artifactTransferRequest.setArtifactId( "org.apache.karaf.features.core" );
  81. artifactTransferRequest.setVersion( "3.0.6552" );
  82. artifactTransferRequest.setRepositoryId( SOURCE_REPO_ID );
  83. artifactTransferRequest.setTargetRepositoryId( TARGET_REPO_ID );
  84. RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader );
  85. repositoriesService.copyArtifact( artifactTransferRequest );
  86. }
  87. catch ( InternalServerErrorException e )
  88. {
  89. // FIXME this doesn't work anymore with cxf 3.x????
  90. //Assertions.assertThat( e.getResponse().getStatusInfo().getReasonPhrase() ) //
  91. // .contains( "cannot find artifact" );
  92. // previous test with cxf 2.x
  93. //assertTrue( e.getMessage() + " do not contains ''",
  94. // StringUtils.contains( e.getMessage(), "cannot find artifact" ) );
  95. throw e;
  96. }
  97. finally
  98. {
  99. cleanRepos();
  100. }
  101. }
  102. @Ignore
  103. public void copyToAnExistingRepo()
  104. throws Exception
  105. {
  106. initSourceTargetRepo();
  107. cleanRepos();
  108. }
  109. }