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