1 package org.apache.archiva.web.action.admin.repositories;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import com.opensymphony.xwork2.validator.ActionValidatorManager;
23 import org.apache.archiva.admin.model.beans.ManagedRepository;
24 import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
25 import org.apache.struts2.StrutsSpringTestCase;
28 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
29 import org.junit.Before;
30 import org.junit.runner.RunWith;
31 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
32 public abstract class AbstractManagedRepositoryActionTest
33 extends StrutsSpringTestCase
35 protected static final String EMPTY_STRING = "";
37 // valid inputs; validation testing
38 protected static final String REPOSITORY_ID_VALID_INPUT = "abcXYZ0129._-";
40 protected static final String REPOSITORY_LOCATION_VALID_INPUT = "abcXYZ0129._/\\~:?!&=-";
42 protected static final String REPOSITORY_INDEX_DIR_VALID_INPUT = "abcXYZ0129._/\\~:?!&=-";
44 protected static final String REPOSITORY_NAME_VALID_INPUT = "abcXYZ 0129.)/ _(-";
46 protected static final int REPOSITORY_RETENTION_COUNT_VALID_INPUT = 1;
48 protected static final int REPOSITORY_DAYS_OLDER_VALID_INPUT = 1;
50 // invalid inputs; validation testing
51 protected static final String REPOSITORY_ID_INVALID_INPUT = "<> \\/~+[ ]'\"";
53 protected static final String REPOSITORY_LOCATION_INVALID_INPUT = "<> ~+[ ]'\"";
55 protected static final String REPOSITORY_INDEX_DIR_INVALID_INPUT = "<> ~+[ ]'\"";
57 protected static final String REPOSITORY_NAME_INVALID_INPUT = "<>\\~+[]'\"";
59 protected static final int REPOSITORY_RETENTION_COUNT_INVALID_INPUT = 101;
61 protected static final int REPOSITORY_DAYS_OLDER_INVALID_INPUT = -1;
63 // testing requisite; validation testing
64 protected ActionValidatorManager actionValidatorManager;
66 protected static final String REPO_ID = "repo-ident";
68 protected File location;
71 protected String[] getContextLocations()
73 return new String[]{ "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" };
83 DefaultActionValidatorManagerFactory defaultActionValidatorManagerFactory =
84 new DefaultActionValidatorManagerFactory();
86 actionValidatorManager = defaultActionValidatorManagerFactory.createDefaultActionValidatorManager();
89 protected void populateRepository( ManagedRepository repository )
91 repository.setId( REPO_ID );
92 repository.setName( "repo name" );
93 repository.setLocation( location.getAbsolutePath() );
94 repository.setLayout( "default" );
95 repository.setCronExpression( "* 0/5 * * * ?" );
96 repository.setDaysOlder( 31 );
97 repository.setRetentionCount( 20 );
98 repository.setReleases( true );
99 repository.setSnapshots( false );
100 repository.setScanned( false );
101 repository.setDeleteReleasedSnapshots( true );
104 protected ManagedRepository createManagedRepository( String id, String name, String location )
106 ManagedRepository managedRepositoryConfiguration = new ManagedRepository();
108 managedRepositoryConfiguration.setId( id );
109 managedRepositoryConfiguration.setName( name );
110 managedRepositoryConfiguration.setLocation( location );
112 return managedRepositoryConfiguration;
116 // for simulating empty/null form purposes; excluding primitive data-typed values
117 protected ManagedRepository createManagedRepository( String id, String name, String location,
120 ManagedRepository managedRepositoryConfiguration = new ManagedRepository();
122 managedRepositoryConfiguration.setId( id );
123 managedRepositoryConfiguration.setName( name );
124 managedRepositoryConfiguration.setLocation( location );
125 managedRepositoryConfiguration.setIndexDirectory( indexDir );
127 return managedRepositoryConfiguration;
130 protected ManagedRepository createManagedRepository( String id, String name, String location, String indexDir,
131 int daysOlder, int retentionCount )
133 ManagedRepository managedRepositoryConfiguration = new ManagedRepository();
135 managedRepositoryConfiguration.setId( id );
136 managedRepositoryConfiguration.setName( name );
137 managedRepositoryConfiguration.setLocation( location );
138 managedRepositoryConfiguration.setIndexDirectory( indexDir );
139 managedRepositoryConfiguration.setDaysOlder( daysOlder );
140 managedRepositoryConfiguration.setRetentionCount( retentionCount );
142 return managedRepositoryConfiguration;
146 protected ManagedRepositoryAdmin getManagedRepositoryAdmin()
148 return applicationContext.getBean( ManagedRepositoryAdmin.class );