]> source.dussan.org Git - archiva.git/blob
3d284e452697ded0e6f9b9e67debc3b7d77948ec
[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
30 /**
31  * @author Olivier Lamy
32  */
33 public class RemoteRepositoriesServiceTest
34     extends AbstractArchivaRestTest
35 {
36
37
38     @Test( expected = ForbiddenException.class )
39     public void listRemoteRepositoriesKarmaFailed()
40         throws Exception
41     {
42         RemoteRepositoriesService service = getRemoteRepositoriesService();
43         try
44         {
45             assertFalse( service.getRemoteRepositories().isEmpty() );
46         }
47         catch ( ForbiddenException e )
48         {
49             assertEquals( 403, e.getResponse().getStatus() );
50             throw e;
51         }
52     }
53
54     @Test
55     public void listRemoteRepositoriesKarma()
56         throws Exception
57     {
58         RemoteRepositoriesService service = getRemoteRepositoriesService();
59
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 );
65
66     }
67
68     @Test
69     public void addAndDeleteRemoteRepository()
70         throws Exception
71     {
72         RemoteRepositoriesService service = getRemoteRepositoriesService();
73
74         WebClient.client( service ).header( "Authorization", authorizationHeader );
75
76         int initialSize = service.getRemoteRepositories().size();
77
78         service.addRemoteRepository( getRemoteRepository() );
79
80         assertNotNull( service.getRemoteRepository( "id-new" ) );
81
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() );
90
91         assertEquals( initialSize + 1, service.getRemoteRepositories().size() );
92
93         service.deleteRemoteRepository( "id-new" );
94
95         assertNull( service.getRemoteRepository( "id-new" ) );
96
97         assertEquals( initialSize, service.getRemoteRepositories().size() );
98
99     }
100
101     @Test
102     public void addAndUpdateAndDeleteRemoteRepository()
103         throws Exception
104     {
105         RemoteRepositoriesService service = getRemoteRepositoriesService();
106
107         WebClient.client( service ).header( "Authorization", authorizationHeader );
108
109         int initialSize = service.getRemoteRepositories().size();
110
111         service.addRemoteRepository( getRemoteRepository() );
112
113         assertNotNull( service.getRemoteRepository( "id-new" ) );
114
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() );
121
122         assertEquals( initialSize + 1, service.getRemoteRepositories().size() );
123
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" );
130
131         service.updateRemoteRepository( repo );
132
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() );
140
141         service.deleteRemoteRepository( "id-new" );
142
143         assertNull( service.getRemoteRepository( "id-new" ) );
144
145         assertEquals( initialSize, service.getRemoteRepositories().size() );
146
147     }
148
149     @Test
150     public void checkRemoteConnectivity()
151             throws Exception {
152         RemoteRepositoriesService service = getRemoteRepositoriesService();
153
154         WebClient.client(service).header("Authorization", authorizationHeader);
155
156         int initialSize = service.getRemoteRepositories().size();
157
158         service.addRemoteRepository(getRemoteRepository());
159
160         assertTrue(service.checkRemoteConnectivity("id-new"));
161
162     }
163
164     RemoteRepository getRemoteRepository()
165     {
166         return new RemoteRepository( "id-new", "new one", "http://foo.com", "default", "foo", "foopassword", 120,
167                                      "cool repo" );
168     }
169
170 }