1 package org.apache.archiva.web.action.admin.repositories;
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 com.opensymphony.xwork2.Action;
23 import org.apache.archiva.admin.model.RepositoryAdminException;
24 import org.apache.archiva.admin.model.beans.ManagedRepository;
25 import org.apache.archiva.admin.repository.DefaultRepositoryCommonValidator;
26 import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
27 import org.apache.archiva.audit.AuditListener;
28 import org.apache.archiva.configuration.ArchivaConfiguration;
29 import org.apache.archiva.configuration.Configuration;
30 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
31 import org.apache.archiva.metadata.repository.MetadataRepository;
32 import org.apache.archiva.metadata.repository.RepositorySession;
33 import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
34 import org.apache.archiva.redback.integration.interceptor.SecureActionBundle;
35 import org.apache.archiva.redback.integration.interceptor.SecureActionException;
36 import org.apache.archiva.redback.role.RoleManager;
37 import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler;
38 import org.apache.archiva.scheduler.repository.RepositoryTask;
39 import org.apache.archiva.security.common.ArchivaRoleConstants;
40 import org.apache.archiva.web.validator.utils.ValidatorUtil;
41 import org.apache.archiva.webtest.memory.TestRepositorySessionFactory;
42 import org.apache.commons.io.FileUtils;
43 import org.easymock.MockControl;
44 import org.easymock.classextension.MockClassControl;
47 import java.io.IOException;
48 import java.util.ArrayList;
49 import java.util.HashMap;
50 import java.util.List;
53 import static org.mockito.Mockito.mock;
54 import static org.mockito.Mockito.when;
56 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
57 import org.junit.Before;
58 import org.junit.Test;
59 import org.junit.runner.RunWith;
62 * EditManagedRepositoryActionTest
66 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
67 public class EditManagedRepositoryActionTest
68 extends AbstractManagedRepositoryActionTest
70 private EditManagedRepositoryAction action;
72 private RoleManager roleManager;
74 private MockControl roleManagerControl;
76 private MockControl archivaConfigurationControl;
78 private ArchivaConfiguration archivaConfiguration;
80 private org.apache.archiva.redback.components.registry.Registry registry;
82 private MockControl registryControl;
84 private MetadataRepository metadataRepository;
86 private MockControl repositoryTaskSchedulerControl;
88 private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
97 action = new EditManagedRepositoryAction();
99 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
100 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
102 roleManagerControl = MockControl.createControl( RoleManager.class );
103 roleManager = (RoleManager) roleManagerControl.getMock();
105 registryControl = MockControl.createControl( org.apache.archiva.redback.components.registry.Registry.class );
106 registry = (org.apache.archiva.redback.components.registry.Registry) registryControl.getMock();
108 repositoryTaskSchedulerControl = MockClassControl.createControl( RepositoryArchivaTaskScheduler.class );
109 repositoryTaskScheduler = (RepositoryArchivaTaskScheduler) repositoryTaskSchedulerControl.getMock();
111 location = new File( System.getProperty( "basedir", "target/test/location" ) );
113 metadataRepository = mock( MetadataRepository.class );
114 RepositorySession repositorySession = mock( RepositorySession.class );
115 when( repositorySession.getRepository() ).thenReturn( metadataRepository );
116 TestRepositorySessionFactory factory = applicationContext.getBean( TestRepositorySessionFactory.class );
117 factory.setRepositorySession( repositorySession );
119 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setArchivaConfiguration( archivaConfiguration );
120 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRoleManager( roleManager );
121 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositoryTaskScheduler(
122 repositoryTaskScheduler );
123 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositorySessionFactory( factory );
125 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRegistry( registry );
127 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setAuditListeners(
128 new ArrayList<AuditListener>( 0 ) );
130 DefaultRepositoryCommonValidator defaultRepositoryCommonValidator = new DefaultRepositoryCommonValidator();
131 defaultRepositoryCommonValidator.setArchivaConfiguration( archivaConfiguration );
132 defaultRepositoryCommonValidator.setRegistry( registry );
134 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositoryCommonValidator(
135 defaultRepositoryCommonValidator );
137 action.setRepositoryCommonValidator( defaultRepositoryCommonValidator );
139 action.setManagedRepositoryAdmin( getManagedRepositoryAdmin() );
144 public void testSecureActionBundle()
145 throws SecureActionException, RepositoryAdminException
147 archivaConfiguration.getConfiguration();
148 archivaConfigurationControl.setReturnValue( new Configuration() );
149 archivaConfigurationControl.replay();
152 SecureActionBundle bundle = action.getSecureActionBundle();
153 assertTrue( bundle.requiresAuthentication() );
154 assertEquals( 1, bundle.getAuthorizationTuples().size() );
158 public void testEditRepositoryInitialPage()
161 Configuration configuration = createConfigurationForEditing( createRepository() );
163 archivaConfiguration.getConfiguration();
164 archivaConfigurationControl.setReturnValue( configuration );
165 Configuration stageRepoConfiguration = new Configuration();
166 stageRepoConfiguration.addManagedRepository( createStagingRepository() );
167 archivaConfigurationControl.setReturnValue( stageRepoConfiguration );
169 archivaConfigurationControl.replay();
171 action.setRepoid( REPO_ID );
174 assertEquals( REPO_ID, action.getRepoid() );
175 ManagedRepository repository = action.getRepository();
176 assertNotNull( repository );
178 ManagedRepository newRepository = createRepository();
179 assertRepositoryEquals( repository, newRepository );
180 assertEquals( repository.getLocation(), newRepository.getLocation() );
182 String status = action.input();
183 assertEquals( Action.INPUT, status );
184 repository = action.getRepository();
185 assertRepositoryEquals( repository, createRepository() );
189 public void testEditRepository()
192 String stageRepoId = REPO_ID + "-stage";
194 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
195 roleManagerControl.setReturnValue( false );
196 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
197 roleManagerControl.setVoidCallable();
199 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
200 roleManagerControl.setReturnValue( false );
201 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
202 roleManagerControl.setVoidCallable();
204 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, stageRepoId );
205 roleManagerControl.setReturnValue( false );
206 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, stageRepoId );
207 roleManagerControl.setVoidCallable();
209 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, stageRepoId );
210 roleManagerControl.setReturnValue( false );
211 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, stageRepoId );
212 roleManagerControl.setVoidCallable();
214 roleManagerControl.replay();
216 registry.getString( "appserver.base", "${appserver.base}" );
217 registryControl.setReturnValue( "target/test", 1, 3 );
218 registry.getString( "appserver.home", "${appserver.home}" );
219 registryControl.setReturnValue( "target/test", 1, 3 );
221 registryControl.replay();
223 RepositoryTask task = new RepositoryTask();
224 task.setRepositoryId( REPO_ID );
225 repositoryTaskScheduler.isProcessingRepositoryTask( REPO_ID );
226 repositoryTaskSchedulerControl.setReturnValue( false );
227 repositoryTaskScheduler.queueTask( task );
228 repositoryTaskSchedulerControl.setVoidCallable();
230 RepositoryTask stageTask = new RepositoryTask();
231 stageTask.setRepositoryId( stageRepoId );
232 repositoryTaskScheduler.isProcessingRepositoryTask( stageRepoId );
233 repositoryTaskSchedulerControl.setReturnValue( false );
234 repositoryTaskScheduler.queueTask( stageTask );
235 repositoryTaskSchedulerControl.setVoidCallable();
237 repositoryTaskSchedulerControl.replay();
239 Configuration configuration = createConfigurationForEditing( createRepository() );
240 archivaConfiguration.getConfiguration();
241 archivaConfigurationControl.setReturnValue( configuration );
242 archivaConfigurationControl.setReturnValue( configuration );
243 archivaConfigurationControl.setReturnValue( configuration );
245 archivaConfigurationControl.setReturnValue( configuration );
246 archivaConfigurationControl.setReturnValue( configuration );
248 Configuration stageRepoConfiguration = new Configuration();
249 stageRepoConfiguration.addManagedRepository( createStagingRepository() );
250 archivaConfigurationControl.setReturnValue( stageRepoConfiguration );
251 archivaConfigurationControl.setReturnValue( configuration );
252 archivaConfigurationControl.setReturnValue( configuration );
254 archivaConfiguration.save( configuration );
255 archivaConfiguration.save( configuration );
257 archivaConfiguration.save( configuration );
259 archivaConfigurationControl.replay();
261 action.setRepoid( REPO_ID );
263 assertEquals( REPO_ID, action.getRepoid() );
264 ManagedRepository repository = action.getRepository();
265 populateRepository( repository );
266 repository.setName( "new repo name" );
268 MockControl repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class );
269 RepositoryStatisticsManager repositoryStatisticsManager =
270 (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock();
271 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositoryStatisticsManager(
272 repositoryStatisticsManager );
273 repositoryStatisticsManager.deleteStatistics( metadataRepository , REPO_ID );
274 repositoryStatisticsManagerControl.setVoidCallable();
275 repositoryStatisticsManagerControl.replay();
277 new File( "target/test/" + REPO_ID + "-stage" ).mkdirs();
279 repository.setLocation( System.getProperty( "basedir" ) + "/target/test/" + REPO_ID );
281 action.setRepository( repository );
282 action.setStageNeeded( true );
283 String status = action.commit();
284 assertEquals( Action.SUCCESS, status );
286 ManagedRepository newRepository = createRepository();
287 newRepository.setName( "new repo name" );
288 assertRepositoryEquals( repository, newRepository );
289 //assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() );
290 //assertEquals( location.getCanonicalPath(), new File( repository.getLocation() ).getCanonicalPath() );
292 roleManagerControl.verify();
293 //archivaConfigurationControl.verify();
294 repositoryStatisticsManagerControl.verify();
295 registryControl.verify();
299 public void testEditRepositoryLocationChanged()
302 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
303 roleManagerControl.setReturnValue( false );
304 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
305 roleManagerControl.setVoidCallable();
307 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
308 roleManagerControl.setReturnValue( false );
309 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
310 roleManagerControl.setVoidCallable();
312 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID + "-stage" );
313 roleManagerControl.setReturnValue( false );
314 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID + "-stage" );
315 roleManagerControl.setVoidCallable();
317 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID + "-stage" );
318 roleManagerControl.setReturnValue( false );
319 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID + "-stage" );
320 roleManagerControl.setVoidCallable();
322 roleManagerControl.replay();
324 registry.getString( "appserver.base" );
325 registryControl.setReturnValue( "target/test", 1, 3 );
327 registry.getString( "appserver.base", "${appserver.base}" );
328 registryControl.setReturnValue( "target/test", 1, 3 );
329 registry.getString( "appserver.home", "${appserver.home}" );
330 registryControl.setReturnValue( "target/test", 1, 3 );
332 registryControl.replay();
334 RepositoryTask task = new RepositoryTask();
335 task.setRepositoryId( REPO_ID );
336 repositoryTaskScheduler.isProcessingRepositoryTask( REPO_ID );
337 repositoryTaskSchedulerControl.setReturnValue( false );
338 repositoryTaskScheduler.queueTask( task );
339 repositoryTaskSchedulerControl.setVoidCallable();
341 repositoryTaskSchedulerControl.replay();
343 Configuration configuration = createConfigurationForEditing( createRepository() );
344 archivaConfiguration.getConfiguration();
346 archivaConfigurationControl.setReturnValue( configuration );
347 archivaConfigurationControl.setReturnValue( configuration );
348 archivaConfigurationControl.setReturnValue( configuration );
349 archivaConfigurationControl.setReturnValue( configuration );
351 archivaConfigurationControl.setReturnValue( configuration );
353 archivaConfigurationControl.setReturnValue( buildEasyConfiguration() );
355 Configuration stageRepoConfiguration = buildEasyConfiguration();
356 stageRepoConfiguration.addManagedRepository( createStagingRepository() );
357 archivaConfigurationControl.setReturnValue( stageRepoConfiguration );
359 archivaConfigurationControl.setReturnValue( configuration );
360 archivaConfigurationControl.setReturnValue( configuration );
362 archivaConfiguration.save( configuration );
363 configuration.addManagedRepository( stageRepoConfiguration.getManagedRepositories().get( 0 ) );
364 archivaConfiguration.save( configuration );
365 archivaConfiguration.save( configuration );
367 archivaConfigurationControl.replay();
369 MockControl repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class );
370 RepositoryStatisticsManager repositoryStatisticsManager =
371 (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock();
372 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositoryStatisticsManager(
373 repositoryStatisticsManager );
374 repositoryStatisticsManager.deleteStatistics( metadataRepository, REPO_ID );
375 repositoryStatisticsManagerControl.replay();
377 new File( "target/test/location/" + REPO_ID + "-stage" ).mkdirs();
379 action.setStageNeeded( true );
380 action.setRepoid( REPO_ID );
382 assertEquals( REPO_ID, action.getRepoid() );
384 ManagedRepository repository = new ManagedRepository();
385 populateRepository( repository );
386 File testFile = new File( "target/test/location/new" );
387 FileUtils.deleteDirectory( testFile );
388 repository.setLocation( "${appserver.base}/location/new" );
389 action.setRepository( repository );
390 String status = action.commit();
391 assertEquals( Action.SUCCESS, status );
392 //assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() );
393 //assertEquals( testFile.getCanonicalPath(), new File( repository.getLocation() ).getCanonicalPath() );
395 roleManagerControl.verify();
396 //archivaConfigurationControl.verify();
397 repositoryStatisticsManagerControl.verify();
398 registryControl.verify();
402 public void testStruts2ValidationFrameworkWithNullInputs()
406 // 0 is the default value for primitive int; null for objects
407 ManagedRepository managedRepositoryConfiguration = createManagedRepository( null, null, null, null, 1, 1 );
408 action.setRepository( managedRepositoryConfiguration );
411 actionValidatorManager.validate( action, EMPTY_STRING );
414 assertTrue( action.hasFieldErrors() );
416 Map<String, List<String>> fieldErrors = action.getFieldErrors();
418 // make an expected field error object
419 Map<String, List<String>> expectedFieldErrors = new HashMap<String, List<String>>();
422 List<String> expectedErrorMessages = new ArrayList<String>();
423 expectedErrorMessages.add( "You must enter a repository identifier." );
424 expectedFieldErrors.put( "repository.id", expectedErrorMessages );
426 expectedErrorMessages = new ArrayList<String>();
427 expectedErrorMessages.add( "You must enter a directory." );
428 expectedFieldErrors.put( "repository.location", expectedErrorMessages );
430 expectedErrorMessages = new ArrayList<String>();
431 expectedErrorMessages.add( "You must enter a repository name." );
432 expectedFieldErrors.put( "repository.name", expectedErrorMessages );
434 ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors );
438 public void testStruts2ValidationFrameworkWithBlankInputs()
442 // 0 is the default value for primitive int
443 ManagedRepository managedRepositoryConfiguration =
444 createManagedRepository( EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, 1, 1 );
445 action.setRepository( managedRepositoryConfiguration );
448 actionValidatorManager.validate( action, EMPTY_STRING );
451 assertTrue( action.hasFieldErrors() );
453 Map<String, List<String>> fieldErrors = action.getFieldErrors();
455 // make an expected field error object
456 Map<String, List<String>> expectedFieldErrors = new HashMap<String, List<String>>();
459 List<String> expectedErrorMessages = new ArrayList<String>();
460 expectedErrorMessages.add( "You must enter a repository identifier." );
461 expectedFieldErrors.put( "repository.id", expectedErrorMessages );
463 expectedErrorMessages = new ArrayList<String>();
464 expectedErrorMessages.add( "You must enter a directory." );
465 expectedFieldErrors.put( "repository.location", expectedErrorMessages );
467 expectedErrorMessages = new ArrayList<String>();
468 expectedErrorMessages.add( "You must enter a repository name." );
469 expectedFieldErrors.put( "repository.name", expectedErrorMessages );
471 ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors );
475 public void testStruts2ValidationFrameworkWithInvalidInputs()
479 ManagedRepository managedRepositoryConfiguration =
480 createManagedRepository( REPOSITORY_ID_INVALID_INPUT, REPOSITORY_NAME_INVALID_INPUT,
481 REPOSITORY_LOCATION_INVALID_INPUT, REPOSITORY_INDEX_DIR_INVALID_INPUT,
482 REPOSITORY_DAYS_OLDER_INVALID_INPUT, REPOSITORY_RETENTION_COUNT_INVALID_INPUT );
483 action.setRepository( managedRepositoryConfiguration );
486 actionValidatorManager.validate( action, EMPTY_STRING );
489 assertTrue( action.hasFieldErrors() );
491 Map<String, List<String>> fieldErrors = action.getFieldErrors();
493 // make an expected field error object
494 Map<String, List<String>> expectedFieldErrors = new HashMap<String, List<String>>();
497 List<String> expectedErrorMessages = new ArrayList<String>();
498 expectedErrorMessages.add(
499 "Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)." );
500 expectedFieldErrors.put( "repository.id", expectedErrorMessages );
502 expectedErrorMessages = new ArrayList<String>();
503 expectedErrorMessages.add(
504 "Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
505 expectedFieldErrors.put( "repository.location", expectedErrorMessages );
507 expectedErrorMessages = new ArrayList<String>();
508 expectedErrorMessages.add(
509 "Repository Name must only contain alphanumeric characters, white-spaces(' '), forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-)." );
510 expectedFieldErrors.put( "repository.name", expectedErrorMessages );
512 expectedErrorMessages = new ArrayList<String>();
513 expectedErrorMessages.add(
514 "Index directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
515 expectedFieldErrors.put( "repository.indexDirectory", expectedErrorMessages );
517 expectedErrorMessages = new ArrayList<String>();
518 expectedErrorMessages.add( "Repository Purge By Retention Count needs to be between 1 and 100." );
519 expectedFieldErrors.put( "repository.retentionCount", expectedErrorMessages );
521 expectedErrorMessages = new ArrayList<String>();
522 expectedErrorMessages.add( "Repository Purge By Days Older Than needs to be larger than 0." );
523 expectedFieldErrors.put( "repository.daysOlder", expectedErrorMessages );
525 ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors );
529 public void testStruts2ValidationFrameworkWithValidInputs()
533 ManagedRepository managedRepositoryConfiguration =
534 createManagedRepository( REPOSITORY_ID_VALID_INPUT, REPOSITORY_NAME_VALID_INPUT,
535 REPOSITORY_LOCATION_VALID_INPUT, REPOSITORY_INDEX_DIR_VALID_INPUT,
536 REPOSITORY_DAYS_OLDER_VALID_INPUT, REPOSITORY_RETENTION_COUNT_VALID_INPUT );
537 action.setRepository( managedRepositoryConfiguration );
540 actionValidatorManager.validate( action, EMPTY_STRING );
543 assertFalse( action.hasFieldErrors() );
546 private void assertRepositoryEquals( ManagedRepository expectedRepository, ManagedRepository actualRepository )
548 assertEquals( expectedRepository.getDaysOlder(), actualRepository.getDaysOlder() );
549 assertEquals( expectedRepository.getId(), actualRepository.getId() );
550 assertEquals( expectedRepository.getIndexDirectory(), actualRepository.getIndexDirectory() );
551 assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() );
552 assertEquals( expectedRepository.getName(), actualRepository.getName() );
553 assertEquals( expectedRepository.getCronExpression(), actualRepository.getCronExpression() );
554 assertEquals( expectedRepository.getRetentionCount(), actualRepository.getRetentionCount() );
555 assertEquals( expectedRepository.isDeleteReleasedSnapshots(), actualRepository.isDeleteReleasedSnapshots() );
556 assertEquals( expectedRepository.isScanned(), actualRepository.isScanned() );
557 assertEquals( expectedRepository.isReleases(), actualRepository.isReleases() );
558 assertEquals( expectedRepository.isSnapshots(), actualRepository.isSnapshots() );
561 private Configuration createConfigurationForEditing( ManagedRepository repositoryConfiguration )
564 Configuration configuration = buildEasyConfiguration();
566 ManagedRepositoryConfiguration managedRepositoryConfiguration = new ManagedRepositoryConfiguration();
568 managedRepositoryConfiguration.setDaysOlder( repositoryConfiguration.getDaysOlder() );
569 managedRepositoryConfiguration.setIndexDir( repositoryConfiguration.getIndexDirectory() );
570 managedRepositoryConfiguration.setRetentionCount( repositoryConfiguration.getRetentionCount() );
571 managedRepositoryConfiguration.setBlockRedeployments( repositoryConfiguration.isBlockRedeployments() );
572 managedRepositoryConfiguration.setDeleteReleasedSnapshots(
573 repositoryConfiguration.isDeleteReleasedSnapshots() );
574 managedRepositoryConfiguration.setLocation( repositoryConfiguration.getLocation() );
575 managedRepositoryConfiguration.setRefreshCronExpression( repositoryConfiguration.getCronExpression() );
576 managedRepositoryConfiguration.setReleases( repositoryConfiguration.isReleases() );
577 managedRepositoryConfiguration.setScanned( repositoryConfiguration.isScanned() );
578 managedRepositoryConfiguration.setId( repositoryConfiguration.getId() );
579 managedRepositoryConfiguration.setName( repositoryConfiguration.getName() );
580 managedRepositoryConfiguration.setLayout( repositoryConfiguration.getLayout() );
582 configuration.addManagedRepository( managedRepositoryConfiguration );
583 return configuration;
586 // easy configuration for hashCode/equals
587 private Configuration buildEasyConfiguration()
589 return new Configuration()
592 public int hashCode()
594 return getManagedRepositories().size();
598 public boolean equals( Object o )
605 private ManagedRepository createRepository()
608 ManagedRepository r = new ManagedRepository();
609 r.setLocation( System.getProperty( "basedir" ) + "/target/repo-" + REPO_ID );
610 r.setIndexDirectory( System.getProperty( "basedir" ) + "/target/repo-" + REPO_ID + "-index" );
612 populateRepository( r );
616 private ManagedRepositoryConfiguration createStagingRepository()
619 ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration();
620 r.setId( REPO_ID + "-stage" );
621 r.setLocation( System.getProperty( "basedir" ) + "/target/" + REPO_ID + "-stage" );
622 populateStagingRepository( r );
626 private void populateStagingRepository( ManagedRepositoryConfiguration repository )
629 repository.setId( REPO_ID + "-stage" );
630 repository.setName( "repo name" );
631 repository.setLocation( "${appserver.base}/location" );
632 repository.setLayout( "default" );
633 repository.setRefreshCronExpression( "* 0/5 * * * ?" );
634 repository.setDaysOlder( 31 );
635 repository.setRetentionCount( 20 );
636 repository.setReleases( true );
637 repository.setSnapshots( true );
638 repository.setScanned( false );
639 repository.setDeleteReleasedSnapshots( true );