1 package org.apache.archiva.rest.services;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.archiva.admin.model.beans.RemoteRepository;
23 import org.apache.archiva.rest.api.services.RemoteRepositoriesService;
24 import org.apache.cxf.jaxrs.client.WebClient;
25 import org.junit.Test;
27 import javax.ws.rs.ForbiddenException;
28 import java.util.List;
29 import java.util.Locale;
32 * @author Olivier Lamy
34 public class RemoteRepositoriesServiceTest
35 extends AbstractArchivaRestTest
39 private void removeRemoteRepositories(String... repos) {
41 RemoteRepositoriesService service = getRemoteRepositoriesService();
42 WebClient.client( service ).header( "Authorization", authorizationHeader );
43 for (String repo : repos ) {
45 service.deleteRemoteRepository(repo);
46 } catch (Throwable ex) {
47 log.warn("Could not remove repo {}", repo);
51 } catch (Throwable ex) {
56 @Test( expected = ForbiddenException.class )
57 public void listRemoteRepositoriesKarmaFailed()
60 RemoteRepositoriesService service = getRemoteRepositoriesService();
63 assertFalse( service.getRemoteRepositories().isEmpty() );
65 catch ( ForbiddenException e )
67 assertEquals( 403, e.getResponse().getStatus() );
73 public void listRemoteRepositoriesKarma()
76 RemoteRepositoriesService service = getRemoteRepositoriesService();
78 WebClient.client( service ).header( "Authorization", authorizationHeader );
79 WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
80 List<RemoteRepository> repos = service.getRemoteRepositories();
81 assertFalse( repos.isEmpty() );
82 log.info( "repos {}", repos );
87 public void addAndDeleteRemoteRepository()
90 RemoteRepositoriesService service = getRemoteRepositoriesService();
92 WebClient.client( service ).header( "Authorization", authorizationHeader );
94 int initialSize = service.getRemoteRepositories().size();
96 service.addRemoteRepository( getRemoteRepository() );
98 assertNotNull( service.getRemoteRepository( "id-new" ) );
100 assertEquals( getRemoteRepository().getName(), service.getRemoteRepository( "id-new" ).getName() );
101 assertEquals( getRemoteRepository().getUrl(), service.getRemoteRepository( "id-new" ).getUrl() );
102 assertEquals( getRemoteRepository().getLayout(), service.getRemoteRepository( "id-new" ).getLayout() );
103 assertEquals( getRemoteRepository().getUserName(), service.getRemoteRepository( "id-new" ).getUserName() );
104 assertEquals( getRemoteRepository().getPassword(), service.getRemoteRepository( "id-new" ).getPassword() );
105 assertEquals( getRemoteRepository().getTimeout(), service.getRemoteRepository( "id-new" ).getTimeout() );
106 assertEquals( getRemoteRepository().getDescription(),
107 service.getRemoteRepository( "id-new" ).getDescription() );
109 assertEquals( initialSize + 1, service.getRemoteRepositories().size() );
111 service.deleteRemoteRepository( "id-new" );
113 assertNull( service.getRemoteRepository( "id-new" ) );
115 assertEquals( initialSize, service.getRemoteRepositories().size() );
120 public void addAndUpdateAndDeleteRemoteRepository()
123 RemoteRepositoriesService service = getRemoteRepositoriesService();
125 WebClient.client( service ).header( "Authorization", authorizationHeader );
127 int initialSize = service.getRemoteRepositories().size();
129 service.addRemoteRepository( getRemoteRepository() );
131 assertNotNull( service.getRemoteRepository( "id-new" ) );
133 assertEquals( getRemoteRepository().getName(), service.getRemoteRepository( "id-new" ).getName() );
134 assertEquals( getRemoteRepository().getUrl(), service.getRemoteRepository( "id-new" ).getUrl() );
135 assertEquals( getRemoteRepository().getLayout(), service.getRemoteRepository( "id-new" ).getLayout() );
136 assertEquals( getRemoteRepository().getUserName(), service.getRemoteRepository( "id-new" ).getUserName() );
137 assertEquals( getRemoteRepository().getPassword(), service.getRemoteRepository( "id-new" ).getPassword() );
138 assertEquals( getRemoteRepository().getTimeout(), service.getRemoteRepository( "id-new" ).getTimeout() );
140 assertEquals( initialSize + 1, service.getRemoteRepositories().size() );
142 RemoteRepository repo = getRemoteRepository();
143 repo.setName( "name changed" );
144 repo.setPassword( "new password" );
145 repo.setUserName( "new username" );
146 repo.setUrl( "http://foo.new.org" );
147 repo.setDescription( "foo bar" );
149 service.updateRemoteRepository( repo );
151 assertEquals( repo.getName(), service.getRemoteRepository( "id-new" ).getName() );
152 assertEquals( repo.getUrl(), service.getRemoteRepository( "id-new" ).getUrl() );
153 assertEquals( repo.getLayout(), service.getRemoteRepository( "id-new" ).getLayout() );
154 assertEquals( repo.getUserName(), service.getRemoteRepository( "id-new" ).getUserName() );
155 assertEquals( repo.getPassword(), service.getRemoteRepository( "id-new" ).getPassword() );
156 assertEquals( repo.getTimeout(), service.getRemoteRepository( "id-new" ).getTimeout() );
157 assertEquals( repo.getDescription(), service.getRemoteRepository( "id-new" ).getDescription() );
159 service.deleteRemoteRepository( "id-new" );
161 assertNull( service.getRemoteRepository( "id-new" ) );
163 assertEquals( initialSize, service.getRemoteRepositories().size() );
168 public void checkRemoteConnectivity()
171 RemoteRepositoriesService service = getRemoteRepositoriesService();
173 WebClient.client(service).header("Authorization", authorizationHeader);
175 int initialSize = service.getRemoteRepositories().size();
177 service.addRemoteRepository(getRemoteRepository());
179 assertTrue(service.checkRemoteConnectivity("id-new"));
181 removeRemoteRepositories("id-new");
187 * Check maven repository
190 public void checkRemoteConnectivity2()
193 RemoteRepositoriesService service = getRemoteRepositoriesService();
195 WebClient.client(service).header("Authorization", authorizationHeader);
197 int initialSize = service.getRemoteRepositories().size();
199 service.addRemoteRepository(getRemoteMavenRepository());
201 assertTrue(service.checkRemoteConnectivity("id-maven1"));
203 removeRemoteRepositories("id-maven1");
210 * Check oracle repository that allows not browsing (MRM-1933)
213 public void checkRemoteConnectivity3()
216 RemoteRepositoriesService service = getRemoteRepositoriesService();
218 WebClient.client(service).header("Authorization", authorizationHeader);
219 WebClient.client(service).accept("application/json");
221 int initialSize = service.getRemoteRepositories().size();
223 service.addRemoteRepository(getRemoteOracleRepository());
225 assertTrue(service.checkRemoteConnectivity("id-oracle"));
227 removeRemoteRepositories("id-oracle");
232 RemoteRepository getRemoteRepository()
234 return new RemoteRepository( Locale.getDefault( ), "id-new", "new one", "http://www.apache.org", "default", "foo", "foopassword", 120,
239 RemoteRepository getRemoteMavenRepository()
241 return new RemoteRepository( Locale.getDefault( ),"id-maven1", "Maven1", "https://repo.maven.apache.org/maven2", "default", "foo", "foopassword", 120,
246 RemoteRepository getRemoteOracleRepository()
248 return new RemoteRepository( Locale.getDefault( ),"id-oracle", "Oracle", "http://download.oracle.com/maven", "default", "foo", "foopassword", 120,