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.Action;
23 import org.apache.archiva.configuration.ArchivaConfiguration;
24 import org.apache.archiva.configuration.Configuration;
25 import org.apache.archiva.configuration.RepositoryGroupConfiguration;
26 import org.apache.struts2.StrutsSpringTestCase;
27 import org.apache.archiva.redback.integration.interceptor.SecureActionBundle;
28 import org.apache.archiva.redback.integration.interceptor.SecureActionException;
29 import org.easymock.MockControl;
31 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
32 import org.junit.After;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
37 * SortRepositoriesActionTest
39 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
40 public class SortRepositoriesActionTest
41 extends StrutsSpringTestCase
43 private static final String REPO_GROUP_ID = "repo-group-ident";
45 private static final String REPO1_ID = "managed-repo-ident-1";
47 private static final String REPO2_ID = "managed-repo-ident-2";
49 private static final String REPO3_ID = "managed-repo-ident-3";
51 private MockControl archivaConfigurationControl;
53 private ArchivaConfiguration archivaConfiguration;
55 private ArchivaConfiguration originalArchivaConfiguration;
57 private SortRepositoriesAction action;
60 protected String[] getContextLocations()
62 return new String[]{ "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" };
71 action = (SortRepositoriesAction) getActionProxy( "/admin/sortDownRepositoryFromGroup.action" ).getAction();
72 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
73 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
74 originalArchivaConfiguration = action.archivaConfiguration;
75 action.setArchivaConfiguration( archivaConfiguration );
80 public void tearDown()
84 action.archivaConfiguration = originalArchivaConfiguration;
88 public void testSecureActionBundle()
89 throws SecureActionException
91 archivaConfiguration.getConfiguration();
92 archivaConfigurationControl.setReturnValue( new Configuration() );
93 archivaConfigurationControl.replay();
95 SecureActionBundle bundle = action.getSecureActionBundle();
96 assertTrue( bundle.requiresAuthentication() );
97 assertEquals( 1, bundle.getAuthorizationTuples().size() );
101 public void testSortDownFirstRepository()
104 Configuration configuration = createInitialConfiguration();
106 archivaConfiguration.getConfiguration();
107 archivaConfigurationControl.setReturnValue( configuration, 4 );
108 archivaConfiguration.save( configuration );
109 archivaConfigurationControl.replay();
111 RepositoryGroupConfiguration repoGroup =
112 (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
113 java.util.List<String> repositories = repoGroup.getRepositories();
115 assertEquals( 3, repositories.size() );
116 assertEquals( REPO1_ID, repositories.get( 0 ) );
117 assertEquals( REPO2_ID, repositories.get( 1 ) );
118 assertEquals( REPO3_ID, repositories.get( 2 ) );
120 // sort down first repo
121 action.setRepoGroupId( repoGroup.getId() );
122 action.setTargetRepo( REPO1_ID );
124 String result = action.sortDown();
125 assertEquals( Action.SUCCESS, result );
127 repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
128 repositories = repoGroup.getRepositories();
129 assertEquals( 3, repositories.size() );
130 assertEquals( REPO2_ID, repositories.get( 0 ) );
131 assertEquals( REPO1_ID, repositories.get( 1 ) );
132 assertEquals( REPO3_ID, repositories.get( 2 ) );
136 public void testSortDownLastRepository()
139 Configuration configuration = createInitialConfiguration();
141 archivaConfiguration.getConfiguration();
142 archivaConfigurationControl.setReturnValue( configuration, 4 );
143 archivaConfiguration.save( configuration );
144 archivaConfigurationControl.replay();
146 RepositoryGroupConfiguration repoGroup =
147 (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
148 java.util.List<String> repositories = repoGroup.getRepositories();
150 assertEquals( 3, repositories.size() );
151 assertEquals( REPO1_ID, repositories.get( 0 ) );
152 assertEquals( REPO2_ID, repositories.get( 1 ) );
153 assertEquals( REPO3_ID, repositories.get( 2 ) );
155 // sort down last repo
156 action.setRepoGroupId( repoGroup.getId() );
157 action.setTargetRepo( REPO3_ID );
159 String result = action.sortDown();
160 assertEquals( Action.SUCCESS, result );
162 repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
163 repositories = repoGroup.getRepositories();
164 assertEquals( 3, repositories.size() );
165 assertEquals( REPO1_ID, repositories.get( 0 ) );
166 assertEquals( REPO2_ID, repositories.get( 1 ) );
167 assertEquals( REPO3_ID, repositories.get( 2 ) );
171 public void testSortUpLastRepository()
174 Configuration configuration = createInitialConfiguration();
176 archivaConfiguration.getConfiguration();
177 archivaConfigurationControl.setReturnValue( configuration, 4 );
178 archivaConfiguration.save( configuration );
179 archivaConfigurationControl.replay();
181 RepositoryGroupConfiguration repoGroup =
182 (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
183 java.util.List<String> repositories = repoGroup.getRepositories();
185 assertEquals( 3, repositories.size() );
186 assertEquals( REPO1_ID, repositories.get( 0 ) );
187 assertEquals( REPO2_ID, repositories.get( 1 ) );
188 assertEquals( REPO3_ID, repositories.get( 2 ) );
191 action.setRepoGroupId( repoGroup.getId() );
192 action.setTargetRepo( REPO3_ID );
194 String result = action.sortUp();
195 assertEquals( Action.SUCCESS, result );
197 repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
198 repositories = repoGroup.getRepositories();
199 assertEquals( 3, repositories.size() );
200 assertEquals( REPO1_ID, repositories.get( 0 ) );
201 assertEquals( REPO3_ID, repositories.get( 1 ) );
202 assertEquals( REPO2_ID, repositories.get( 2 ) );
206 public void testSortUpFirstRepository()
209 Configuration configuration = createInitialConfiguration();
211 archivaConfiguration.getConfiguration();
212 archivaConfigurationControl.setReturnValue( configuration, 4 );
213 archivaConfiguration.save( configuration );
214 archivaConfigurationControl.replay();
216 RepositoryGroupConfiguration repoGroup =
217 (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
218 java.util.List<String> repositories = repoGroup.getRepositories();
220 assertEquals( 3, repositories.size() );
221 assertEquals( REPO1_ID, repositories.get( 0 ) );
222 assertEquals( REPO2_ID, repositories.get( 1 ) );
223 assertEquals( REPO3_ID, repositories.get( 2 ) );
225 // sort up first repo
226 action.setRepoGroupId( repoGroup.getId() );
227 action.setTargetRepo( REPO1_ID );
229 String result = action.sortUp();
230 assertEquals( Action.SUCCESS, result );
232 repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
233 repositories = repoGroup.getRepositories();
234 assertEquals( 3, repositories.size() );
235 assertEquals( REPO1_ID, repositories.get( 0 ) );
236 assertEquals( REPO2_ID, repositories.get( 1 ) );
237 assertEquals( REPO3_ID, repositories.get( 2 ) );
240 private Configuration createInitialConfiguration()
242 Configuration config = new Configuration();
244 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
245 repoGroup.setId( REPO_GROUP_ID );
246 repoGroup.addRepository( REPO1_ID );
247 repoGroup.addRepository( REPO2_ID );
248 repoGroup.addRepository( REPO3_ID );
250 config.addRepositoryGroup( repoGroup );