]> source.dussan.org Git - archiva.git/blob
17f15b08e58781072b2499723f6e311c0f4e8571
[archiva.git] /
1 package org.apache.archiva.web.xmlrpc.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 java.util.ArrayList;
23 import java.util.List;
24
25 import org.apache.archiva.web.xmlrpc.api.AdministrationService;
26 import org.apache.archiva.web.xmlrpc.api.beans.ManagedRepository;
27 import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository;
28 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
29 import org.apache.maven.archiva.configuration.Configuration;
30 import org.apache.maven.archiva.configuration.DatabaseScanningConfiguration;
31 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
32 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
33 import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
34 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
35 import org.easymock.MockControl;
36 import org.easymock.classextension.MockClassControl;
37
38 /**
39  * 
40  * @version $Id$
41  */
42 public class AdministrationServiceImplTest
43     extends PlexusInSpringTestCase
44 {    
45     private MockControl archivaConfigControl;
46     
47     private ArchivaConfiguration archivaConfig;
48     
49     private MockControl configControl;
50     
51     private Configuration config;
52     
53     private AdministrationService service;
54     
55     protected void setUp()
56         throws Exception
57     {
58         super.setUp();
59         
60         archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class );
61         archivaConfig = ( ArchivaConfiguration ) archivaConfigControl.getMock();
62         
63         configControl = MockClassControl.createControl( Configuration.class );
64         config = ( Configuration ) configControl.getMock();      
65         
66         service = new AdministrationServiceImpl();
67     }
68     
69     public void testConfigureValidDatabaseConsumer()
70         throws Exception
71     {
72         /*DatabaseScanningConfiguration dbScanning = new DatabaseScanningConfiguration();
73         dbScanning.addCleanupConsumer( "cleanup-index" );
74         dbScanning.addCleanupConsumer( "cleanup-database" );
75         dbScanning.addUnprocessedConsumer( "unprocessed-artifacts" );
76         dbScanning.addUnprocessedConsumer( "unprocessed-poms" );
77         
78      // test enable
79         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
80         configControl.expectAndReturn( config.getDatabaseScanning(), dbScanning );
81         
82         config.setDatabaseScanning( dbScanning );
83         configControl.setMatcher( MockControl.ALWAYS_MATCHER );
84         configControl.setVoidCallable();
85         
86         archivaConfig.save( config );
87         archivaConfigControl.setVoidCallable();
88         
89         archivaConfigControl.replay();
90         configControl.replay();
91         
92         boolean success = service.configureDatabaseConsumer( "new-cleanup-consumer", true ); 
93         
94         archivaConfigControl.verify();
95         configControl.verify();
96         
97         assertTrue( success );
98         
99       // test disable 
100         archivaConfigControl.reset();
101         configControl.reset();
102         
103         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
104         configControl.expectAndReturn( config.getDatabaseScanning(), dbScanning );
105         
106         config.setDatabaseScanning( dbScanning );
107         configControl.setMatcher( MockControl.ALWAYS_MATCHER );
108         configControl.setVoidCallable();
109         
110         archivaConfig.save( config );
111         archivaConfigControl.setVoidCallable();
112         
113         archivaConfigControl.replay();
114         configControl.replay();
115         
116         success = service.configureDatabaseConsumer( "new-cleanup-consumer", false ); 
117         
118         archivaConfigControl.verify();
119         configControl.verify();
120         
121         assertTrue( success );*/
122     }
123     
124     public void testConfigureInvalidDatabaseConsumer()
125         throws Exception
126     {
127         
128     }
129     
130     public void testConfigureValidRepositoryConsumer()
131         throws Exception
132     {
133         // test enable & disable
134     }
135     
136     public void testConfigureInvalidRepositoryConsumer()
137         throws Exception
138     {
139     
140     }
141     
142     public void testDeleteArtifactArtifactExists()
143         throws Exception
144     {
145     
146     }
147     
148     public void testDeleteArtifactArtifactDoesNotExist()
149         throws Exception
150     {
151     
152     }
153     
154     public void testDeleteArtifacRepositoryDoesNotExist()
155         throws Exception
156     {
157     
158     }
159     
160     public void testExecuteRepoScannerRepoExists()
161         throws Exception
162     {
163     
164     }
165     
166     public void testExecuteRepoScannerRepoDoesNotExist()
167         throws Exception
168     {
169     
170     }
171     
172     public void testExecuteDbScanner()
173         throws Exception
174     {
175         
176     }
177     
178     public void testGetAllDbConsumers()
179         throws Exception
180     {
181         /*DatabaseScanningConfiguration dbScanning = new DatabaseScanningConfiguration();
182         dbScanning.addCleanupConsumer( "cleanup-index" );
183         dbScanning.addCleanupConsumer( "cleanup-database" );
184         dbScanning.addUnprocessedConsumer( "unprocessed-artifacts" );
185         dbScanning.addUnprocessedConsumer( "unprocessed-poms" );
186         
187         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
188         configControl.expectAndReturn( config.getDatabaseScanning(), dbScanning );
189         
190         archivaConfigControl.replay();
191         configControl.replay();
192         
193         List<String> dbConsumers = service.getAllDatabaseConsumers(); 
194         
195         archivaConfigControl.verify();
196         configControl.verify();
197         
198         assertNotNull( dbConsumers );
199         assertEquals( 4, dbConsumers.size() );
200         assertTrue( dbConsumers.contains( "cleanup-index" ) );
201         assertTrue( dbConsumers.contains( "cleanup-database" ) );
202         assertTrue( dbConsumers.contains( "unprocessed-artifacts" ) );
203         assertTrue( dbConsumers.contains( "unprocessed-poms" ) );*/
204     }
205     
206     public void testGetAllRepoConsumers()
207         throws Exception
208     {
209         /*RepositoryScanningConfiguration repoScanning = new RepositoryScanningConfiguration();
210         repoScanning.addKnownContentConsumer( "index-artifacts" );
211         repoScanning.addKnownContentConsumer( "index-poms" );
212         repoScanning.addKnownContentConsumer( "fix-checksums" );
213         repoScanning.addInvalidContentConsumer( "check-poms" );
214         repoScanning.addInvalidContentConsumer( "check-metadata" );
215         
216         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
217         configControl.expectAndReturn( config.getRepositoryScanning(), repoScanning );
218         
219         archivaConfigControl.replay();
220         configControl.replay();
221         
222         List<String> repoConsumers = service.getAllDatabaseConsumers(); 
223         
224         archivaConfigControl.verify();
225         configControl.verify();
226         
227         assertNotNull( repoConsumers );
228         assertEquals( 5, repoConsumers.size() );
229         assertTrue( repoConsumers.contains( "index-artifacts" ) );
230         assertTrue( repoConsumers.contains( "index-poms" ) );
231         assertTrue( repoConsumers.contains( "fix-checksums" ) );
232         assertTrue( repoConsumers.contains( "check-poms" ) );
233         assertTrue( repoConsumers.contains( "check-metadata" ) );*/
234     }
235     
236     public void testGetAllManagedRepositories()
237         throws Exception
238     {
239         /*List<ManagedRepositoryConfiguration> managedRepos = new ArrayList<ManagedRepositoryConfiguration>();        
240         managedRepos.add( createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
241         managedRepos.add( createManagedRepo( "snapshots", "default", "Snapshots Repository", false, true ) );
242         
243         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
244         configControl.expectAndReturn( config.getManagedRepositories(), managedRepos );
245         
246         archivaConfigControl.replay();
247         configControl.replay();
248         
249         List<ManagedRepository> repos = service.getAllManagedRepositories(); 
250         
251         archivaConfigControl.verify();
252         configControl.verify();
253         
254         assertNotNull( repos );
255         assertEquals( 2, repos.size() );
256                 
257         assertManagedRepo( ( ManagedRepository ) repos.get( 0 ), managedRepos.get( 0 ) );
258         assertManagedRepo( ( ManagedRepository ) repos.get( 1 ), managedRepos.get( 1 ) );*/
259     }
260
261     public void testGetAllRemoteRepositories()
262         throws Exception
263     {
264         /*List<RemoteRepositoryConfiguration> remoteRepos = new ArrayList<RemoteRepositoryConfiguration>(); 
265         remoteRepos.add( createRemoteRepository( "central", "Central Repository", "default", "http://repo1.maven.org/maven2") );
266         remoteRepos.add( createRemoteRepository( "dummy", "Dummy Remote Repository", "legacy", "http://dummy.com/dummy") );
267         
268         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
269         configControl.expectAndReturn( config.getRemoteRepositories(), remoteRepos );
270         
271         archivaConfigControl.replay();
272         configControl.replay();
273         
274         List<RemoteRepository> repos = service.getAllRemoteRepositories(); 
275         
276         archivaConfigControl.verify();
277         configControl.verify();
278         
279         assertNotNull( repos );
280         assertEquals( 2, repos.size() );
281          
282         assertRemoteRepo( (RemoteRepository) repos.get( 0 ), remoteRepos.get( 0 ) );
283         assertRemoteRepo( (RemoteRepository) repos.get( 1 ), remoteRepos.get( 1 ) );        */
284     }
285
286     private void assertRemoteRepo( RemoteRepository remoteRepo, RemoteRepositoryConfiguration expectedRepoConfig )
287     {
288         assertEquals( expectedRepoConfig.getId(), remoteRepo.getId() );
289         assertEquals( expectedRepoConfig.getLayout(), remoteRepo.getLayout() );
290         assertEquals( expectedRepoConfig.getName(), remoteRepo.getName() );
291         assertEquals( expectedRepoConfig.getUrl(), remoteRepo.getUrl() );       
292     }
293     
294     private RemoteRepositoryConfiguration createRemoteRepository(String id, String name, String layout, String url)
295     {
296         RemoteRepositoryConfiguration remoteConfig = new RemoteRepositoryConfiguration();
297         remoteConfig.setId( id );
298         remoteConfig.setName( name );
299         remoteConfig.setLayout( layout );
300         remoteConfig.setUrl( url );
301         
302         return remoteConfig;
303     }
304     
305     private void assertManagedRepo( ManagedRepository managedRepo, ManagedRepositoryConfiguration expectedRepoConfig )
306     {
307         assertEquals( expectedRepoConfig.getId(), managedRepo.getId() );
308         assertEquals( expectedRepoConfig.getLayout(), managedRepo.getLayout() );
309         assertEquals( expectedRepoConfig.getName(), managedRepo.getName() );
310         assertEquals( "http://localhost:8080/archiva/repository/" + expectedRepoConfig.getId(), managedRepo.getUrl() );
311         assertEquals( expectedRepoConfig.isReleases(), managedRepo.isReleases() );
312         assertEquals( expectedRepoConfig.isSnapshots(), managedRepo.isSnapshots() );
313     }
314
315     private ManagedRepositoryConfiguration createManagedRepo( String id, String layout, String name,
316                                                               boolean hasReleases, boolean hasSnapshots )
317     {
318         ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
319         repoConfig.setId( id );
320         repoConfig.setLayout( layout );
321         repoConfig.setName( name );
322         repoConfig.setReleases( hasReleases );
323         repoConfig.setSnapshots( hasSnapshots );
324         
325         return repoConfig;
326     }
327     
328 }