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