]> source.dussan.org Git - archiva.git/blob
b4b2e2d4f8c99e900b8c47738650f376a504fb24
[archiva.git] /
1 package org.apache.archiva.web.action.admin.repositories;
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 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.scheduler.repository.RepositoryArchivaTaskScheduler;
35 import org.apache.archiva.scheduler.repository.RepositoryTask;
36 import org.apache.archiva.security.common.ArchivaRoleConstants;
37 import org.apache.archiva.web.validator.utils.ValidatorUtil;
38 import org.apache.archiva.webtest.memory.TestRepositorySessionFactory;
39 import org.apache.commons.io.FileUtils;
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;
46
47 import java.io.File;
48 import java.io.IOException;
49 import java.util.ArrayList;
50 import java.util.HashMap;
51 import java.util.List;
52 import java.util.Map;
53
54 import static org.mockito.Mockito.mock;
55 import static org.mockito.Mockito.when;
56
57 /**
58  * EditManagedRepositoryActionTest
59  *
60  * @version $Id$
61  */
62 public class EditManagedRepositoryActionTest
63     extends AbstractManagedRepositoryActionTest
64 {
65     private EditManagedRepositoryAction action;
66
67     private RoleManager roleManager;
68
69     private MockControl roleManagerControl;
70
71     private MockControl archivaConfigurationControl;
72
73     private ArchivaConfiguration archivaConfiguration;
74
75     private Registry registry;
76
77     private MockControl registryControl;
78
79     private MetadataRepository metadataRepository;
80
81     private MockControl repositoryTaskSchedulerControl;
82
83     private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
84
85     @Override
86     protected void setUp()
87         throws Exception
88     {
89         super.setUp();
90
91         action = new EditManagedRepositoryAction();
92
93         archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
94         archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
95
96         roleManagerControl = MockControl.createControl( RoleManager.class );
97         roleManager = (RoleManager) roleManagerControl.getMock();
98
99         registryControl = MockControl.createControl( Registry.class );
100         registry = (Registry) registryControl.getMock();
101
102         repositoryTaskSchedulerControl = MockClassControl.createControl( RepositoryArchivaTaskScheduler.class );
103         repositoryTaskScheduler = (RepositoryArchivaTaskScheduler) repositoryTaskSchedulerControl.getMock();
104
105         location = new File( System.getProperty( "basedir", "target/test/location" ) );
106
107         metadataRepository = mock( MetadataRepository.class );
108         RepositorySession repositorySession = mock( RepositorySession.class );
109         when( repositorySession.getRepository() ).thenReturn( metadataRepository );
110         TestRepositorySessionFactory factory = applicationContext.getBean( TestRepositorySessionFactory.class );
111         factory.setRepositorySession( repositorySession );
112
113         ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setArchivaConfiguration( archivaConfiguration );
114         ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRoleManager( roleManager );
115         ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositoryTaskScheduler(
116             repositoryTaskScheduler );
117         ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositorySessionFactory( factory );
118
119         ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRegistry( registry );
120
121         ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setAuditListeners(
122             new ArrayList<AuditListener>( 0 ) );
123
124         DefaultRepositoryCommonValidator defaultRepositoryCommonValidator = new DefaultRepositoryCommonValidator();
125         defaultRepositoryCommonValidator.setArchivaConfiguration( archivaConfiguration );
126         defaultRepositoryCommonValidator.setRegistry( registry );
127
128         ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositoryCommonValidator(
129             defaultRepositoryCommonValidator );
130
131         action.setRepositoryCommonValidator( defaultRepositoryCommonValidator );
132
133         action.setManagedRepositoryAdmin( getManagedRepositoryAdmin() );
134
135     }
136
137     public void testSecureActionBundle()
138         throws SecureActionException, RepositoryAdminException
139     {
140         archivaConfiguration.getConfiguration();
141         archivaConfigurationControl.setReturnValue( new Configuration() );
142         archivaConfigurationControl.replay();
143
144         action.prepare();
145         SecureActionBundle bundle = action.getSecureActionBundle();
146         assertTrue( bundle.requiresAuthentication() );
147         assertEquals( 1, bundle.getAuthorizationTuples().size() );
148     }
149
150     public void testEditRepositoryInitialPage()
151         throws Exception
152     {
153         Configuration configuration = createConfigurationForEditing( createRepository() );
154
155         archivaConfiguration.getConfiguration();
156         archivaConfigurationControl.setReturnValue( configuration );
157         Configuration stageRepoConfiguration = new Configuration();
158         stageRepoConfiguration.addManagedRepository( createStagingRepository() );
159         archivaConfigurationControl.setReturnValue( stageRepoConfiguration );
160
161         archivaConfigurationControl.replay();
162
163         action.setRepoid( REPO_ID );
164
165         action.prepare();
166         assertEquals( REPO_ID, action.getRepoid() );
167         ManagedRepository repository = action.getRepository();
168         assertNotNull( repository );
169
170         ManagedRepository newRepository = createRepository();
171         assertRepositoryEquals( repository, newRepository );
172         assertEquals( repository.getLocation(), newRepository.getLocation() );
173
174         String status = action.input();
175         assertEquals( Action.INPUT, status );
176         repository = action.getRepository();
177         assertRepositoryEquals( repository, createRepository() );
178     }
179
180     public void testEditRepository()
181         throws Exception
182     {
183         String stageRepoId = REPO_ID + "-stage";
184
185         roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
186         roleManagerControl.setReturnValue( false );
187         roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
188         roleManagerControl.setVoidCallable();
189
190         roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
191         roleManagerControl.setReturnValue( false );
192         roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
193         roleManagerControl.setVoidCallable();
194
195         roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, stageRepoId );
196         roleManagerControl.setReturnValue( false );
197         roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, stageRepoId );
198         roleManagerControl.setVoidCallable();
199
200         roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, stageRepoId );
201         roleManagerControl.setReturnValue( false );
202         roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, stageRepoId );
203         roleManagerControl.setVoidCallable();
204
205         roleManagerControl.replay();
206
207         registry.getString( "appserver.base", "${appserver.base}" );
208         registryControl.setReturnValue( "target/test", 1, 3 );
209         registry.getString( "appserver.home", "${appserver.home}" );
210         registryControl.setReturnValue( "target/test", 1, 3 );
211
212         registryControl.replay();
213
214         RepositoryTask task = new RepositoryTask();
215         task.setRepositoryId( REPO_ID );
216         repositoryTaskScheduler.isProcessingRepositoryTask( REPO_ID );
217         repositoryTaskSchedulerControl.setReturnValue( false );
218         repositoryTaskScheduler.queueTask( task );
219         repositoryTaskSchedulerControl.setVoidCallable();
220
221         RepositoryTask stageTask = new RepositoryTask();
222         stageTask.setRepositoryId( stageRepoId );
223         repositoryTaskScheduler.isProcessingRepositoryTask( stageRepoId );
224         repositoryTaskSchedulerControl.setReturnValue( false );
225         repositoryTaskScheduler.queueTask( stageTask );
226         repositoryTaskSchedulerControl.setVoidCallable();
227
228         repositoryTaskSchedulerControl.replay();
229
230         Configuration configuration = createConfigurationForEditing( createRepository() );
231         archivaConfiguration.getConfiguration();
232         archivaConfigurationControl.setReturnValue( configuration );
233         archivaConfigurationControl.setReturnValue( configuration );
234         archivaConfigurationControl.setReturnValue( configuration );
235
236         archivaConfigurationControl.setReturnValue( configuration );
237         archivaConfigurationControl.setReturnValue( configuration );
238
239         Configuration stageRepoConfiguration = new Configuration();
240         stageRepoConfiguration.addManagedRepository( createStagingRepository() );
241         archivaConfigurationControl.setReturnValue( stageRepoConfiguration );
242         archivaConfigurationControl.setReturnValue( configuration );
243         archivaConfigurationControl.setReturnValue( configuration );
244
245         archivaConfiguration.save( configuration );
246         archivaConfiguration.save( configuration );
247
248         archivaConfiguration.save( configuration );
249
250         archivaConfigurationControl.replay();
251
252         action.setRepoid( REPO_ID );
253         action.prepare();
254         assertEquals( REPO_ID, action.getRepoid() );
255         ManagedRepository repository = action.getRepository();
256         populateRepository( repository );
257         repository.setName( "new repo name" );
258
259         MockControl repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class );
260         RepositoryStatisticsManager repositoryStatisticsManager =
261             (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock();
262         ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositoryStatisticsManager(
263             repositoryStatisticsManager );
264         // no deletion
265         repositoryStatisticsManagerControl.replay();
266
267         new File( "target/test/" + REPO_ID + "-stage" ).mkdirs();
268
269         action.setRepository( repository );
270         action.setStageNeeded( true );
271         String status = action.commit();
272         assertEquals( Action.SUCCESS, status );
273
274         ManagedRepository newRepository = createRepository();
275         newRepository.setName( "new repo name" );
276         assertRepositoryEquals( repository, newRepository );
277         //assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() );
278         //assertEquals( location.getCanonicalPath(), new File( repository.getLocation() ).getCanonicalPath() );
279
280         roleManagerControl.verify();
281         //archivaConfigurationControl.verify();
282         repositoryStatisticsManagerControl.verify();
283         registryControl.verify();
284     }
285
286     public void testEditRepositoryLocationChanged()
287         throws Exception
288     {
289         roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
290         roleManagerControl.setReturnValue( false );
291         roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
292         roleManagerControl.setVoidCallable();
293
294         roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
295         roleManagerControl.setReturnValue( false );
296         roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
297         roleManagerControl.setVoidCallable();
298
299         roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID + "-stage" );
300         roleManagerControl.setReturnValue( false );
301         roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID + "-stage" );
302         roleManagerControl.setVoidCallable();
303
304         roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID + "-stage" );
305         roleManagerControl.setReturnValue( false );
306         roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID + "-stage" );
307         roleManagerControl.setVoidCallable();
308
309         roleManagerControl.replay();
310
311         registry.getString( "appserver.base" );
312         registryControl.setReturnValue( "target/test", 1, 3 );
313
314         registry.getString( "appserver.base", "${appserver.base}" );
315         registryControl.setReturnValue( "target/test", 1, 3 );
316         registry.getString( "appserver.home", "${appserver.home}" );
317         registryControl.setReturnValue( "target/test", 1, 3 );
318
319         registryControl.replay();
320
321         RepositoryTask task = new RepositoryTask();
322         task.setRepositoryId( REPO_ID );
323         repositoryTaskScheduler.isProcessingRepositoryTask( REPO_ID );
324         repositoryTaskSchedulerControl.setReturnValue( false );
325         repositoryTaskScheduler.queueTask( task );
326         repositoryTaskSchedulerControl.setVoidCallable();
327
328         repositoryTaskSchedulerControl.replay();
329
330         Configuration configuration = createConfigurationForEditing( createRepository() );
331         archivaConfiguration.getConfiguration();
332
333         archivaConfigurationControl.setReturnValue( configuration );
334         archivaConfigurationControl.setReturnValue( configuration );
335         archivaConfigurationControl.setReturnValue( configuration );
336         archivaConfigurationControl.setReturnValue( configuration );
337
338         archivaConfigurationControl.setReturnValue( configuration );
339
340         archivaConfigurationControl.setReturnValue( buildEasyConfiguration() );
341
342         Configuration stageRepoConfiguration = buildEasyConfiguration();
343         stageRepoConfiguration.addManagedRepository( createStagingRepository() );
344         archivaConfigurationControl.setReturnValue( stageRepoConfiguration );
345
346         archivaConfigurationControl.setReturnValue( configuration );
347         archivaConfigurationControl.setReturnValue( configuration );
348
349         archivaConfiguration.save( configuration );
350         configuration.addManagedRepository( stageRepoConfiguration.getManagedRepositories().get( 0 ) );
351         archivaConfiguration.save( configuration );
352         archivaConfiguration.save( configuration );
353
354         archivaConfigurationControl.replay();
355
356         MockControl repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class );
357         RepositoryStatisticsManager repositoryStatisticsManager =
358             (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock();
359         ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositoryStatisticsManager(
360             repositoryStatisticsManager );
361         repositoryStatisticsManager.deleteStatistics( metadataRepository, REPO_ID );
362         repositoryStatisticsManagerControl.replay();
363
364         new File( "target/test/location/" + REPO_ID + "-stage" ).mkdirs();
365
366         action.setStageNeeded( true );
367         action.setRepoid( REPO_ID );
368         action.prepare();
369         assertEquals( REPO_ID, action.getRepoid() );
370
371         ManagedRepository repository = new ManagedRepository();
372         populateRepository( repository );
373         File testFile = new File( "target/test/location/new" );
374         FileUtils.deleteDirectory( testFile );
375         repository.setLocation( "${appserver.base}/location/new" );
376         action.setRepository( repository );
377         String status = action.commit();
378         assertEquals( Action.SUCCESS, status );
379         //assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() );
380         //assertEquals( testFile.getCanonicalPath(), new File( repository.getLocation() ).getCanonicalPath() );
381
382         roleManagerControl.verify();
383         //archivaConfigurationControl.verify();
384         repositoryStatisticsManagerControl.verify();
385         registryControl.verify();
386     }
387
388     public void testStruts2ValidationFrameworkWithNullInputs()
389         throws Exception
390     {
391         // prep
392         // 0 is the default value for primitive int; null for objects
393         ManagedRepository managedRepositoryConfiguration = createManagedRepository( null, null, null, null, 1, 1 );
394         action.setRepository( managedRepositoryConfiguration );
395
396         // test
397         actionValidatorManager.validate( action, EMPTY_STRING );
398
399         // verify
400         assertTrue( action.hasFieldErrors() );
401
402         Map<String, List<String>> fieldErrors = action.getFieldErrors();
403
404         // make an expected field error object
405         Map<String, List<String>> expectedFieldErrors = new HashMap<String, List<String>>();
406
407         // populate
408         List<String> expectedErrorMessages = new ArrayList<String>();
409         expectedErrorMessages.add( "You must enter a repository identifier." );
410         expectedFieldErrors.put( "repository.id", expectedErrorMessages );
411
412         expectedErrorMessages = new ArrayList<String>();
413         expectedErrorMessages.add( "You must enter a directory." );
414         expectedFieldErrors.put( "repository.location", expectedErrorMessages );
415
416         expectedErrorMessages = new ArrayList<String>();
417         expectedErrorMessages.add( "You must enter a repository name." );
418         expectedFieldErrors.put( "repository.name", expectedErrorMessages );
419
420         ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors );
421     }
422
423     public void testStruts2ValidationFrameworkWithBlankInputs()
424         throws Exception
425     {
426         // prep
427         // 0 is the default value for primitive int
428         ManagedRepository managedRepositoryConfiguration =
429             createManagedRepository( EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, 1, 1 );
430         action.setRepository( managedRepositoryConfiguration );
431
432         // test
433         actionValidatorManager.validate( action, EMPTY_STRING );
434
435         // verify
436         assertTrue( action.hasFieldErrors() );
437
438         Map<String, List<String>> fieldErrors = action.getFieldErrors();
439
440         // make an expected field error object
441         Map<String, List<String>> expectedFieldErrors = new HashMap<String, List<String>>();
442
443         // populate
444         List<String> expectedErrorMessages = new ArrayList<String>();
445         expectedErrorMessages.add( "You must enter a repository identifier." );
446         expectedFieldErrors.put( "repository.id", expectedErrorMessages );
447
448         expectedErrorMessages = new ArrayList<String>();
449         expectedErrorMessages.add( "You must enter a directory." );
450         expectedFieldErrors.put( "repository.location", expectedErrorMessages );
451
452         expectedErrorMessages = new ArrayList<String>();
453         expectedErrorMessages.add( "You must enter a repository name." );
454         expectedFieldErrors.put( "repository.name", expectedErrorMessages );
455
456         ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors );
457     }
458
459     public void testStruts2ValidationFrameworkWithInvalidInputs()
460         throws Exception
461     {
462         // prep
463         ManagedRepository managedRepositoryConfiguration =
464             createManagedRepository( REPOSITORY_ID_INVALID_INPUT, REPOSITORY_NAME_INVALID_INPUT,
465                                      REPOSITORY_LOCATION_INVALID_INPUT, REPOSITORY_INDEX_DIR_INVALID_INPUT,
466                                      REPOSITORY_DAYS_OLDER_INVALID_INPUT, REPOSITORY_RETENTION_COUNT_INVALID_INPUT );
467         action.setRepository( managedRepositoryConfiguration );
468
469         // test
470         actionValidatorManager.validate( action, EMPTY_STRING );
471
472         // verify
473         assertTrue( action.hasFieldErrors() );
474
475         Map<String, List<String>> fieldErrors = action.getFieldErrors();
476
477         // make an expected field error object
478         Map<String, List<String>> expectedFieldErrors = new HashMap<String, List<String>>();
479
480         // populate
481         List<String> expectedErrorMessages = new ArrayList<String>();
482         expectedErrorMessages.add(
483             "Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)." );
484         expectedFieldErrors.put( "repository.id", expectedErrorMessages );
485
486         expectedErrorMessages = new ArrayList<String>();
487         expectedErrorMessages.add(
488             "Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
489         expectedFieldErrors.put( "repository.location", expectedErrorMessages );
490
491         expectedErrorMessages = new ArrayList<String>();
492         expectedErrorMessages.add(
493             "Repository Name must only contain alphanumeric characters, white-spaces(' '), forward-slashes(/), open-parenthesis('('), close-parenthesis(')'),  underscores(_), dots(.), and dashes(-)." );
494         expectedFieldErrors.put( "repository.name", expectedErrorMessages );
495
496         expectedErrorMessages = new ArrayList<String>();
497         expectedErrorMessages.add(
498             "Index directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
499         expectedFieldErrors.put( "repository.indexDirectory", expectedErrorMessages );
500
501         expectedErrorMessages = new ArrayList<String>();
502         expectedErrorMessages.add( "Repository Purge By Retention Count needs to be between 1 and 100." );
503         expectedFieldErrors.put( "repository.retentionCount", expectedErrorMessages );
504
505         expectedErrorMessages = new ArrayList<String>();
506         expectedErrorMessages.add( "Repository Purge By Days Older Than needs to be larger than 0." );
507         expectedFieldErrors.put( "repository.daysOlder", expectedErrorMessages );
508
509         ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors );
510     }
511
512     public void testStruts2ValidationFrameworkWithValidInputs()
513         throws Exception
514     {
515         // prep
516         ManagedRepository managedRepositoryConfiguration =
517             createManagedRepository( REPOSITORY_ID_VALID_INPUT, REPOSITORY_NAME_VALID_INPUT,
518                                      REPOSITORY_LOCATION_VALID_INPUT, REPOSITORY_INDEX_DIR_VALID_INPUT,
519                                      REPOSITORY_DAYS_OLDER_VALID_INPUT, REPOSITORY_RETENTION_COUNT_VALID_INPUT );
520         action.setRepository( managedRepositoryConfiguration );
521
522         // test
523         actionValidatorManager.validate( action, EMPTY_STRING );
524
525         // verify
526         assertFalse( action.hasFieldErrors() );
527     }
528
529     private void assertRepositoryEquals( ManagedRepository expectedRepository, ManagedRepository actualRepository )
530     {
531         assertEquals( expectedRepository.getDaysOlder(), actualRepository.getDaysOlder() );
532         assertEquals( expectedRepository.getId(), actualRepository.getId() );
533         assertEquals( expectedRepository.getIndexDirectory(), actualRepository.getIndexDirectory() );
534         assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() );
535         assertEquals( expectedRepository.getName(), actualRepository.getName() );
536         assertEquals( expectedRepository.getCronExpression(), actualRepository.getCronExpression() );
537         assertEquals( expectedRepository.getRetentionCount(), actualRepository.getRetentionCount() );
538         assertEquals( expectedRepository.isDeleteReleasedSnapshots(), actualRepository.isDeleteReleasedSnapshots() );
539         assertEquals( expectedRepository.isScanned(), actualRepository.isScanned() );
540         assertEquals( expectedRepository.isReleases(), actualRepository.isReleases() );
541         assertEquals( expectedRepository.isSnapshots(), actualRepository.isSnapshots() );
542     }
543
544     private Configuration createConfigurationForEditing( ManagedRepository repositoryConfiguration )
545         throws Exception
546     {
547         Configuration configuration = buildEasyConfiguration();
548
549         ManagedRepositoryConfiguration managedRepositoryConfiguration = new ManagedRepositoryConfiguration();
550
551         managedRepositoryConfiguration.setDaysOlder( repositoryConfiguration.getDaysOlder() );
552         managedRepositoryConfiguration.setIndexDir( repositoryConfiguration.getIndexDirectory() );
553         managedRepositoryConfiguration.setRetentionCount( repositoryConfiguration.getRetentionCount() );
554         managedRepositoryConfiguration.setBlockRedeployments( repositoryConfiguration.isBlockRedeployments() );
555         managedRepositoryConfiguration.setDeleteReleasedSnapshots(
556             repositoryConfiguration.isDeleteReleasedSnapshots() );
557         managedRepositoryConfiguration.setLocation( repositoryConfiguration.getLocation() );
558         managedRepositoryConfiguration.setRefreshCronExpression( repositoryConfiguration.getCronExpression() );
559         managedRepositoryConfiguration.setReleases( repositoryConfiguration.isReleases() );
560         managedRepositoryConfiguration.setScanned( repositoryConfiguration.isScanned() );
561         managedRepositoryConfiguration.setId( repositoryConfiguration.getId() );
562         managedRepositoryConfiguration.setName( repositoryConfiguration.getName() );
563         managedRepositoryConfiguration.setLayout( repositoryConfiguration.getLayout() );
564
565         configuration.addManagedRepository( managedRepositoryConfiguration );
566         return configuration;
567     }
568
569     // easy configuration for hashCode/equals
570     private Configuration buildEasyConfiguration()
571     {
572         return new Configuration()
573         {
574             @Override
575             public int hashCode()
576             {
577                 return getManagedRepositories().size();
578             }
579
580             @Override
581             public boolean equals( Object o )
582             {
583                 return true;
584             }
585         };
586     }
587
588     private ManagedRepository createRepository()
589         throws IOException
590     {
591         ManagedRepository r = new ManagedRepository();
592         r.setId( REPO_ID );
593         populateRepository( r );
594         return r;
595     }
596
597     private ManagedRepositoryConfiguration createStagingRepository()
598         throws IOException
599     {
600         ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration();
601         r.setId( REPO_ID + "-stage" );
602         populateStagingRepository( r );
603         return r;
604     }
605
606     private void populateStagingRepository( ManagedRepositoryConfiguration repository )
607         throws IOException
608     {
609         repository.setId( REPO_ID + "-stage" );
610         repository.setName( "repo name" );
611         repository.setLocation( "${appserver.base}/location" );
612         repository.setLayout( "default" );
613         repository.setRefreshCronExpression( "* 0/5 * * * ?" );
614         repository.setDaysOlder( 31 );
615         repository.setRetentionCount( 20 );
616         repository.setReleases( true );
617         repository.setSnapshots( true );
618         repository.setScanned( false );
619         repository.setDeleteReleasedSnapshots( true );
620     }
621 }