1 package org.apache.archiva.web.xmlrpc.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 java.util.ArrayList;
23 import java.util.List;
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;
42 public class AdministrationServiceImplTest
43 extends PlexusInSpringTestCase
45 private MockControl archivaConfigControl;
47 private ArchivaConfiguration archivaConfig;
49 private MockControl configControl;
51 private Configuration config;
53 private AdministrationService service;
55 protected void setUp()
60 archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class );
61 archivaConfig = ( ArchivaConfiguration ) archivaConfigControl.getMock();
63 configControl = MockClassControl.createControl( Configuration.class );
64 config = ( Configuration ) configControl.getMock();
66 service = new AdministrationServiceImpl();
69 public void testConfigureValidDatabaseConsumer()
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" );
79 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
80 configControl.expectAndReturn( config.getDatabaseScanning(), dbScanning );
82 config.setDatabaseScanning( dbScanning );
83 configControl.setMatcher( MockControl.ALWAYS_MATCHER );
84 configControl.setVoidCallable();
86 archivaConfig.save( config );
87 archivaConfigControl.setVoidCallable();
89 archivaConfigControl.replay();
90 configControl.replay();
92 boolean success = service.configureDatabaseConsumer( "new-cleanup-consumer", true );
94 archivaConfigControl.verify();
95 configControl.verify();
97 assertTrue( success );
100 archivaConfigControl.reset();
101 configControl.reset();
103 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
104 configControl.expectAndReturn( config.getDatabaseScanning(), dbScanning );
106 config.setDatabaseScanning( dbScanning );
107 configControl.setMatcher( MockControl.ALWAYS_MATCHER );
108 configControl.setVoidCallable();
110 archivaConfig.save( config );
111 archivaConfigControl.setVoidCallable();
113 archivaConfigControl.replay();
114 configControl.replay();
116 success = service.configureDatabaseConsumer( "new-cleanup-consumer", false );
118 archivaConfigControl.verify();
119 configControl.verify();
121 assertTrue( success );*/
124 public void testConfigureInvalidDatabaseConsumer()
130 public void testConfigureValidRepositoryConsumer()
133 // test enable & disable
136 public void testConfigureInvalidRepositoryConsumer()
142 public void testDeleteArtifactArtifactExists()
148 public void testDeleteArtifactArtifactDoesNotExist()
154 public void testDeleteArtifacRepositoryDoesNotExist()
160 public void testExecuteRepoScannerRepoExists()
166 public void testExecuteRepoScannerRepoDoesNotExist()
172 public void testExecuteDbScanner()
178 public void testGetAllDbConsumers()
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" );
187 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
188 configControl.expectAndReturn( config.getDatabaseScanning(), dbScanning );
190 archivaConfigControl.replay();
191 configControl.replay();
193 List<String> dbConsumers = service.getAllDatabaseConsumers();
195 archivaConfigControl.verify();
196 configControl.verify();
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" ) );*/
206 public void testGetAllRepoConsumers()
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" );
216 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
217 configControl.expectAndReturn( config.getRepositoryScanning(), repoScanning );
219 archivaConfigControl.replay();
220 configControl.replay();
222 List<String> repoConsumers = service.getAllDatabaseConsumers();
224 archivaConfigControl.verify();
225 configControl.verify();
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" ) );*/
236 public void testGetAllManagedRepositories()
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 ) );
243 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
244 configControl.expectAndReturn( config.getManagedRepositories(), managedRepos );
246 archivaConfigControl.replay();
247 configControl.replay();
249 List<ManagedRepository> repos = service.getAllManagedRepositories();
251 archivaConfigControl.verify();
252 configControl.verify();
254 assertNotNull( repos );
255 assertEquals( 2, repos.size() );
257 assertManagedRepo( ( ManagedRepository ) repos.get( 0 ), managedRepos.get( 0 ) );
258 assertManagedRepo( ( ManagedRepository ) repos.get( 1 ), managedRepos.get( 1 ) );*/
261 public void testGetAllRemoteRepositories()
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") );
268 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
269 configControl.expectAndReturn( config.getRemoteRepositories(), remoteRepos );
271 archivaConfigControl.replay();
272 configControl.replay();
274 List<RemoteRepository> repos = service.getAllRemoteRepositories();
276 archivaConfigControl.verify();
277 configControl.verify();
279 assertNotNull( repos );
280 assertEquals( 2, repos.size() );
282 assertRemoteRepo( (RemoteRepository) repos.get( 0 ), remoteRepos.get( 0 ) );
283 assertRemoteRepo( (RemoteRepository) repos.get( 1 ), remoteRepos.get( 1 ) ); */
286 private void assertRemoteRepo( RemoteRepository remoteRepo, RemoteRepositoryConfiguration expectedRepoConfig )
288 assertEquals( expectedRepoConfig.getId(), remoteRepo.getId() );
289 assertEquals( expectedRepoConfig.getLayout(), remoteRepo.getLayout() );
290 assertEquals( expectedRepoConfig.getName(), remoteRepo.getName() );
291 assertEquals( expectedRepoConfig.getUrl(), remoteRepo.getUrl() );
294 private RemoteRepositoryConfiguration createRemoteRepository(String id, String name, String layout, String url)
296 RemoteRepositoryConfiguration remoteConfig = new RemoteRepositoryConfiguration();
297 remoteConfig.setId( id );
298 remoteConfig.setName( name );
299 remoteConfig.setLayout( layout );
300 remoteConfig.setUrl( url );
305 private void assertManagedRepo( ManagedRepository managedRepo, ManagedRepositoryConfiguration expectedRepoConfig )
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() );
315 private ManagedRepositoryConfiguration createManagedRepo( String id, String layout, String name,
316 boolean hasReleases, boolean hasSnapshots )
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 );