]> source.dussan.org Git - archiva.git/blob
7c5feded2bb409aacdac09b187ac3f1b79f39011
[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.RepositoryCommonValidator;
26 import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
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.archiva.security.ArchivaRoleConstants;
35 import org.apache.archiva.web.validator.utils.ValidatorUtil;
36 import org.apache.commons.io.FileUtils;
37 import org.apache.archiva.configuration.ArchivaConfiguration;
38 import org.apache.archiva.configuration.Configuration;
39 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
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( "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         RepositoryCommonValidator repositoryCommonValidator = new RepositoryCommonValidator();
125         repositoryCommonValidator.setArchivaConfiguration( archivaConfiguration );
126         repositoryCommonValidator.setRegistry( registry );
127
128         ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositoryCommonValidator(
129             repositoryCommonValidator );
130
131         action.setRepositoryCommonValidator( repositoryCommonValidator );
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" );
209         registry.getString( "appserver.home", "${appserver.home}" );
210         registryControl.setReturnValue( "target/test" );
211
212         registry.getString( "appserver.base", "${appserver.base}" );
213         registryControl.setReturnValue( "target/test" );
214         registry.getString( "appserver.home", "${appserver.home}" );
215         registryControl.setReturnValue( "target/test" );
216
217         registryControl.replay();
218
219         RepositoryTask task = new RepositoryTask();
220         task.setRepositoryId( REPO_ID );
221         repositoryTaskScheduler.isProcessingRepositoryTask( REPO_ID );
222         repositoryTaskSchedulerControl.setReturnValue( false );
223         repositoryTaskScheduler.queueTask( task );
224         repositoryTaskSchedulerControl.setVoidCallable();
225
226         RepositoryTask stageTask = new RepositoryTask();
227         stageTask.setRepositoryId( stageRepoId );
228         repositoryTaskScheduler.isProcessingRepositoryTask( stageRepoId );
229         repositoryTaskSchedulerControl.setReturnValue( false );
230         repositoryTaskScheduler.queueTask( stageTask );
231         repositoryTaskSchedulerControl.setVoidCallable();
232
233         repositoryTaskSchedulerControl.replay();
234
235         Configuration configuration = createConfigurationForEditing( createRepository() );
236         archivaConfiguration.getConfiguration();
237         archivaConfigurationControl.setReturnValue( configuration );
238         archivaConfigurationControl.setReturnValue( configuration );
239         archivaConfigurationControl.setReturnValue( configuration );
240
241         archivaConfigurationControl.setReturnValue( configuration );
242         archivaConfigurationControl.setReturnValue( configuration );
243
244         Configuration stageRepoConfiguration = new Configuration();
245         stageRepoConfiguration.addManagedRepository( createStagingRepository() );
246         archivaConfigurationControl.setReturnValue( stageRepoConfiguration );
247         archivaConfigurationControl.setReturnValue( configuration );
248         archivaConfigurationControl.setReturnValue( configuration );
249
250         archivaConfiguration.save( configuration );
251         archivaConfiguration.save( configuration );
252
253         archivaConfiguration.save( configuration );
254
255         archivaConfigurationControl.replay();
256
257         action.setRepoid( REPO_ID );
258         action.prepare();
259         assertEquals( REPO_ID, action.getRepoid() );
260         ManagedRepository repository = action.getRepository();
261         populateRepository( repository );
262         repository.setName( "new repo name" );
263
264         MockControl repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class );
265         RepositoryStatisticsManager repositoryStatisticsManager =
266             (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock();
267         ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositoryStatisticsManager(
268             repositoryStatisticsManager );
269         // no deletion
270         repositoryStatisticsManagerControl.replay();
271
272         new File( "target/test/" + REPO_ID + "-stage" ).mkdirs();
273
274         action.setRepository( repository );
275         action.setStageNeeded( true );
276         String status = action.commit();
277         assertEquals( Action.SUCCESS, status );
278
279         ManagedRepository newRepository = createRepository();
280         newRepository.setName( "new repo name" );
281         assertRepositoryEquals( repository, newRepository );
282         //assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() );
283         //assertEquals( location.getCanonicalPath(), new File( repository.getLocation() ).getCanonicalPath() );
284
285         roleManagerControl.verify();
286         //archivaConfigurationControl.verify();
287         repositoryStatisticsManagerControl.verify();
288         registryControl.verify();
289     }
290
291     public void testEditRepositoryLocationChanged()
292         throws Exception
293     {
294         roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
295         roleManagerControl.setReturnValue( false );
296         roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
297         roleManagerControl.setVoidCallable();
298
299         roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
300         roleManagerControl.setReturnValue( false );
301         roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
302         roleManagerControl.setVoidCallable();
303
304         roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID + "-stage" );
305         roleManagerControl.setReturnValue( false );
306         roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID + "-stage" );
307         roleManagerControl.setVoidCallable();
308
309         roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID + "-stage" );
310         roleManagerControl.setReturnValue( false );
311         roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID + "-stage" );
312         roleManagerControl.setVoidCallable();
313
314         roleManagerControl.replay();
315
316         registry.getString( "appserver.base", "${appserver.base}" );
317         registryControl.setReturnValue( "target/test" );
318         registry.getString( "appserver.home", "${appserver.home}" );
319         registryControl.setReturnValue( "target/test" );
320
321         registry.getString( "appserver.base", "${appserver.base}" );
322         registryControl.setReturnValue( "target/test" );
323         registry.getString( "appserver.home", "${appserver.home}" );
324         registryControl.setReturnValue( "target/test" );
325
326         registryControl.replay();
327
328         RepositoryTask task = new RepositoryTask();
329         task.setRepositoryId( REPO_ID );
330         repositoryTaskScheduler.isProcessingRepositoryTask( REPO_ID );
331         repositoryTaskSchedulerControl.setReturnValue( false );
332         repositoryTaskScheduler.queueTask( task );
333         repositoryTaskSchedulerControl.setVoidCallable();
334
335         repositoryTaskSchedulerControl.replay();
336
337         Configuration configuration = createConfigurationForEditing( createRepository() );
338         archivaConfiguration.getConfiguration();
339         archivaConfigurationControl.setReturnValue( configuration );
340         archivaConfigurationControl.setReturnValue( configuration );
341         archivaConfigurationControl.setReturnValue( configuration );
342         archivaConfigurationControl.setReturnValue( configuration );
343
344         archivaConfigurationControl.setReturnValue( configuration );
345
346         archivaConfigurationControl.setReturnValue( buildEasyConfiguration() );
347
348         Configuration stageRepoConfiguration = buildEasyConfiguration();
349         stageRepoConfiguration.addManagedRepository( createStagingRepository() );
350         archivaConfigurationControl.setReturnValue( stageRepoConfiguration );
351
352         archivaConfigurationControl.setReturnValue( configuration );
353         archivaConfigurationControl.setReturnValue( configuration );
354
355         archivaConfiguration.save( configuration );
356         configuration.addManagedRepository( stageRepoConfiguration.getManagedRepositories().get( 0 ) );
357         archivaConfiguration.save( configuration );
358         archivaConfiguration.save( configuration );
359
360         archivaConfigurationControl.replay();
361
362         MockControl repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class );
363         RepositoryStatisticsManager repositoryStatisticsManager =
364             (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock();
365         ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositoryStatisticsManager(
366             repositoryStatisticsManager );
367         repositoryStatisticsManager.deleteStatistics( metadataRepository, REPO_ID );
368         repositoryStatisticsManagerControl.replay();
369
370         new File( "target/test/location/" + REPO_ID + "-stage" ).mkdirs();
371
372         action.setStageNeeded( true );
373         action.setRepoid( REPO_ID );
374         action.prepare();
375         assertEquals( REPO_ID, action.getRepoid() );
376
377         ManagedRepository repository = new ManagedRepository();
378         populateRepository( repository );
379         File testFile = new File( "target/test/location/new" );
380         FileUtils.deleteDirectory( testFile );
381         repository.setLocation( "${appserver.base}/location/new" );
382         action.setRepository( repository );
383         String status = action.commit();
384         assertEquals( Action.SUCCESS, status );
385         //assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() );
386         //assertEquals( testFile.getCanonicalPath(), new File( repository.getLocation() ).getCanonicalPath() );
387
388         roleManagerControl.verify();
389         //archivaConfigurationControl.verify();
390         repositoryStatisticsManagerControl.verify();
391         registryControl.verify();
392     }
393
394     public void testStruts2ValidationFrameworkWithNullInputs()
395         throws Exception
396     {
397         // prep
398         // 0 is the default value for primitive int; null for objects
399         ManagedRepository managedRepositoryConfiguration = createManagedRepository( null, null, null, null, 1, 1 );
400         action.setRepository( managedRepositoryConfiguration );
401
402         // test
403         actionValidatorManager.validate( action, EMPTY_STRING );
404
405         // verify
406         assertTrue( action.hasFieldErrors() );
407
408         Map<String, List<String>> fieldErrors = action.getFieldErrors();
409
410         // make an expected field error object
411         Map<String, List<String>> expectedFieldErrors = new HashMap<String, List<String>>();
412
413         // populate
414         List<String> expectedErrorMessages = new ArrayList<String>();
415         expectedErrorMessages.add( "You must enter a repository identifier." );
416         expectedFieldErrors.put( "repository.id", expectedErrorMessages );
417
418         expectedErrorMessages = new ArrayList<String>();
419         expectedErrorMessages.add( "You must enter a directory." );
420         expectedFieldErrors.put( "repository.location", expectedErrorMessages );
421
422         expectedErrorMessages = new ArrayList<String>();
423         expectedErrorMessages.add( "You must enter a repository name." );
424         expectedFieldErrors.put( "repository.name", expectedErrorMessages );
425
426         ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors );
427     }
428
429     public void testStruts2ValidationFrameworkWithBlankInputs()
430         throws Exception
431     {
432         // prep
433         // 0 is the default value for primitive int
434         ManagedRepository managedRepositoryConfiguration =
435             createManagedRepository( EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, 1, 1 );
436         action.setRepository( managedRepositoryConfiguration );
437
438         // test
439         actionValidatorManager.validate( action, EMPTY_STRING );
440
441         // verify
442         assertTrue( action.hasFieldErrors() );
443
444         Map<String, List<String>> fieldErrors = action.getFieldErrors();
445
446         // make an expected field error object
447         Map<String, List<String>> expectedFieldErrors = new HashMap<String, List<String>>();
448
449         // populate
450         List<String> expectedErrorMessages = new ArrayList<String>();
451         expectedErrorMessages.add( "You must enter a repository identifier." );
452         expectedFieldErrors.put( "repository.id", expectedErrorMessages );
453
454         expectedErrorMessages = new ArrayList<String>();
455         expectedErrorMessages.add( "You must enter a directory." );
456         expectedFieldErrors.put( "repository.location", expectedErrorMessages );
457
458         expectedErrorMessages = new ArrayList<String>();
459         expectedErrorMessages.add( "You must enter a repository name." );
460         expectedFieldErrors.put( "repository.name", expectedErrorMessages );
461
462         ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors );
463     }
464
465     public void testStruts2ValidationFrameworkWithInvalidInputs()
466         throws Exception
467     {
468         // prep
469         ManagedRepository managedRepositoryConfiguration =
470             createManagedRepository( REPOSITORY_ID_INVALID_INPUT, REPOSITORY_NAME_INVALID_INPUT,
471                                      REPOSITORY_LOCATION_INVALID_INPUT, REPOSITORY_INDEX_DIR_INVALID_INPUT,
472                                      REPOSITORY_DAYS_OLDER_INVALID_INPUT, REPOSITORY_RETENTION_COUNT_INVALID_INPUT );
473         action.setRepository( managedRepositoryConfiguration );
474
475         // test
476         actionValidatorManager.validate( action, EMPTY_STRING );
477
478         // verify
479         assertTrue( action.hasFieldErrors() );
480
481         Map<String, List<String>> fieldErrors = action.getFieldErrors();
482
483         // make an expected field error object
484         Map<String, List<String>> expectedFieldErrors = new HashMap<String, List<String>>();
485
486         // populate
487         List<String> expectedErrorMessages = new ArrayList<String>();
488         expectedErrorMessages.add(
489             "Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)." );
490         expectedFieldErrors.put( "repository.id", expectedErrorMessages );
491
492         expectedErrorMessages = new ArrayList<String>();
493         expectedErrorMessages.add(
494             "Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
495         expectedFieldErrors.put( "repository.location", expectedErrorMessages );
496
497         expectedErrorMessages = new ArrayList<String>();
498         expectedErrorMessages.add(
499             "Repository Name must only contain alphanumeric characters, white-spaces(' '), forward-slashes(/), open-parenthesis('('), close-parenthesis(')'),  underscores(_), dots(.), and dashes(-)." );
500         expectedFieldErrors.put( "repository.name", expectedErrorMessages );
501
502         expectedErrorMessages = new ArrayList<String>();
503         expectedErrorMessages.add(
504             "Index 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.indexDirectory", expectedErrorMessages );
506
507         expectedErrorMessages = new ArrayList<String>();
508         expectedErrorMessages.add( "Repository Purge By Retention Count needs to be between 1 and 100." );
509         expectedFieldErrors.put( "repository.retentionCount", expectedErrorMessages );
510
511         expectedErrorMessages = new ArrayList<String>();
512         expectedErrorMessages.add( "Repository Purge By Days Older Than needs to be larger than 0." );
513         expectedFieldErrors.put( "repository.daysOlder", expectedErrorMessages );
514
515         ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors );
516     }
517
518     public void testStruts2ValidationFrameworkWithValidInputs()
519         throws Exception
520     {
521         // prep
522         ManagedRepository managedRepositoryConfiguration =
523             createManagedRepository( REPOSITORY_ID_VALID_INPUT, REPOSITORY_NAME_VALID_INPUT,
524                                      REPOSITORY_LOCATION_VALID_INPUT, REPOSITORY_INDEX_DIR_VALID_INPUT,
525                                      REPOSITORY_DAYS_OLDER_VALID_INPUT, REPOSITORY_RETENTION_COUNT_VALID_INPUT );
526         action.setRepository( managedRepositoryConfiguration );
527
528         // test
529         actionValidatorManager.validate( action, EMPTY_STRING );
530
531         // verify
532         assertFalse( action.hasFieldErrors() );
533     }
534
535     private void assertRepositoryEquals( ManagedRepository expectedRepository, ManagedRepository actualRepository )
536     {
537         assertEquals( expectedRepository.getDaysOlder(), actualRepository.getDaysOlder() );
538         assertEquals( expectedRepository.getId(), actualRepository.getId() );
539         assertEquals( expectedRepository.getIndexDirectory(), actualRepository.getIndexDirectory() );
540         assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() );
541         assertEquals( expectedRepository.getName(), actualRepository.getName() );
542         assertEquals( expectedRepository.getCronExpression(), actualRepository.getCronExpression() );
543         assertEquals( expectedRepository.getRetentionCount(), actualRepository.getRetentionCount() );
544         assertEquals( expectedRepository.isDeleteReleasedSnapshots(), actualRepository.isDeleteReleasedSnapshots() );
545         assertEquals( expectedRepository.isScanned(), actualRepository.isScanned() );
546         assertEquals( expectedRepository.isReleases(), actualRepository.isReleases() );
547         assertEquals( expectedRepository.isSnapshots(), actualRepository.isSnapshots() );
548     }
549
550     private Configuration createConfigurationForEditing( ManagedRepository repositoryConfiguration )
551         throws Exception
552     {
553         Configuration configuration = buildEasyConfiguration();
554
555         ManagedRepositoryConfiguration managedRepositoryConfiguration = new ManagedRepositoryConfiguration();
556
557         managedRepositoryConfiguration.setDaysOlder( repositoryConfiguration.getDaysOlder() );
558         managedRepositoryConfiguration.setIndexDir( repositoryConfiguration.getIndexDirectory() );
559         managedRepositoryConfiguration.setRetentionCount( repositoryConfiguration.getRetentionCount() );
560         managedRepositoryConfiguration.setBlockRedeployments( repositoryConfiguration.isBlockRedeployments() );
561         managedRepositoryConfiguration.setDeleteReleasedSnapshots(
562             repositoryConfiguration.isDeleteReleasedSnapshots() );
563         managedRepositoryConfiguration.setLocation( repositoryConfiguration.getLocation() );
564         managedRepositoryConfiguration.setRefreshCronExpression( repositoryConfiguration.getCronExpression() );
565         managedRepositoryConfiguration.setReleases( repositoryConfiguration.isReleases() );
566         managedRepositoryConfiguration.setScanned( repositoryConfiguration.isScanned() );
567         managedRepositoryConfiguration.setId( repositoryConfiguration.getId() );
568         managedRepositoryConfiguration.setName( repositoryConfiguration.getName() );
569         managedRepositoryConfiguration.setLayout( repositoryConfiguration.getLayout() );
570
571         configuration.addManagedRepository( managedRepositoryConfiguration );
572         return configuration;
573     }
574
575     // easy configuration for hashCode/equals
576     private Configuration buildEasyConfiguration()
577     {
578         return new Configuration()
579         {
580             @Override
581             public int hashCode()
582             {
583                 return getManagedRepositories().size();
584             }
585
586             @Override
587             public boolean equals( Object o )
588             {
589                 return true;
590             }
591         };
592     }
593
594     private ManagedRepository createRepository()
595         throws IOException
596     {
597         ManagedRepository r = new ManagedRepository();
598         r.setId( REPO_ID );
599         populateRepository( r );
600         return r;
601     }
602
603     private ManagedRepositoryConfiguration createStagingRepository()
604         throws IOException
605     {
606         ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration();
607         r.setId( REPO_ID + "-stage" );
608         populateStagingRepository( r );
609         return r;
610     }
611
612     private void populateStagingRepository( ManagedRepositoryConfiguration repository )
613         throws IOException
614     {
615         repository.setId( REPO_ID + "-stage" );
616         repository.setName( "repo name" );
617         repository.setLocation( "${appserver.base}/location" );
618         repository.setLayout( "default" );
619         repository.setRefreshCronExpression( "* 0/5 * * * ?" );
620         repository.setDaysOlder( 31 );
621         repository.setRetentionCount( 20 );
622         repository.setReleases( true );
623         repository.setSnapshots( true );
624         repository.setScanned( false );
625         repository.setDeleteReleasedSnapshots( true );
626     }
627 }