]> source.dussan.org Git - archiva.git/blob
57e3a1af744a463624c140f3abf2543f8442609b
[archiva.git] /
1 package org.apache.archiva.rest.services;
2
3 /*
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
11  *
12  *   http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  * under the License.
20  */
21
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;
26
27 import javax.ws.rs.ForbiddenException;
28 import java.util.List;
29 import java.util.Locale;
30
31 /**
32  * @author Olivier Lamy
33  */
34 public class RemoteRepositoriesServiceTest
35     extends AbstractArchivaRestTest
36 {
37
38
39     @Test( expected = ForbiddenException.class )
40     public void listRemoteRepositoriesKarmaFailed()
41         throws Exception
42     {
43         RemoteRepositoriesService service = getRemoteRepositoriesService();
44         try
45         {
46             assertFalse( service.getRemoteRepositories().isEmpty() );
47         }
48         catch ( ForbiddenException e )
49         {
50             assertEquals( 403, e.getResponse().getStatus() );
51             throw e;
52         }
53     }
54
55     @Test
56     public void listRemoteRepositoriesKarma()
57         throws Exception
58     {
59         RemoteRepositoriesService service = getRemoteRepositoriesService();
60
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 );
66
67     }
68
69     @Test
70     public void addAndDeleteRemoteRepository()
71         throws Exception
72     {
73         RemoteRepositoriesService service = getRemoteRepositoriesService();
74
75         WebClient.client( service ).header( "Authorization", authorizationHeader );
76
77         int initialSize = service.getRemoteRepositories().size();
78
79         service.addRemoteRepository( getRemoteRepository() );
80
81         assertNotNull( service.getRemoteRepository( "id-new" ) );
82
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() );
91
92         assertEquals( initialSize + 1, service.getRemoteRepositories().size() );
93
94         service.deleteRemoteRepository( "id-new" );
95
96         assertNull( service.getRemoteRepository( "id-new" ) );
97
98         assertEquals( initialSize, service.getRemoteRepositories().size() );
99
100     }
101
102     @Test
103     public void addAndUpdateAndDeleteRemoteRepository()
104         throws Exception
105     {
106         RemoteRepositoriesService service = getRemoteRepositoriesService();
107
108         WebClient.client( service ).header( "Authorization", authorizationHeader );
109
110         int initialSize = service.getRemoteRepositories().size();
111
112         service.addRemoteRepository( getRemoteRepository() );
113
114         assertNotNull( service.getRemoteRepository( "id-new" ) );
115
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() );
122
123         assertEquals( initialSize + 1, service.getRemoteRepositories().size() );
124
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" );
131
132         service.updateRemoteRepository( repo );
133
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() );
141
142         service.deleteRemoteRepository( "id-new" );
143
144         assertNull( service.getRemoteRepository( "id-new" ) );
145
146         assertEquals( initialSize, service.getRemoteRepositories().size() );
147
148     }
149
150     @Test
151     public void checkRemoteConnectivity()
152             throws Exception {
153         RemoteRepositoriesService service = getRemoteRepositoriesService();
154
155         WebClient.client(service).header("Authorization", authorizationHeader);
156
157         int initialSize = service.getRemoteRepositories().size();
158
159         service.addRemoteRepository(getRemoteRepository());
160
161         assertTrue(service.checkRemoteConnectivity("id-new"));
162
163     }
164
165     /*
166      * Check maven repository
167      */
168     @Test
169     public void checkRemoteConnectivity2()
170             throws Exception {
171         RemoteRepositoriesService service = getRemoteRepositoriesService();
172
173         WebClient.client(service).header("Authorization", authorizationHeader);
174
175         int initialSize = service.getRemoteRepositories().size();
176
177         service.addRemoteRepository(getRemoteMavenRepository());
178
179         assertTrue(service.checkRemoteConnectivity("id-maven1"));
180
181     }
182
183
184     /*
185      *  Check oracle repository that allows not browsing (MRM-1933)
186      */
187     @Test
188     public void checkRemoteConnectivity3()
189             throws Exception {
190         RemoteRepositoriesService service = getRemoteRepositoriesService();
191
192         WebClient.client(service).header("Authorization", authorizationHeader);
193         WebClient.client(service).accept("application/json");
194
195         int initialSize = service.getRemoteRepositories().size();
196
197         service.addRemoteRepository(getRemoteOracleRepository());
198
199         assertTrue(service.checkRemoteConnectivity("id-oracle"));
200
201     }
202
203     RemoteRepository getRemoteRepository()
204     {
205         return new RemoteRepository( Locale.getDefault( ), "id-new", "new one", "http://www.apache.org", "default", "foo", "foopassword", 120,
206                                      "cool repo" );
207     }
208
209
210     RemoteRepository getRemoteMavenRepository()
211     {
212         return new RemoteRepository( Locale.getDefault( ),"id-maven1", "Maven1", "http://repo.maven.apache.org/maven2", "default", "foo", "foopassword", 120,
213                 "cool repo3" );
214     }
215
216
217     RemoteRepository getRemoteOracleRepository()
218     {
219         return new RemoteRepository( Locale.getDefault( ),"id-oracle", "Oracle", "http://download.oracle.com/maven", "default", "foo", "foopassword", 120,
220                 "cool repo4" );
221     }
222
223 }