1 package org.apache.maven.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.repository.managed.ManagedRepository;
24 import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin;
25 import org.apache.struts2.StrutsSpringTestCase;
29 public abstract class AbstractManagedRepositoryActionTest
30 extends StrutsSpringTestCase
32 protected static final String EMPTY_STRING = "";
34 // valid inputs; validation testing
35 protected static final String REPOSITORY_ID_VALID_INPUT = "abcXYZ0129._-";
37 protected static final String REPOSITORY_LOCATION_VALID_INPUT = "abcXYZ0129._/\\~:?!&=-";
39 protected static final String REPOSITORY_INDEX_DIR_VALID_INPUT = "abcXYZ0129._/\\~:?!&=-";
41 protected static final String REPOSITORY_NAME_VALID_INPUT = "abcXYZ 0129.)/ _(-";
43 protected static final int REPOSITORY_RETENTION_COUNT_VALID_INPUT = 1;
45 protected static final int REPOSITORY_DAYS_OLDER_VALID_INPUT = 1;
47 // invalid inputs; validation testing
48 protected static final String REPOSITORY_ID_INVALID_INPUT = "<> \\/~+[ ]'\"";
50 protected static final String REPOSITORY_LOCATION_INVALID_INPUT = "<> ~+[ ]'\"";
52 protected static final String REPOSITORY_INDEX_DIR_INVALID_INPUT = "<> ~+[ ]'\"";
54 protected static final String REPOSITORY_NAME_INVALID_INPUT = "<>\\~+[]'\"";
56 protected static final int REPOSITORY_RETENTION_COUNT_INVALID_INPUT = 101;
58 protected static final int REPOSITORY_DAYS_OLDER_INVALID_INPUT = -1;
60 // testing requisite; validation testing
61 protected ActionValidatorManager actionValidatorManager;
63 protected static final String REPO_ID = "repo-ident";
65 protected File location;
68 protected String[] getContextLocations()
70 return new String[]{ "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" };
74 protected void setUp()
79 DefaultActionValidatorManagerFactory defaultActionValidatorManagerFactory =
80 new DefaultActionValidatorManagerFactory();
82 actionValidatorManager = defaultActionValidatorManagerFactory.createDefaultActionValidatorManager();
85 protected void populateRepository( ManagedRepository repository )
87 repository.setId( REPO_ID );
88 repository.setName( "repo name" );
89 repository.setLocation( location.getAbsolutePath() );
90 repository.setLayout( "default" );
91 repository.setCronExpression( "* 0/5 * * * ?" );
92 repository.setDaysOlder( 31 );
93 repository.setRetentionCount( 20 );
94 repository.setReleases( true );
95 repository.setSnapshots( false );
96 repository.setScanned( false );
97 repository.setDeleteReleasedSnapshots( true );
100 protected ManagedRepository createManagedRepository( String id, String name, String location )
102 ManagedRepository managedRepositoryConfiguration = new ManagedRepository();
104 managedRepositoryConfiguration.setId( id );
105 managedRepositoryConfiguration.setName( name );
106 managedRepositoryConfiguration.setLocation( location );
108 return managedRepositoryConfiguration;
112 // for simulating empty/null form purposes; excluding primitive data-typed values
113 protected ManagedRepository createManagedRepository( String id, String name, String location,
116 ManagedRepository managedRepositoryConfiguration = new ManagedRepository();
118 managedRepositoryConfiguration.setId( id );
119 managedRepositoryConfiguration.setName( name );
120 managedRepositoryConfiguration.setLocation( location );
121 managedRepositoryConfiguration.setIndexDirectory( indexDir );
123 return managedRepositoryConfiguration;
126 protected ManagedRepository createManagedRepository( String id, String name, String location, String indexDir,
127 int daysOlder, int retentionCount )
129 ManagedRepository managedRepositoryConfiguration = new ManagedRepository();
131 managedRepositoryConfiguration.setId( id );
132 managedRepositoryConfiguration.setName( name );
133 managedRepositoryConfiguration.setLocation( location );
134 managedRepositoryConfiguration.setIndexDirectory( indexDir );
135 managedRepositoryConfiguration.setDaysOlder( daysOlder );
136 managedRepositoryConfiguration.setRetentionCount( retentionCount );
138 return managedRepositoryConfiguration;
142 protected ManagedRepositoryAdmin getManagedRepositoryAdmin()
144 return applicationContext.getBean( ManagedRepositoryAdmin.class );