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