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