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;
31 * @author Olivier Lamy
33 public class RemoteRepositoriesServiceTest
34 extends AbstractArchivaRestTest
38 @Test( expected = ForbiddenException.class )
39 public void listRemoteRepositoriesKarmaFailed()
42 RemoteRepositoriesService service = getRemoteRepositoriesService();
45 assertFalse( service.getRemoteRepositories().isEmpty() );
47 catch ( ForbiddenException e )
49 assertEquals( 403, e.getResponse().getStatus() );
55 public void listRemoteRepositoriesKarma()
58 RemoteRepositoriesService service = getRemoteRepositoriesService();
60 WebClient.client( service ).header( "Authorization", authorizationHeader );
61 WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
62 List<RemoteRepository> repos = service.getRemoteRepositories();
63 assertFalse( repos.isEmpty() );
64 log.info( "repos {}", repos );
69 public void addAndDeleteRemoteRepository()
72 RemoteRepositoriesService service = getRemoteRepositoriesService();
74 WebClient.client( service ).header( "Authorization", authorizationHeader );
76 int initialSize = service.getRemoteRepositories().size();
78 service.addRemoteRepository( getRemoteRepository() );
80 assertNotNull( service.getRemoteRepository( "id-new" ) );
82 assertEquals( getRemoteRepository().getName(), service.getRemoteRepository( "id-new" ).getName() );
83 assertEquals( getRemoteRepository().getUrl(), service.getRemoteRepository( "id-new" ).getUrl() );
84 assertEquals( getRemoteRepository().getLayout(), service.getRemoteRepository( "id-new" ).getLayout() );
85 assertEquals( getRemoteRepository().getUserName(), service.getRemoteRepository( "id-new" ).getUserName() );
86 assertEquals( getRemoteRepository().getPassword(), service.getRemoteRepository( "id-new" ).getPassword() );
87 assertEquals( getRemoteRepository().getTimeout(), service.getRemoteRepository( "id-new" ).getTimeout() );
88 assertEquals( getRemoteRepository().getDescription(),
89 service.getRemoteRepository( "id-new" ).getDescription() );
91 assertEquals( initialSize + 1, service.getRemoteRepositories().size() );
93 service.deleteRemoteRepository( "id-new" );
95 assertNull( service.getRemoteRepository( "id-new" ) );
97 assertEquals( initialSize, service.getRemoteRepositories().size() );
102 public void addAndUpdateAndDeleteRemoteRepository()
105 RemoteRepositoriesService service = getRemoteRepositoriesService();
107 WebClient.client( service ).header( "Authorization", authorizationHeader );
109 int initialSize = service.getRemoteRepositories().size();
111 service.addRemoteRepository( getRemoteRepository() );
113 assertNotNull( service.getRemoteRepository( "id-new" ) );
115 assertEquals( getRemoteRepository().getName(), service.getRemoteRepository( "id-new" ).getName() );
116 assertEquals( getRemoteRepository().getUrl(), service.getRemoteRepository( "id-new" ).getUrl() );
117 assertEquals( getRemoteRepository().getLayout(), service.getRemoteRepository( "id-new" ).getLayout() );
118 assertEquals( getRemoteRepository().getUserName(), service.getRemoteRepository( "id-new" ).getUserName() );
119 assertEquals( getRemoteRepository().getPassword(), service.getRemoteRepository( "id-new" ).getPassword() );
120 assertEquals( getRemoteRepository().getTimeout(), service.getRemoteRepository( "id-new" ).getTimeout() );
122 assertEquals( initialSize + 1, service.getRemoteRepositories().size() );
124 RemoteRepository repo = getRemoteRepository();
125 repo.setName( "name changed" );
126 repo.setPassword( "new password" );
127 repo.setUserName( "new username" );
128 repo.setUrl( "http://foo.new.org" );
129 repo.setDescription( "foo bar" );
131 service.updateRemoteRepository( repo );
133 assertEquals( repo.getName(), service.getRemoteRepository( "id-new" ).getName() );
134 assertEquals( repo.getUrl(), service.getRemoteRepository( "id-new" ).getUrl() );
135 assertEquals( repo.getLayout(), service.getRemoteRepository( "id-new" ).getLayout() );
136 assertEquals( repo.getUserName(), service.getRemoteRepository( "id-new" ).getUserName() );
137 assertEquals( repo.getPassword(), service.getRemoteRepository( "id-new" ).getPassword() );
138 assertEquals( repo.getTimeout(), service.getRemoteRepository( "id-new" ).getTimeout() );
139 assertEquals( repo.getDescription(), service.getRemoteRepository( "id-new" ).getDescription() );
141 service.deleteRemoteRepository( "id-new" );
143 assertNull( service.getRemoteRepository( "id-new" ) );
145 assertEquals( initialSize, service.getRemoteRepositories().size() );
149 RemoteRepository getRemoteRepository()
151 return new RemoteRepository( "id-new", "new one", "http://foo.com", "default", "foo", "foopassword", 120,