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.ArchivaBlockJUnit4ClassRunner;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
33 public abstract class AbstractManagedRepositoryActionTest
34 extends StrutsSpringTestCase
36 protected static final String EMPTY_STRING = "";
38 // valid inputs; validation testing
39 protected static final String REPOSITORY_ID_VALID_INPUT = "abcXYZ0129._-";
41 protected static final String REPOSITORY_LOCATION_VALID_INPUT = "abcXYZ0129._/\\~:?!&=-";
43 protected static final String REPOSITORY_INDEX_DIR_VALID_INPUT = "abcXYZ0129._/\\~:?!&=-";
45 protected static final String REPOSITORY_NAME_VALID_INPUT = "abcXYZ 0129.)/ _(-";
47 protected static final int REPOSITORY_RETENTION_COUNT_VALID_INPUT = 1;
49 protected static final int REPOSITORY_DAYS_OLDER_VALID_INPUT = 1;
51 // invalid inputs; validation testing
52 protected static final String REPOSITORY_ID_INVALID_INPUT = "<> \\/~+[ ]'\"";
54 protected static final String REPOSITORY_LOCATION_INVALID_INPUT = "<> ~+[ ]'\"";
56 protected static final String REPOSITORY_INDEX_DIR_INVALID_INPUT = "<> ~+[ ]'\"";
58 protected static final String REPOSITORY_NAME_INVALID_INPUT = "<>\\~+[]'\"";
60 protected static final int REPOSITORY_RETENTION_COUNT_INVALID_INPUT = 101;
62 protected static final int REPOSITORY_DAYS_OLDER_INVALID_INPUT = -1;
64 // testing requisite; validation testing
65 protected ActionValidatorManager actionValidatorManager;
67 protected static final String REPO_ID = "repo-ident";
69 protected File location;
72 protected String[] getContextLocations()
74 return new String[]{ "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" };
84 DefaultActionValidatorManagerFactory defaultActionValidatorManagerFactory =
85 new DefaultActionValidatorManagerFactory();
87 actionValidatorManager = defaultActionValidatorManagerFactory.createDefaultActionValidatorManager();
90 protected void populateRepository( ManagedRepository repository )
92 repository.setId( REPO_ID );
93 repository.setName( "repo name" );
94 repository.setLocation( location.getAbsolutePath() );
95 repository.setLayout( "default" );
96 repository.setCronExpression( "* 0/5 * * * ?" );
97 repository.setDaysOlder( 31 );
98 repository.setRetentionCount( 20 );
99 repository.setReleases( true );
100 repository.setSnapshots( false );
101 repository.setScanned( false );
102 repository.setDeleteReleasedSnapshots( true );
105 protected ManagedRepository createManagedRepository( String id, String name, String location )
107 ManagedRepository managedRepositoryConfiguration = new ManagedRepository();
109 managedRepositoryConfiguration.setId( id );
110 managedRepositoryConfiguration.setName( name );
111 managedRepositoryConfiguration.setLocation( location );
113 return managedRepositoryConfiguration;
117 // for simulating empty/null form purposes; excluding primitive data-typed values
118 protected ManagedRepository createManagedRepository( String id, String name, String location,
121 ManagedRepository managedRepositoryConfiguration = new ManagedRepository();
123 managedRepositoryConfiguration.setId( id );
124 managedRepositoryConfiguration.setName( name );
125 managedRepositoryConfiguration.setLocation( location );
126 managedRepositoryConfiguration.setIndexDirectory( indexDir );
128 return managedRepositoryConfiguration;
131 protected ManagedRepository createManagedRepository( String id, String name, String location, String indexDir,
132 int daysOlder, int retentionCount )
134 ManagedRepository managedRepositoryConfiguration = new ManagedRepository();
136 managedRepositoryConfiguration.setId( id );
137 managedRepositoryConfiguration.setName( name );
138 managedRepositoryConfiguration.setLocation( location );
139 managedRepositoryConfiguration.setIndexDirectory( indexDir );
140 managedRepositoryConfiguration.setDaysOlder( daysOlder );
141 managedRepositoryConfiguration.setRetentionCount( retentionCount );
143 return managedRepositoryConfiguration;
147 protected ManagedRepositoryAdmin getManagedRepositoryAdmin()
149 return applicationContext.getBean( ManagedRepositoryAdmin.class );