1 package org.apache.maven.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.repository.RepositoryAdminException;
24 import org.apache.archiva.admin.repository.RepositoryCommonValidator;
25 import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
26 import org.apache.archiva.admin.repository.managed.ManagedRepository;
27 import org.apache.archiva.audit.AuditListener;
28 import org.apache.archiva.metadata.repository.MetadataRepository;
29 import org.apache.archiva.metadata.repository.RepositorySession;
30 import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
31 import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
32 import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler;
33 import org.apache.archiva.scheduler.repository.RepositoryTask;
34 import org.apache.commons.io.FileUtils;
35 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
36 import org.apache.maven.archiva.configuration.Configuration;
37 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
38 import org.apache.archiva.security.ArchivaRoleConstants;
39 import org.apache.archiva.web.validator.utils.ValidatorUtil;
40 import org.codehaus.plexus.redback.role.RoleManager;
41 import org.codehaus.plexus.registry.Registry;
42 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
43 import org.codehaus.redback.integration.interceptor.SecureActionException;
44 import org.easymock.MockControl;
45 import org.easymock.classextension.MockClassControl;
48 import java.io.IOException;
49 import java.util.ArrayList;
50 import java.util.HashMap;
51 import java.util.List;
54 import static org.mockito.Mockito.mock;
55 import static org.mockito.Mockito.when;
58 * EditManagedRepositoryActionTest
62 public class EditManagedRepositoryActionTest
63 extends AbstractManagedRepositoryActionTest
65 private EditManagedRepositoryAction action;
67 private RoleManager roleManager;
69 private MockControl roleManagerControl;
71 private MockControl archivaConfigurationControl;
73 private ArchivaConfiguration archivaConfiguration;
75 private Registry registry;
77 private MockControl registryControl;
79 private MetadataRepository metadataRepository;
81 private MockControl repositoryTaskSchedulerControl;
83 private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
86 protected void setUp()
91 action = new EditManagedRepositoryAction();
93 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
94 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
95 action.setArchivaConfiguration( archivaConfiguration );
97 roleManagerControl = MockControl.createControl( RoleManager.class );
98 roleManager = (RoleManager) roleManagerControl.getMock();
100 registryControl = MockControl.createControl( Registry.class );
101 registry = (Registry) registryControl.getMock();
103 repositoryTaskSchedulerControl = MockClassControl.createControl( RepositoryArchivaTaskScheduler.class );
104 repositoryTaskScheduler = (RepositoryArchivaTaskScheduler) repositoryTaskSchedulerControl.getMock();
106 location = new File( "target/test/location" );
108 metadataRepository = mock( MetadataRepository.class );
109 RepositorySession repositorySession = mock( RepositorySession.class );
110 when( repositorySession.getRepository() ).thenReturn( metadataRepository );
111 TestRepositorySessionFactory factory = applicationContext.getBean( TestRepositorySessionFactory.class );
112 factory.setRepositorySession( repositorySession );
114 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setArchivaConfiguration( archivaConfiguration );
115 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRoleManager( roleManager );
116 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositoryTaskScheduler(
117 repositoryTaskScheduler );
118 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositorySessionFactory( factory );
120 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRegistry( registry );
122 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setAuditListeners(
123 new ArrayList<AuditListener>( 0 ) );
125 RepositoryCommonValidator repositoryCommonValidator = new RepositoryCommonValidator();
126 repositoryCommonValidator.setArchivaConfiguration( archivaConfiguration );
127 repositoryCommonValidator.setRegistry( registry );
129 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositoryCommonValidator(
130 repositoryCommonValidator );
132 action.setRepositoryCommonValidator( repositoryCommonValidator );
134 action.setManagedRepositoryAdmin( getManagedRepositoryAdmin() );
138 public void testSecureActionBundle()
139 throws SecureActionException, RepositoryAdminException
141 archivaConfiguration.getConfiguration();
142 archivaConfigurationControl.setReturnValue( new Configuration() );
143 archivaConfigurationControl.replay();
146 SecureActionBundle bundle = action.getSecureActionBundle();
147 assertTrue( bundle.requiresAuthentication() );
148 assertEquals( 1, bundle.getAuthorizationTuples().size() );
151 public void testEditRepositoryInitialPage()
154 Configuration configuration = createConfigurationForEditing( createRepository() );
156 archivaConfiguration.getConfiguration();
157 archivaConfigurationControl.setReturnValue( configuration );
158 Configuration stageRepoConfiguration = new Configuration();
159 stageRepoConfiguration.addManagedRepository( createStagingRepository() );
160 archivaConfigurationControl.setReturnValue( stageRepoConfiguration );
162 archivaConfigurationControl.replay();
164 action.setRepoid( REPO_ID );
167 assertEquals( REPO_ID, action.getRepoid() );
168 ManagedRepository repository = action.getRepository();
169 assertNotNull( repository );
171 ManagedRepository newRepository = createRepository();
172 assertRepositoryEquals( repository, newRepository );
173 assertEquals( repository.getLocation(), newRepository.getLocation() );
175 String status = action.input();
176 assertEquals( Action.INPUT, status );
177 repository = action.getRepository();
178 assertRepositoryEquals( repository, createRepository() );
181 public void testEditRepository()
184 String stageRepoId = REPO_ID + "-stage";
186 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
187 roleManagerControl.setReturnValue( false );
188 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
189 roleManagerControl.setVoidCallable();
191 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
192 roleManagerControl.setReturnValue( false );
193 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
194 roleManagerControl.setVoidCallable();
196 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, stageRepoId );
197 roleManagerControl.setReturnValue( false );
198 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, stageRepoId );
199 roleManagerControl.setVoidCallable();
201 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, stageRepoId );
202 roleManagerControl.setReturnValue( false );
203 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, stageRepoId );
204 roleManagerControl.setVoidCallable();
206 roleManagerControl.replay();
208 registry.getString( "appserver.base", "${appserver.base}" );
209 registryControl.setReturnValue( "target/test" );
210 registry.getString( "appserver.home", "${appserver.home}" );
211 registryControl.setReturnValue( "target/test" );
213 registry.getString( "appserver.base", "${appserver.base}" );
214 registryControl.setReturnValue( "target/test" );
215 registry.getString( "appserver.home", "${appserver.home}" );
216 registryControl.setReturnValue( "target/test" );
218 registryControl.replay();
220 RepositoryTask task = new RepositoryTask();
221 task.setRepositoryId( REPO_ID );
222 repositoryTaskScheduler.isProcessingRepositoryTask( REPO_ID );
223 repositoryTaskSchedulerControl.setReturnValue( false );
224 repositoryTaskScheduler.queueTask( task );
225 repositoryTaskSchedulerControl.setVoidCallable();
227 RepositoryTask stageTask = new RepositoryTask();
228 stageTask.setRepositoryId( stageRepoId );
229 repositoryTaskScheduler.isProcessingRepositoryTask( stageRepoId );
230 repositoryTaskSchedulerControl.setReturnValue( false );
231 repositoryTaskScheduler.queueTask( stageTask );
232 repositoryTaskSchedulerControl.setVoidCallable();
234 repositoryTaskSchedulerControl.replay();
236 Configuration configuration = createConfigurationForEditing( createRepository() );
237 archivaConfiguration.getConfiguration();
238 archivaConfigurationControl.setReturnValue( configuration );
239 archivaConfigurationControl.setReturnValue( configuration );
240 archivaConfigurationControl.setReturnValue( configuration );
242 archivaConfigurationControl.setReturnValue( configuration );
243 archivaConfigurationControl.setReturnValue( configuration );
245 Configuration stageRepoConfiguration = new Configuration();
246 stageRepoConfiguration.addManagedRepository( createStagingRepository() );
247 archivaConfigurationControl.setReturnValue( stageRepoConfiguration );
248 archivaConfigurationControl.setReturnValue( configuration );
249 archivaConfigurationControl.setReturnValue( configuration );
251 archivaConfiguration.save( configuration );
252 archivaConfiguration.save( configuration );
254 archivaConfiguration.save( configuration );
256 archivaConfigurationControl.replay();
258 action.setRepoid( REPO_ID );
260 assertEquals( REPO_ID, action.getRepoid() );
261 ManagedRepository repository = action.getRepository();
262 populateRepository( repository );
263 repository.setName( "new repo name" );
265 MockControl repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class );
266 RepositoryStatisticsManager repositoryStatisticsManager =
267 (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock();
268 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositoryStatisticsManager(
269 repositoryStatisticsManager );
271 repositoryStatisticsManagerControl.replay();
273 new File( "target/test/" + REPO_ID + "-stage" ).mkdirs();
275 action.setRepository( repository );
276 action.setStageNeeded( true );
277 String status = action.commit();
278 assertEquals( Action.SUCCESS, status );
280 ManagedRepository newRepository = createRepository();
281 newRepository.setName( "new repo name" );
282 assertRepositoryEquals( repository, newRepository );
283 //assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() );
284 //assertEquals( location.getCanonicalPath(), new File( repository.getLocation() ).getCanonicalPath() );
286 roleManagerControl.verify();
287 //archivaConfigurationControl.verify();
288 repositoryStatisticsManagerControl.verify();
289 registryControl.verify();
292 public void testEditRepositoryLocationChanged()
295 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
296 roleManagerControl.setReturnValue( false );
297 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
298 roleManagerControl.setVoidCallable();
300 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
301 roleManagerControl.setReturnValue( false );
302 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
303 roleManagerControl.setVoidCallable();
305 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID + "-stage" );
306 roleManagerControl.setReturnValue( false );
307 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID + "-stage" );
308 roleManagerControl.setVoidCallable();
310 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID + "-stage" );
311 roleManagerControl.setReturnValue( false );
312 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID + "-stage" );
313 roleManagerControl.setVoidCallable();
315 roleManagerControl.replay();
317 registry.getString( "appserver.base", "${appserver.base}" );
318 registryControl.setReturnValue( "target/test" );
319 registry.getString( "appserver.home", "${appserver.home}" );
320 registryControl.setReturnValue( "target/test" );
322 registry.getString( "appserver.base", "${appserver.base}" );
323 registryControl.setReturnValue( "target/test" );
324 registry.getString( "appserver.home", "${appserver.home}" );
325 registryControl.setReturnValue( "target/test" );
327 registryControl.replay();
329 RepositoryTask task = new RepositoryTask();
330 task.setRepositoryId( REPO_ID );
331 repositoryTaskScheduler.isProcessingRepositoryTask( REPO_ID );
332 repositoryTaskSchedulerControl.setReturnValue( false );
333 repositoryTaskScheduler.queueTask( task );
334 repositoryTaskSchedulerControl.setVoidCallable();
336 repositoryTaskSchedulerControl.replay();
338 Configuration configuration = createConfigurationForEditing( createRepository() );
339 archivaConfiguration.getConfiguration();
340 archivaConfigurationControl.setReturnValue( configuration );
341 archivaConfigurationControl.setReturnValue( configuration );
342 archivaConfigurationControl.setReturnValue( configuration );
343 archivaConfigurationControl.setReturnValue( configuration );
345 archivaConfigurationControl.setReturnValue( configuration );
347 archivaConfigurationControl.setReturnValue( buildEasyConfiguration() );
349 Configuration stageRepoConfiguration = buildEasyConfiguration();
350 stageRepoConfiguration.addManagedRepository( createStagingRepository() );
351 archivaConfigurationControl.setReturnValue( stageRepoConfiguration );
353 archivaConfigurationControl.setReturnValue( configuration );
354 archivaConfigurationControl.setReturnValue( configuration );
356 archivaConfiguration.save( configuration );
357 configuration.addManagedRepository( stageRepoConfiguration.getManagedRepositories().get( 0 ) );
358 archivaConfiguration.save( configuration );
359 archivaConfiguration.save( configuration );
361 archivaConfigurationControl.replay();
363 MockControl repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class );
364 RepositoryStatisticsManager repositoryStatisticsManager =
365 (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock();
366 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositoryStatisticsManager(
367 repositoryStatisticsManager );
368 repositoryStatisticsManager.deleteStatistics( metadataRepository, REPO_ID );
369 repositoryStatisticsManagerControl.replay();
371 new File( "target/test/location/" + REPO_ID + "-stage" ).mkdirs();
373 action.setStageNeeded( true );
374 action.setRepoid( REPO_ID );
376 assertEquals( REPO_ID, action.getRepoid() );
378 ManagedRepository repository = new ManagedRepository();
379 populateRepository( repository );
380 File testFile = new File( "target/test/location/new" );
381 FileUtils.deleteDirectory( testFile );
382 repository.setLocation( "${appserver.base}/location/new" );
383 action.setRepository( repository );
384 String status = action.commit();
385 assertEquals( Action.SUCCESS, status );
386 //assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() );
387 //assertEquals( testFile.getCanonicalPath(), new File( repository.getLocation() ).getCanonicalPath() );
389 roleManagerControl.verify();
390 //archivaConfigurationControl.verify();
391 repositoryStatisticsManagerControl.verify();
392 registryControl.verify();
395 public void testStruts2ValidationFrameworkWithNullInputs()
399 // 0 is the default value for primitive int; null for objects
400 ManagedRepository managedRepositoryConfiguration = createManagedRepository( null, null, null, null, 1, 1 );
401 action.setRepository( managedRepositoryConfiguration );
404 actionValidatorManager.validate( action, EMPTY_STRING );
407 assertTrue( action.hasFieldErrors() );
409 Map<String, List<String>> fieldErrors = action.getFieldErrors();
411 // make an expected field error object
412 Map<String, List<String>> expectedFieldErrors = new HashMap<String, List<String>>();
415 List<String> expectedErrorMessages = new ArrayList<String>();
416 expectedErrorMessages.add( "You must enter a repository identifier." );
417 expectedFieldErrors.put( "repository.id", expectedErrorMessages );
419 expectedErrorMessages = new ArrayList<String>();
420 expectedErrorMessages.add( "You must enter a directory." );
421 expectedFieldErrors.put( "repository.location", expectedErrorMessages );
423 expectedErrorMessages = new ArrayList<String>();
424 expectedErrorMessages.add( "You must enter a repository name." );
425 expectedFieldErrors.put( "repository.name", expectedErrorMessages );
427 ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors );
430 public void testStruts2ValidationFrameworkWithBlankInputs()
434 // 0 is the default value for primitive int
435 ManagedRepository managedRepositoryConfiguration =
436 createManagedRepository( EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, 1, 1 );
437 action.setRepository( managedRepositoryConfiguration );
440 actionValidatorManager.validate( action, EMPTY_STRING );
443 assertTrue( action.hasFieldErrors() );
445 Map<String, List<String>> fieldErrors = action.getFieldErrors();
447 // make an expected field error object
448 Map<String, List<String>> expectedFieldErrors = new HashMap<String, List<String>>();
451 List<String> expectedErrorMessages = new ArrayList<String>();
452 expectedErrorMessages.add( "You must enter a repository identifier." );
453 expectedFieldErrors.put( "repository.id", expectedErrorMessages );
455 expectedErrorMessages = new ArrayList<String>();
456 expectedErrorMessages.add( "You must enter a directory." );
457 expectedFieldErrors.put( "repository.location", expectedErrorMessages );
459 expectedErrorMessages = new ArrayList<String>();
460 expectedErrorMessages.add( "You must enter a repository name." );
461 expectedFieldErrors.put( "repository.name", expectedErrorMessages );
463 ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors );
466 public void testStruts2ValidationFrameworkWithInvalidInputs()
470 ManagedRepository managedRepositoryConfiguration =
471 createManagedRepository( REPOSITORY_ID_INVALID_INPUT, REPOSITORY_NAME_INVALID_INPUT,
472 REPOSITORY_LOCATION_INVALID_INPUT, REPOSITORY_INDEX_DIR_INVALID_INPUT,
473 REPOSITORY_DAYS_OLDER_INVALID_INPUT, REPOSITORY_RETENTION_COUNT_INVALID_INPUT );
474 action.setRepository( managedRepositoryConfiguration );
477 actionValidatorManager.validate( action, EMPTY_STRING );
480 assertTrue( action.hasFieldErrors() );
482 Map<String, List<String>> fieldErrors = action.getFieldErrors();
484 // make an expected field error object
485 Map<String, List<String>> expectedFieldErrors = new HashMap<String, List<String>>();
488 List<String> expectedErrorMessages = new ArrayList<String>();
489 expectedErrorMessages.add(
490 "Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)." );
491 expectedFieldErrors.put( "repository.id", expectedErrorMessages );
493 expectedErrorMessages = new ArrayList<String>();
494 expectedErrorMessages.add(
495 "Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
496 expectedFieldErrors.put( "repository.location", expectedErrorMessages );
498 expectedErrorMessages = new ArrayList<String>();
499 expectedErrorMessages.add(
500 "Repository Name must only contain alphanumeric characters, white-spaces(' '), forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-)." );
501 expectedFieldErrors.put( "repository.name", expectedErrorMessages );
503 expectedErrorMessages = new ArrayList<String>();
504 expectedErrorMessages.add(
505 "Index directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
506 expectedFieldErrors.put( "repository.indexDirectory", expectedErrorMessages );
508 expectedErrorMessages = new ArrayList<String>();
509 expectedErrorMessages.add( "Repository Purge By Retention Count needs to be between 1 and 100." );
510 expectedFieldErrors.put( "repository.retentionCount", expectedErrorMessages );
512 expectedErrorMessages = new ArrayList<String>();
513 expectedErrorMessages.add( "Repository Purge By Days Older Than needs to be larger than 0." );
514 expectedFieldErrors.put( "repository.daysOlder", expectedErrorMessages );
516 ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors );
519 public void testStruts2ValidationFrameworkWithValidInputs()
523 ManagedRepository managedRepositoryConfiguration =
524 createManagedRepository( REPOSITORY_ID_VALID_INPUT, REPOSITORY_NAME_VALID_INPUT,
525 REPOSITORY_LOCATION_VALID_INPUT, REPOSITORY_INDEX_DIR_VALID_INPUT,
526 REPOSITORY_DAYS_OLDER_VALID_INPUT, REPOSITORY_RETENTION_COUNT_VALID_INPUT );
527 action.setRepository( managedRepositoryConfiguration );
530 actionValidatorManager.validate( action, EMPTY_STRING );
533 assertFalse( action.hasFieldErrors() );
536 private void assertRepositoryEquals( ManagedRepository expectedRepository, ManagedRepository actualRepository )
538 assertEquals( expectedRepository.getDaysOlder(), actualRepository.getDaysOlder() );
539 assertEquals( expectedRepository.getId(), actualRepository.getId() );
540 assertEquals( expectedRepository.getIndexDirectory(), actualRepository.getIndexDirectory() );
541 assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() );
542 assertEquals( expectedRepository.getName(), actualRepository.getName() );
543 assertEquals( expectedRepository.getCronExpression(), actualRepository.getCronExpression() );
544 assertEquals( expectedRepository.getRetentionCount(), actualRepository.getRetentionCount() );
545 assertEquals( expectedRepository.isDeleteReleasedSnapshots(), actualRepository.isDeleteReleasedSnapshots() );
546 assertEquals( expectedRepository.isScanned(), actualRepository.isScanned() );
547 assertEquals( expectedRepository.isReleases(), actualRepository.isReleases() );
548 assertEquals( expectedRepository.isSnapshots(), actualRepository.isSnapshots() );
551 private Configuration createConfigurationForEditing( ManagedRepository repositoryConfiguration )
554 Configuration configuration = buildEasyConfiguration();
556 ManagedRepositoryConfiguration managedRepositoryConfiguration = new ManagedRepositoryConfiguration();
558 managedRepositoryConfiguration.setDaysOlder( repositoryConfiguration.getDaysOlder() );
559 managedRepositoryConfiguration.setIndexDir( repositoryConfiguration.getIndexDirectory() );
560 managedRepositoryConfiguration.setRetentionCount( repositoryConfiguration.getRetentionCount() );
561 managedRepositoryConfiguration.setBlockRedeployments( repositoryConfiguration.isBlockRedeployments() );
562 managedRepositoryConfiguration.setDeleteReleasedSnapshots(
563 repositoryConfiguration.isDeleteReleasedSnapshots() );
564 managedRepositoryConfiguration.setLocation( repositoryConfiguration.getLocation() );
565 managedRepositoryConfiguration.setRefreshCronExpression( repositoryConfiguration.getCronExpression() );
566 managedRepositoryConfiguration.setReleases( repositoryConfiguration.isReleases() );
567 managedRepositoryConfiguration.setScanned( repositoryConfiguration.isScanned() );
568 managedRepositoryConfiguration.setId( repositoryConfiguration.getId() );
569 managedRepositoryConfiguration.setName( repositoryConfiguration.getName() );
570 managedRepositoryConfiguration.setLayout( repositoryConfiguration.getLayout() );
572 configuration.addManagedRepository( managedRepositoryConfiguration );
573 return configuration;
576 // easy configuration for hashCode/equals
577 private Configuration buildEasyConfiguration()
579 return new Configuration()
582 public int hashCode()
584 return getManagedRepositories().size();
588 public boolean equals( Object o )
595 private ManagedRepository createRepository()
598 ManagedRepository r = new ManagedRepository();
600 populateRepository( r );
604 private ManagedRepositoryConfiguration createStagingRepository()
607 ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration();
608 r.setId( REPO_ID + "-stage" );
609 populateStagingRepository( r );
613 private void populateStagingRepository( ManagedRepositoryConfiguration repository )
616 repository.setId( REPO_ID + "-stage" );
617 repository.setName( "repo name" );
618 repository.setLocation( "${appserver.base}/location" );
619 repository.setLayout( "default" );
620 repository.setRefreshCronExpression( "* 0/5 * * * ?" );
621 repository.setDaysOlder( 31 );
622 repository.setRetentionCount( 20 );
623 repository.setReleases( true );
624 repository.setSnapshots( true );
625 repository.setScanned( false );
626 repository.setDeleteReleasedSnapshots( true );