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;
57 * EditManagedRepositoryActionTest
61 public class EditManagedRepositoryActionTest
62 extends AbstractManagedRepositoryActionTest
64 private EditManagedRepositoryAction action;
66 private RoleManager roleManager;
68 private MockControl roleManagerControl;
70 private MockControl archivaConfigurationControl;
72 private ArchivaConfiguration archivaConfiguration;
74 private org.apache.archiva.redback.components.registry.Registry registry;
76 private MockControl registryControl;
78 private MetadataRepository metadataRepository;
80 private MockControl repositoryTaskSchedulerControl;
82 private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
85 protected void setUp()
90 action = new EditManagedRepositoryAction();
92 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
93 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
95 roleManagerControl = MockControl.createControl( RoleManager.class );
96 roleManager = (RoleManager) roleManagerControl.getMock();
98 registryControl = MockControl.createControl( org.apache.archiva.redback.components.registry.Registry.class );
99 registry = (org.apache.archiva.redback.components.registry.Registry) registryControl.getMock();
101 repositoryTaskSchedulerControl = MockClassControl.createControl( RepositoryArchivaTaskScheduler.class );
102 repositoryTaskScheduler = (RepositoryArchivaTaskScheduler) repositoryTaskSchedulerControl.getMock();
104 location = new File( System.getProperty( "basedir", "target/test/location" ) );
106 metadataRepository = mock( MetadataRepository.class );
107 RepositorySession repositorySession = mock( RepositorySession.class );
108 when( repositorySession.getRepository() ).thenReturn( metadataRepository );
109 TestRepositorySessionFactory factory = applicationContext.getBean( TestRepositorySessionFactory.class );
110 factory.setRepositorySession( repositorySession );
112 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setArchivaConfiguration( archivaConfiguration );
113 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRoleManager( roleManager );
114 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositoryTaskScheduler(
115 repositoryTaskScheduler );
116 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositorySessionFactory( factory );
118 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRegistry( registry );
120 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setAuditListeners(
121 new ArrayList<AuditListener>( 0 ) );
123 DefaultRepositoryCommonValidator defaultRepositoryCommonValidator = new DefaultRepositoryCommonValidator();
124 defaultRepositoryCommonValidator.setArchivaConfiguration( archivaConfiguration );
125 defaultRepositoryCommonValidator.setRegistry( registry );
127 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositoryCommonValidator(
128 defaultRepositoryCommonValidator );
130 action.setRepositoryCommonValidator( defaultRepositoryCommonValidator );
132 action.setManagedRepositoryAdmin( getManagedRepositoryAdmin() );
136 public void testSecureActionBundle()
137 throws SecureActionException, RepositoryAdminException
139 archivaConfiguration.getConfiguration();
140 archivaConfigurationControl.setReturnValue( new Configuration() );
141 archivaConfigurationControl.replay();
144 SecureActionBundle bundle = action.getSecureActionBundle();
145 assertTrue( bundle.requiresAuthentication() );
146 assertEquals( 1, bundle.getAuthorizationTuples().size() );
149 public void testEditRepositoryInitialPage()
152 Configuration configuration = createConfigurationForEditing( createRepository() );
154 archivaConfiguration.getConfiguration();
155 archivaConfigurationControl.setReturnValue( configuration );
156 Configuration stageRepoConfiguration = new Configuration();
157 stageRepoConfiguration.addManagedRepository( createStagingRepository() );
158 archivaConfigurationControl.setReturnValue( stageRepoConfiguration );
160 archivaConfigurationControl.replay();
162 action.setRepoid( REPO_ID );
165 assertEquals( REPO_ID, action.getRepoid() );
166 ManagedRepository repository = action.getRepository();
167 assertNotNull( repository );
169 ManagedRepository newRepository = createRepository();
170 assertRepositoryEquals( repository, newRepository );
171 assertEquals( repository.getLocation(), newRepository.getLocation() );
173 String status = action.input();
174 assertEquals( Action.INPUT, status );
175 repository = action.getRepository();
176 assertRepositoryEquals( repository, createRepository() );
179 public void testEditRepository()
182 String stageRepoId = REPO_ID + "-stage";
184 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
185 roleManagerControl.setReturnValue( false );
186 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
187 roleManagerControl.setVoidCallable();
189 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
190 roleManagerControl.setReturnValue( false );
191 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
192 roleManagerControl.setVoidCallable();
194 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, stageRepoId );
195 roleManagerControl.setReturnValue( false );
196 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, stageRepoId );
197 roleManagerControl.setVoidCallable();
199 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, stageRepoId );
200 roleManagerControl.setReturnValue( false );
201 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, stageRepoId );
202 roleManagerControl.setVoidCallable();
204 roleManagerControl.replay();
206 registry.getString( "appserver.base", "${appserver.base}" );
207 registryControl.setReturnValue( "target/test", 1, 3 );
208 registry.getString( "appserver.home", "${appserver.home}" );
209 registryControl.setReturnValue( "target/test", 1, 3 );
211 registryControl.replay();
213 RepositoryTask task = new RepositoryTask();
214 task.setRepositoryId( REPO_ID );
215 repositoryTaskScheduler.isProcessingRepositoryTask( REPO_ID );
216 repositoryTaskSchedulerControl.setReturnValue( false );
217 repositoryTaskScheduler.queueTask( task );
218 repositoryTaskSchedulerControl.setVoidCallable();
220 RepositoryTask stageTask = new RepositoryTask();
221 stageTask.setRepositoryId( stageRepoId );
222 repositoryTaskScheduler.isProcessingRepositoryTask( stageRepoId );
223 repositoryTaskSchedulerControl.setReturnValue( false );
224 repositoryTaskScheduler.queueTask( stageTask );
225 repositoryTaskSchedulerControl.setVoidCallable();
227 repositoryTaskSchedulerControl.replay();
229 Configuration configuration = createConfigurationForEditing( createRepository() );
230 archivaConfiguration.getConfiguration();
231 archivaConfigurationControl.setReturnValue( configuration );
232 archivaConfigurationControl.setReturnValue( configuration );
233 archivaConfigurationControl.setReturnValue( configuration );
235 archivaConfigurationControl.setReturnValue( configuration );
236 archivaConfigurationControl.setReturnValue( configuration );
238 Configuration stageRepoConfiguration = new Configuration();
239 stageRepoConfiguration.addManagedRepository( createStagingRepository() );
240 archivaConfigurationControl.setReturnValue( stageRepoConfiguration );
241 archivaConfigurationControl.setReturnValue( configuration );
242 archivaConfigurationControl.setReturnValue( configuration );
244 archivaConfiguration.save( configuration );
245 archivaConfiguration.save( configuration );
247 archivaConfiguration.save( configuration );
249 archivaConfigurationControl.replay();
251 action.setRepoid( REPO_ID );
253 assertEquals( REPO_ID, action.getRepoid() );
254 ManagedRepository repository = action.getRepository();
255 populateRepository( repository );
256 repository.setName( "new repo name" );
258 MockControl repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class );
259 RepositoryStatisticsManager repositoryStatisticsManager =
260 (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock();
261 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositoryStatisticsManager(
262 repositoryStatisticsManager );
263 repositoryStatisticsManager.deleteStatistics( metadataRepository , REPO_ID );
264 repositoryStatisticsManagerControl.setVoidCallable();
265 repositoryStatisticsManagerControl.replay();
267 new File( "target/test/" + REPO_ID + "-stage" ).mkdirs();
269 repository.setLocation( System.getProperty( "basedir" ) + "/target/test/" + REPO_ID );
271 action.setRepository( repository );
272 action.setStageNeeded( true );
273 String status = action.commit();
274 assertEquals( Action.SUCCESS, status );
276 ManagedRepository newRepository = createRepository();
277 newRepository.setName( "new repo name" );
278 assertRepositoryEquals( repository, newRepository );
279 //assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() );
280 //assertEquals( location.getCanonicalPath(), new File( repository.getLocation() ).getCanonicalPath() );
282 roleManagerControl.verify();
283 //archivaConfigurationControl.verify();
284 repositoryStatisticsManagerControl.verify();
285 registryControl.verify();
288 public void testEditRepositoryLocationChanged()
291 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
292 roleManagerControl.setReturnValue( false );
293 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
294 roleManagerControl.setVoidCallable();
296 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
297 roleManagerControl.setReturnValue( false );
298 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
299 roleManagerControl.setVoidCallable();
301 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID + "-stage" );
302 roleManagerControl.setReturnValue( false );
303 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID + "-stage" );
304 roleManagerControl.setVoidCallable();
306 roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID + "-stage" );
307 roleManagerControl.setReturnValue( false );
308 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID + "-stage" );
309 roleManagerControl.setVoidCallable();
311 roleManagerControl.replay();
313 registry.getString( "appserver.base" );
314 registryControl.setReturnValue( "target/test", 1, 3 );
316 registry.getString( "appserver.base", "${appserver.base}" );
317 registryControl.setReturnValue( "target/test", 1, 3 );
318 registry.getString( "appserver.home", "${appserver.home}" );
319 registryControl.setReturnValue( "target/test", 1, 3 );
321 registryControl.replay();
323 RepositoryTask task = new RepositoryTask();
324 task.setRepositoryId( REPO_ID );
325 repositoryTaskScheduler.isProcessingRepositoryTask( REPO_ID );
326 repositoryTaskSchedulerControl.setReturnValue( false );
327 repositoryTaskScheduler.queueTask( task );
328 repositoryTaskSchedulerControl.setVoidCallable();
330 repositoryTaskSchedulerControl.replay();
332 Configuration configuration = createConfigurationForEditing( createRepository() );
333 archivaConfiguration.getConfiguration();
335 archivaConfigurationControl.setReturnValue( configuration );
336 archivaConfigurationControl.setReturnValue( configuration );
337 archivaConfigurationControl.setReturnValue( configuration );
338 archivaConfigurationControl.setReturnValue( configuration );
340 archivaConfigurationControl.setReturnValue( configuration );
342 archivaConfigurationControl.setReturnValue( buildEasyConfiguration() );
344 Configuration stageRepoConfiguration = buildEasyConfiguration();
345 stageRepoConfiguration.addManagedRepository( createStagingRepository() );
346 archivaConfigurationControl.setReturnValue( stageRepoConfiguration );
348 archivaConfigurationControl.setReturnValue( configuration );
349 archivaConfigurationControl.setReturnValue( configuration );
351 archivaConfiguration.save( configuration );
352 configuration.addManagedRepository( stageRepoConfiguration.getManagedRepositories().get( 0 ) );
353 archivaConfiguration.save( configuration );
354 archivaConfiguration.save( configuration );
356 archivaConfigurationControl.replay();
358 MockControl repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class );
359 RepositoryStatisticsManager repositoryStatisticsManager =
360 (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock();
361 ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositoryStatisticsManager(
362 repositoryStatisticsManager );
363 repositoryStatisticsManager.deleteStatistics( metadataRepository, REPO_ID );
364 repositoryStatisticsManagerControl.replay();
366 new File( "target/test/location/" + REPO_ID + "-stage" ).mkdirs();
368 action.setStageNeeded( true );
369 action.setRepoid( REPO_ID );
371 assertEquals( REPO_ID, action.getRepoid() );
373 ManagedRepository repository = new ManagedRepository();
374 populateRepository( repository );
375 File testFile = new File( "target/test/location/new" );
376 FileUtils.deleteDirectory( testFile );
377 repository.setLocation( "${appserver.base}/location/new" );
378 action.setRepository( repository );
379 String status = action.commit();
380 assertEquals( Action.SUCCESS, status );
381 //assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() );
382 //assertEquals( testFile.getCanonicalPath(), new File( repository.getLocation() ).getCanonicalPath() );
384 roleManagerControl.verify();
385 //archivaConfigurationControl.verify();
386 repositoryStatisticsManagerControl.verify();
387 registryControl.verify();
390 public void testStruts2ValidationFrameworkWithNullInputs()
394 // 0 is the default value for primitive int; null for objects
395 ManagedRepository managedRepositoryConfiguration = createManagedRepository( null, null, null, null, 1, 1 );
396 action.setRepository( managedRepositoryConfiguration );
399 actionValidatorManager.validate( action, EMPTY_STRING );
402 assertTrue( action.hasFieldErrors() );
404 Map<String, List<String>> fieldErrors = action.getFieldErrors();
406 // make an expected field error object
407 Map<String, List<String>> expectedFieldErrors = new HashMap<String, List<String>>();
410 List<String> expectedErrorMessages = new ArrayList<String>();
411 expectedErrorMessages.add( "You must enter a repository identifier." );
412 expectedFieldErrors.put( "repository.id", expectedErrorMessages );
414 expectedErrorMessages = new ArrayList<String>();
415 expectedErrorMessages.add( "You must enter a directory." );
416 expectedFieldErrors.put( "repository.location", expectedErrorMessages );
418 expectedErrorMessages = new ArrayList<String>();
419 expectedErrorMessages.add( "You must enter a repository name." );
420 expectedFieldErrors.put( "repository.name", expectedErrorMessages );
422 ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors );
425 public void testStruts2ValidationFrameworkWithBlankInputs()
429 // 0 is the default value for primitive int
430 ManagedRepository managedRepositoryConfiguration =
431 createManagedRepository( EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, 1, 1 );
432 action.setRepository( managedRepositoryConfiguration );
435 actionValidatorManager.validate( action, EMPTY_STRING );
438 assertTrue( action.hasFieldErrors() );
440 Map<String, List<String>> fieldErrors = action.getFieldErrors();
442 // make an expected field error object
443 Map<String, List<String>> expectedFieldErrors = new HashMap<String, List<String>>();
446 List<String> expectedErrorMessages = new ArrayList<String>();
447 expectedErrorMessages.add( "You must enter a repository identifier." );
448 expectedFieldErrors.put( "repository.id", expectedErrorMessages );
450 expectedErrorMessages = new ArrayList<String>();
451 expectedErrorMessages.add( "You must enter a directory." );
452 expectedFieldErrors.put( "repository.location", expectedErrorMessages );
454 expectedErrorMessages = new ArrayList<String>();
455 expectedErrorMessages.add( "You must enter a repository name." );
456 expectedFieldErrors.put( "repository.name", expectedErrorMessages );
458 ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors );
461 public void testStruts2ValidationFrameworkWithInvalidInputs()
465 ManagedRepository managedRepositoryConfiguration =
466 createManagedRepository( REPOSITORY_ID_INVALID_INPUT, REPOSITORY_NAME_INVALID_INPUT,
467 REPOSITORY_LOCATION_INVALID_INPUT, REPOSITORY_INDEX_DIR_INVALID_INPUT,
468 REPOSITORY_DAYS_OLDER_INVALID_INPUT, REPOSITORY_RETENTION_COUNT_INVALID_INPUT );
469 action.setRepository( managedRepositoryConfiguration );
472 actionValidatorManager.validate( action, EMPTY_STRING );
475 assertTrue( action.hasFieldErrors() );
477 Map<String, List<String>> fieldErrors = action.getFieldErrors();
479 // make an expected field error object
480 Map<String, List<String>> expectedFieldErrors = new HashMap<String, List<String>>();
483 List<String> expectedErrorMessages = new ArrayList<String>();
484 expectedErrorMessages.add(
485 "Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)." );
486 expectedFieldErrors.put( "repository.id", expectedErrorMessages );
488 expectedErrorMessages = new ArrayList<String>();
489 expectedErrorMessages.add(
490 "Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
491 expectedFieldErrors.put( "repository.location", expectedErrorMessages );
493 expectedErrorMessages = new ArrayList<String>();
494 expectedErrorMessages.add(
495 "Repository Name must only contain alphanumeric characters, white-spaces(' '), forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-)." );
496 expectedFieldErrors.put( "repository.name", expectedErrorMessages );
498 expectedErrorMessages = new ArrayList<String>();
499 expectedErrorMessages.add(
500 "Index directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
501 expectedFieldErrors.put( "repository.indexDirectory", expectedErrorMessages );
503 expectedErrorMessages = new ArrayList<String>();
504 expectedErrorMessages.add( "Repository Purge By Retention Count needs to be between 1 and 100." );
505 expectedFieldErrors.put( "repository.retentionCount", expectedErrorMessages );
507 expectedErrorMessages = new ArrayList<String>();
508 expectedErrorMessages.add( "Repository Purge By Days Older Than needs to be larger than 0." );
509 expectedFieldErrors.put( "repository.daysOlder", expectedErrorMessages );
511 ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors );
514 public void testStruts2ValidationFrameworkWithValidInputs()
518 ManagedRepository managedRepositoryConfiguration =
519 createManagedRepository( REPOSITORY_ID_VALID_INPUT, REPOSITORY_NAME_VALID_INPUT,
520 REPOSITORY_LOCATION_VALID_INPUT, REPOSITORY_INDEX_DIR_VALID_INPUT,
521 REPOSITORY_DAYS_OLDER_VALID_INPUT, REPOSITORY_RETENTION_COUNT_VALID_INPUT );
522 action.setRepository( managedRepositoryConfiguration );
525 actionValidatorManager.validate( action, EMPTY_STRING );
528 assertFalse( action.hasFieldErrors() );
531 private void assertRepositoryEquals( ManagedRepository expectedRepository, ManagedRepository actualRepository )
533 assertEquals( expectedRepository.getDaysOlder(), actualRepository.getDaysOlder() );
534 assertEquals( expectedRepository.getId(), actualRepository.getId() );
535 assertEquals( expectedRepository.getIndexDirectory(), actualRepository.getIndexDirectory() );
536 assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() );
537 assertEquals( expectedRepository.getName(), actualRepository.getName() );
538 assertEquals( expectedRepository.getCronExpression(), actualRepository.getCronExpression() );
539 assertEquals( expectedRepository.getRetentionCount(), actualRepository.getRetentionCount() );
540 assertEquals( expectedRepository.isDeleteReleasedSnapshots(), actualRepository.isDeleteReleasedSnapshots() );
541 assertEquals( expectedRepository.isScanned(), actualRepository.isScanned() );
542 assertEquals( expectedRepository.isReleases(), actualRepository.isReleases() );
543 assertEquals( expectedRepository.isSnapshots(), actualRepository.isSnapshots() );
546 private Configuration createConfigurationForEditing( ManagedRepository repositoryConfiguration )
549 Configuration configuration = buildEasyConfiguration();
551 ManagedRepositoryConfiguration managedRepositoryConfiguration = new ManagedRepositoryConfiguration();
553 managedRepositoryConfiguration.setDaysOlder( repositoryConfiguration.getDaysOlder() );
554 managedRepositoryConfiguration.setIndexDir( repositoryConfiguration.getIndexDirectory() );
555 managedRepositoryConfiguration.setRetentionCount( repositoryConfiguration.getRetentionCount() );
556 managedRepositoryConfiguration.setBlockRedeployments( repositoryConfiguration.isBlockRedeployments() );
557 managedRepositoryConfiguration.setDeleteReleasedSnapshots(
558 repositoryConfiguration.isDeleteReleasedSnapshots() );
559 managedRepositoryConfiguration.setLocation( repositoryConfiguration.getLocation() );
560 managedRepositoryConfiguration.setRefreshCronExpression( repositoryConfiguration.getCronExpression() );
561 managedRepositoryConfiguration.setReleases( repositoryConfiguration.isReleases() );
562 managedRepositoryConfiguration.setScanned( repositoryConfiguration.isScanned() );
563 managedRepositoryConfiguration.setId( repositoryConfiguration.getId() );
564 managedRepositoryConfiguration.setName( repositoryConfiguration.getName() );
565 managedRepositoryConfiguration.setLayout( repositoryConfiguration.getLayout() );
567 configuration.addManagedRepository( managedRepositoryConfiguration );
568 return configuration;
571 // easy configuration for hashCode/equals
572 private Configuration buildEasyConfiguration()
574 return new Configuration()
577 public int hashCode()
579 return getManagedRepositories().size();
583 public boolean equals( Object o )
590 private ManagedRepository createRepository()
593 ManagedRepository r = new ManagedRepository();
594 r.setLocation( System.getProperty( "basedir" ) + "/target/repo-" + REPO_ID );
595 r.setIndexDirectory( System.getProperty( "basedir" ) + "/target/repo-" + REPO_ID + "-index" );
597 populateRepository( r );
601 private ManagedRepositoryConfiguration createStagingRepository()
604 ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration();
605 r.setId( REPO_ID + "-stage" );
606 r.setLocation( System.getProperty( "basedir" ) + "/target/" + REPO_ID + "-stage" );
607 populateStagingRepository( r );
611 private void populateStagingRepository( ManagedRepositoryConfiguration repository )
614 repository.setId( REPO_ID + "-stage" );
615 repository.setName( "repo name" );
616 repository.setLocation( "${appserver.base}/location" );
617 repository.setLayout( "default" );
618 repository.setRefreshCronExpression( "* 0/5 * * * ?" );
619 repository.setDaysOlder( 31 );
620 repository.setRetentionCount( 20 );
621 repository.setReleases( true );
622 repository.setSnapshots( true );
623 repository.setScanned( false );
624 repository.setDeleteReleasedSnapshots( true );