]> source.dussan.org Git - archiva.git/blob
2dcb8f7d8302527b95a21b029925fe9feb8c6673
[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( "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", "${appserver.base}" );
312         registryControl.setReturnValue( "target/test", 1, 3 );
313         registry.getString( "appserver.home", "${appserver.home}" );
314         registryControl.setReturnValue( "target/test", 1, 3 );
315
316         registryControl.replay();
317
318         RepositoryTask task = new RepositoryTask();
319         task.setRepositoryId( REPO_ID );
320         repositoryTaskScheduler.isProcessingRepositoryTask( REPO_ID );
321         repositoryTaskSchedulerControl.setReturnValue( false );
322         repositoryTaskScheduler.queueTask( task );
323         repositoryTaskSchedulerControl.setVoidCallable();
324
325         repositoryTaskSchedulerControl.replay();
326
327         Configuration configuration = createConfigurationForEditing( createRepository() );
328         archivaConfiguration.getConfiguration();
329         archivaConfigurationControl.setReturnValue( configuration );
330         archivaConfigurationControl.setReturnValue( configuration );
331         archivaConfigurationControl.setReturnValue( configuration );
332         archivaConfigurationControl.setReturnValue( configuration );
333
334         archivaConfigurationControl.setReturnValue( configuration );
335
336         archivaConfigurationControl.setReturnValue( buildEasyConfiguration() );
337
338         Configuration stageRepoConfiguration = buildEasyConfiguration();
339         stageRepoConfiguration.addManagedRepository( createStagingRepository() );
340         archivaConfigurationControl.setReturnValue( stageRepoConfiguration );
341
342         archivaConfigurationControl.setReturnValue( configuration );
343         archivaConfigurationControl.setReturnValue( configuration );
344
345         archivaConfiguration.save( configuration );
346         configuration.addManagedRepository( stageRepoConfiguration.getManagedRepositories().get( 0 ) );
347         archivaConfiguration.save( configuration );
348         archivaConfiguration.save( configuration );
349
350         archivaConfigurationControl.replay();
351
352         MockControl repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class );
353         RepositoryStatisticsManager repositoryStatisticsManager =
354             (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock();
355         ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositoryStatisticsManager(
356             repositoryStatisticsManager );
357         repositoryStatisticsManager.deleteStatistics( metadataRepository, REPO_ID );
358         repositoryStatisticsManagerControl.replay();
359
360         new File( "target/test/location/" + REPO_ID + "-stage" ).mkdirs();
361
362         action.setStageNeeded( true );
363         action.setRepoid( REPO_ID );
364         action.prepare();
365         assertEquals( REPO_ID, action.getRepoid() );
366
367         ManagedRepository repository = new ManagedRepository();
368         populateRepository( repository );
369         File testFile = new File( "target/test/location/new" );
370         FileUtils.deleteDirectory( testFile );
371         repository.setLocation( "${appserver.base}/location/new" );
372         action.setRepository( repository );
373         String status = action.commit();
374         assertEquals( Action.SUCCESS, status );
375         //assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() );
376         //assertEquals( testFile.getCanonicalPath(), new File( repository.getLocation() ).getCanonicalPath() );
377
378         roleManagerControl.verify();
379         //archivaConfigurationControl.verify();
380         repositoryStatisticsManagerControl.verify();
381         registryControl.verify();
382     }
383
384     public void testStruts2ValidationFrameworkWithNullInputs()
385         throws Exception
386     {
387         // prep
388         // 0 is the default value for primitive int; null for objects
389         ManagedRepository managedRepositoryConfiguration = createManagedRepository( null, null, null, null, 1, 1 );
390         action.setRepository( managedRepositoryConfiguration );
391
392         // test
393         actionValidatorManager.validate( action, EMPTY_STRING );
394
395         // verify
396         assertTrue( action.hasFieldErrors() );
397
398         Map<String, List<String>> fieldErrors = action.getFieldErrors();
399
400         // make an expected field error object
401         Map<String, List<String>> expectedFieldErrors = new HashMap<String, List<String>>();
402
403         // populate
404         List<String> expectedErrorMessages = new ArrayList<String>();
405         expectedErrorMessages.add( "You must enter a repository identifier." );
406         expectedFieldErrors.put( "repository.id", expectedErrorMessages );
407
408         expectedErrorMessages = new ArrayList<String>();
409         expectedErrorMessages.add( "You must enter a directory." );
410         expectedFieldErrors.put( "repository.location", expectedErrorMessages );
411
412         expectedErrorMessages = new ArrayList<String>();
413         expectedErrorMessages.add( "You must enter a repository name." );
414         expectedFieldErrors.put( "repository.name", expectedErrorMessages );
415
416         ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors );
417     }
418
419     public void testStruts2ValidationFrameworkWithBlankInputs()
420         throws Exception
421     {
422         // prep
423         // 0 is the default value for primitive int
424         ManagedRepository managedRepositoryConfiguration =
425             createManagedRepository( EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, 1, 1 );
426         action.setRepository( managedRepositoryConfiguration );
427
428         // test
429         actionValidatorManager.validate( action, EMPTY_STRING );
430
431         // verify
432         assertTrue( action.hasFieldErrors() );
433
434         Map<String, List<String>> fieldErrors = action.getFieldErrors();
435
436         // make an expected field error object
437         Map<String, List<String>> expectedFieldErrors = new HashMap<String, List<String>>();
438
439         // populate
440         List<String> expectedErrorMessages = new ArrayList<String>();
441         expectedErrorMessages.add( "You must enter a repository identifier." );
442         expectedFieldErrors.put( "repository.id", expectedErrorMessages );
443
444         expectedErrorMessages = new ArrayList<String>();
445         expectedErrorMessages.add( "You must enter a directory." );
446         expectedFieldErrors.put( "repository.location", expectedErrorMessages );
447
448         expectedErrorMessages = new ArrayList<String>();
449         expectedErrorMessages.add( "You must enter a repository name." );
450         expectedFieldErrors.put( "repository.name", expectedErrorMessages );
451
452         ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors );
453     }
454
455     public void testStruts2ValidationFrameworkWithInvalidInputs()
456         throws Exception
457     {
458         // prep
459         ManagedRepository managedRepositoryConfiguration =
460             createManagedRepository( REPOSITORY_ID_INVALID_INPUT, REPOSITORY_NAME_INVALID_INPUT,
461                                      REPOSITORY_LOCATION_INVALID_INPUT, REPOSITORY_INDEX_DIR_INVALID_INPUT,
462                                      REPOSITORY_DAYS_OLDER_INVALID_INPUT, REPOSITORY_RETENTION_COUNT_INVALID_INPUT );
463         action.setRepository( managedRepositoryConfiguration );
464
465         // test
466         actionValidatorManager.validate( action, EMPTY_STRING );
467
468         // verify
469         assertTrue( action.hasFieldErrors() );
470
471         Map<String, List<String>> fieldErrors = action.getFieldErrors();
472
473         // make an expected field error object
474         Map<String, List<String>> expectedFieldErrors = new HashMap<String, List<String>>();
475
476         // populate
477         List<String> expectedErrorMessages = new ArrayList<String>();
478         expectedErrorMessages.add(
479             "Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)." );
480         expectedFieldErrors.put( "repository.id", expectedErrorMessages );
481
482         expectedErrorMessages = new ArrayList<String>();
483         expectedErrorMessages.add(
484             "Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
485         expectedFieldErrors.put( "repository.location", expectedErrorMessages );
486
487         expectedErrorMessages = new ArrayList<String>();
488         expectedErrorMessages.add(
489             "Repository Name must only contain alphanumeric characters, white-spaces(' '), forward-slashes(/), open-parenthesis('('), close-parenthesis(')'),  underscores(_), dots(.), and dashes(-)." );
490         expectedFieldErrors.put( "repository.name", expectedErrorMessages );
491
492         expectedErrorMessages = new ArrayList<String>();
493         expectedErrorMessages.add(
494             "Index 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.indexDirectory", expectedErrorMessages );
496
497         expectedErrorMessages = new ArrayList<String>();
498         expectedErrorMessages.add( "Repository Purge By Retention Count needs to be between 1 and 100." );
499         expectedFieldErrors.put( "repository.retentionCount", expectedErrorMessages );
500
501         expectedErrorMessages = new ArrayList<String>();
502         expectedErrorMessages.add( "Repository Purge By Days Older Than needs to be larger than 0." );
503         expectedFieldErrors.put( "repository.daysOlder", expectedErrorMessages );
504
505         ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors );
506     }
507
508     public void testStruts2ValidationFrameworkWithValidInputs()
509         throws Exception
510     {
511         // prep
512         ManagedRepository managedRepositoryConfiguration =
513             createManagedRepository( REPOSITORY_ID_VALID_INPUT, REPOSITORY_NAME_VALID_INPUT,
514                                      REPOSITORY_LOCATION_VALID_INPUT, REPOSITORY_INDEX_DIR_VALID_INPUT,
515                                      REPOSITORY_DAYS_OLDER_VALID_INPUT, REPOSITORY_RETENTION_COUNT_VALID_INPUT );
516         action.setRepository( managedRepositoryConfiguration );
517
518         // test
519         actionValidatorManager.validate( action, EMPTY_STRING );
520
521         // verify
522         assertFalse( action.hasFieldErrors() );
523     }
524
525     private void assertRepositoryEquals( ManagedRepository expectedRepository, ManagedRepository actualRepository )
526     {
527         assertEquals( expectedRepository.getDaysOlder(), actualRepository.getDaysOlder() );
528         assertEquals( expectedRepository.getId(), actualRepository.getId() );
529         assertEquals( expectedRepository.getIndexDirectory(), actualRepository.getIndexDirectory() );
530         assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() );
531         assertEquals( expectedRepository.getName(), actualRepository.getName() );
532         assertEquals( expectedRepository.getCronExpression(), actualRepository.getCronExpression() );
533         assertEquals( expectedRepository.getRetentionCount(), actualRepository.getRetentionCount() );
534         assertEquals( expectedRepository.isDeleteReleasedSnapshots(), actualRepository.isDeleteReleasedSnapshots() );
535         assertEquals( expectedRepository.isScanned(), actualRepository.isScanned() );
536         assertEquals( expectedRepository.isReleases(), actualRepository.isReleases() );
537         assertEquals( expectedRepository.isSnapshots(), actualRepository.isSnapshots() );
538     }
539
540     private Configuration createConfigurationForEditing( ManagedRepository repositoryConfiguration )
541         throws Exception
542     {
543         Configuration configuration = buildEasyConfiguration();
544
545         ManagedRepositoryConfiguration managedRepositoryConfiguration = new ManagedRepositoryConfiguration();
546
547         managedRepositoryConfiguration.setDaysOlder( repositoryConfiguration.getDaysOlder() );
548         managedRepositoryConfiguration.setIndexDir( repositoryConfiguration.getIndexDirectory() );
549         managedRepositoryConfiguration.setRetentionCount( repositoryConfiguration.getRetentionCount() );
550         managedRepositoryConfiguration.setBlockRedeployments( repositoryConfiguration.isBlockRedeployments() );
551         managedRepositoryConfiguration.setDeleteReleasedSnapshots(
552             repositoryConfiguration.isDeleteReleasedSnapshots() );
553         managedRepositoryConfiguration.setLocation( repositoryConfiguration.getLocation() );
554         managedRepositoryConfiguration.setRefreshCronExpression( repositoryConfiguration.getCronExpression() );
555         managedRepositoryConfiguration.setReleases( repositoryConfiguration.isReleases() );
556         managedRepositoryConfiguration.setScanned( repositoryConfiguration.isScanned() );
557         managedRepositoryConfiguration.setId( repositoryConfiguration.getId() );
558         managedRepositoryConfiguration.setName( repositoryConfiguration.getName() );
559         managedRepositoryConfiguration.setLayout( repositoryConfiguration.getLayout() );
560
561         configuration.addManagedRepository( managedRepositoryConfiguration );
562         return configuration;
563     }
564
565     // easy configuration for hashCode/equals
566     private Configuration buildEasyConfiguration()
567     {
568         return new Configuration()
569         {
570             @Override
571             public int hashCode()
572             {
573                 return getManagedRepositories().size();
574             }
575
576             @Override
577             public boolean equals( Object o )
578             {
579                 return true;
580             }
581         };
582     }
583
584     private ManagedRepository createRepository()
585         throws IOException
586     {
587         ManagedRepository r = new ManagedRepository();
588         r.setId( REPO_ID );
589         populateRepository( r );
590         return r;
591     }
592
593     private ManagedRepositoryConfiguration createStagingRepository()
594         throws IOException
595     {
596         ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration();
597         r.setId( REPO_ID + "-stage" );
598         populateStagingRepository( r );
599         return r;
600     }
601
602     private void populateStagingRepository( ManagedRepositoryConfiguration repository )
603         throws IOException
604     {
605         repository.setId( REPO_ID + "-stage" );
606         repository.setName( "repo name" );
607         repository.setLocation( "${appserver.base}/location" );
608         repository.setLayout( "default" );
609         repository.setRefreshCronExpression( "* 0/5 * * * ?" );
610         repository.setDaysOlder( 31 );
611         repository.setRetentionCount( 20 );
612         repository.setReleases( true );
613         repository.setSnapshots( true );
614         repository.setScanned( false );
615         repository.setDeleteReleasedSnapshots( true );
616     }
617 }