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