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 @Test( expected = ForbiddenException.class )
40 public void listRemoteRepositoriesKarmaFailed()
43 RemoteRepositoriesService service = getRemoteRepositoriesService();
46 assertFalse( service.getRemoteRepositories().isEmpty() );
48 catch ( ForbiddenException e )
50 assertEquals( 403, e.getResponse().getStatus() );
56 public void listRemoteRepositoriesKarma()
59 RemoteRepositoriesService service = getRemoteRepositoriesService();
61 WebClient.client( service ).header( "Authorization", authorizationHeader );
62 WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
63 List<RemoteRepository> repos = service.getRemoteRepositories();
64 assertFalse( repos.isEmpty() );
65 log.info( "repos {}", repos );
70 public void addAndDeleteRemoteRepository()
73 RemoteRepositoriesService service = getRemoteRepositoriesService();
75 WebClient.client( service ).header( "Authorization", authorizationHeader );
77 int initialSize = service.getRemoteRepositories().size();
79 service.addRemoteRepository( getRemoteRepository() );
81 assertNotNull( service.getRemoteRepository( "id-new" ) );
83 assertEquals( getRemoteRepository().getName(), service.getRemoteRepository( "id-new" ).getName() );
84 assertEquals( getRemoteRepository().getUrl(), service.getRemoteRepository( "id-new" ).getUrl() );
85 assertEquals( getRemoteRepository().getLayout(), service.getRemoteRepository( "id-new" ).getLayout() );
86 assertEquals( getRemoteRepository().getUserName(), service.getRemoteRepository( "id-new" ).getUserName() );
87 assertEquals( getRemoteRepository().getPassword(), service.getRemoteRepository( "id-new" ).getPassword() );
88 assertEquals( getRemoteRepository().getTimeout(), service.getRemoteRepository( "id-new" ).getTimeout() );
89 assertEquals( getRemoteRepository().getDescription(),
90 service.getRemoteRepository( "id-new" ).getDescription() );
92 assertEquals( initialSize + 1, service.getRemoteRepositories().size() );
94 service.deleteRemoteRepository( "id-new" );
96 assertNull( service.getRemoteRepository( "id-new" ) );
98 assertEquals( initialSize, service.getRemoteRepositories().size() );
103 public void addAndUpdateAndDeleteRemoteRepository()
106 RemoteRepositoriesService service = getRemoteRepositoriesService();
108 WebClient.client( service ).header( "Authorization", authorizationHeader );
110 int initialSize = service.getRemoteRepositories().size();
112 service.addRemoteRepository( getRemoteRepository() );
114 assertNotNull( service.getRemoteRepository( "id-new" ) );
116 assertEquals( getRemoteRepository().getName(), service.getRemoteRepository( "id-new" ).getName() );
117 assertEquals( getRemoteRepository().getUrl(), service.getRemoteRepository( "id-new" ).getUrl() );
118 assertEquals( getRemoteRepository().getLayout(), service.getRemoteRepository( "id-new" ).getLayout() );
119 assertEquals( getRemoteRepository().getUserName(), service.getRemoteRepository( "id-new" ).getUserName() );
120 assertEquals( getRemoteRepository().getPassword(), service.getRemoteRepository( "id-new" ).getPassword() );
121 assertEquals( getRemoteRepository().getTimeout(), service.getRemoteRepository( "id-new" ).getTimeout() );
123 assertEquals( initialSize + 1, service.getRemoteRepositories().size() );
125 RemoteRepository repo = getRemoteRepository();
126 repo.setName( "name changed" );
127 repo.setPassword( "new password" );
128 repo.setUserName( "new username" );
129 repo.setUrl( "http://foo.new.org" );
130 repo.setDescription( "foo bar" );
132 service.updateRemoteRepository( repo );
134 assertEquals( repo.getName(), service.getRemoteRepository( "id-new" ).getName() );
135 assertEquals( repo.getUrl(), service.getRemoteRepository( "id-new" ).getUrl() );
136 assertEquals( repo.getLayout(), service.getRemoteRepository( "id-new" ).getLayout() );
137 assertEquals( repo.getUserName(), service.getRemoteRepository( "id-new" ).getUserName() );
138 assertEquals( repo.getPassword(), service.getRemoteRepository( "id-new" ).getPassword() );
139 assertEquals( repo.getTimeout(), service.getRemoteRepository( "id-new" ).getTimeout() );
140 assertEquals( repo.getDescription(), service.getRemoteRepository( "id-new" ).getDescription() );
142 service.deleteRemoteRepository( "id-new" );
144 assertNull( service.getRemoteRepository( "id-new" ) );
146 assertEquals( initialSize, service.getRemoteRepositories().size() );
151 public void checkRemoteConnectivity()
153 RemoteRepositoriesService service = getRemoteRepositoriesService();
155 WebClient.client(service).header("Authorization", authorizationHeader);
157 int initialSize = service.getRemoteRepositories().size();
159 service.addRemoteRepository(getRemoteRepository());
161 assertTrue(service.checkRemoteConnectivity("id-new"));
166 * Check maven repository
169 public void checkRemoteConnectivity2()
171 RemoteRepositoriesService service = getRemoteRepositoriesService();
173 WebClient.client(service).header("Authorization", authorizationHeader);
175 int initialSize = service.getRemoteRepositories().size();
177 service.addRemoteRepository(getRemoteMavenRepository());
179 assertTrue(service.checkRemoteConnectivity("id-maven1"));
185 * Check oracle repository that allows not browsing (MRM-1933)
188 public void checkRemoteConnectivity3()
190 RemoteRepositoriesService service = getRemoteRepositoriesService();
192 WebClient.client(service).header("Authorization", authorizationHeader);
193 WebClient.client(service).accept("application/json");
195 int initialSize = service.getRemoteRepositories().size();
197 service.addRemoteRepository(getRemoteOracleRepository());
199 assertTrue(service.checkRemoteConnectivity("id-oracle"));
203 RemoteRepository getRemoteRepository()
205 return new RemoteRepository( Locale.getDefault( ), "id-new", "new one", "http://www.apache.org", "default", "foo", "foopassword", 120,
210 RemoteRepository getRemoteMavenRepository()
212 return new RemoteRepository( Locale.getDefault( ),"id-maven1", "Maven1", "http://repo.maven.apache.org/maven2", "default", "foo", "foopassword", 120,
217 RemoteRepository getRemoteOracleRepository()
219 return new RemoteRepository( Locale.getDefault( ),"id-oracle", "Oracle", "http://download.oracle.com/maven", "default", "foo", "foopassword", 120,