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;
32 * SortRepositoriesActionTest
34 public class SortRepositoriesActionTest
35 extends StrutsSpringTestCase
37 private static final String REPO_GROUP_ID = "repo-group-ident";
39 private static final String REPO1_ID = "managed-repo-ident-1";
41 private static final String REPO2_ID = "managed-repo-ident-2";
43 private static final String REPO3_ID = "managed-repo-ident-3";
45 private MockControl archivaConfigurationControl;
47 private ArchivaConfiguration archivaConfiguration;
49 private ArchivaConfiguration originalArchivaConfiguration;
51 private SortRepositoriesAction action;
54 protected String[] getContextLocations()
56 return new String[]{ "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" };
59 protected void setUp()
63 action = (SortRepositoriesAction) getActionProxy( "/admin/sortDownRepositoryFromGroup.action" ).getAction();
64 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
65 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
66 originalArchivaConfiguration = action.archivaConfiguration;
67 action.setArchivaConfiguration( archivaConfiguration );
71 protected void tearDown()
75 action.archivaConfiguration = originalArchivaConfiguration;
78 public void testSecureActionBundle()
79 throws SecureActionException
81 archivaConfiguration.getConfiguration();
82 archivaConfigurationControl.setReturnValue( new Configuration() );
83 archivaConfigurationControl.replay();
85 SecureActionBundle bundle = action.getSecureActionBundle();
86 assertTrue( bundle.requiresAuthentication() );
87 assertEquals( 1, bundle.getAuthorizationTuples().size() );
90 public void testSortDownFirstRepository()
93 Configuration configuration = createInitialConfiguration();
95 archivaConfiguration.getConfiguration();
96 archivaConfigurationControl.setReturnValue( configuration, 4 );
97 archivaConfiguration.save( configuration );
98 archivaConfigurationControl.replay();
100 RepositoryGroupConfiguration repoGroup =
101 (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
102 java.util.List<String> repositories = repoGroup.getRepositories();
104 assertEquals( 3, repositories.size() );
105 assertEquals( REPO1_ID, repositories.get( 0 ) );
106 assertEquals( REPO2_ID, repositories.get( 1 ) );
107 assertEquals( REPO3_ID, repositories.get( 2 ) );
109 // sort down first repo
110 action.setRepoGroupId( repoGroup.getId() );
111 action.setTargetRepo( REPO1_ID );
113 String result = action.sortDown();
114 assertEquals( Action.SUCCESS, result );
116 repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
117 repositories = repoGroup.getRepositories();
118 assertEquals( 3, repositories.size() );
119 assertEquals( REPO2_ID, repositories.get( 0 ) );
120 assertEquals( REPO1_ID, repositories.get( 1 ) );
121 assertEquals( REPO3_ID, repositories.get( 2 ) );
124 public void testSortDownLastRepository()
127 Configuration configuration = createInitialConfiguration();
129 archivaConfiguration.getConfiguration();
130 archivaConfigurationControl.setReturnValue( configuration, 4 );
131 archivaConfiguration.save( configuration );
132 archivaConfigurationControl.replay();
134 RepositoryGroupConfiguration repoGroup =
135 (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
136 java.util.List<String> repositories = repoGroup.getRepositories();
138 assertEquals( 3, repositories.size() );
139 assertEquals( REPO1_ID, repositories.get( 0 ) );
140 assertEquals( REPO2_ID, repositories.get( 1 ) );
141 assertEquals( REPO3_ID, repositories.get( 2 ) );
143 // sort down last repo
144 action.setRepoGroupId( repoGroup.getId() );
145 action.setTargetRepo( REPO3_ID );
147 String result = action.sortDown();
148 assertEquals( Action.SUCCESS, result );
150 repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
151 repositories = repoGroup.getRepositories();
152 assertEquals( 3, repositories.size() );
153 assertEquals( REPO1_ID, repositories.get( 0 ) );
154 assertEquals( REPO2_ID, repositories.get( 1 ) );
155 assertEquals( REPO3_ID, repositories.get( 2 ) );
158 public void testSortUpLastRepository()
161 Configuration configuration = createInitialConfiguration();
163 archivaConfiguration.getConfiguration();
164 archivaConfigurationControl.setReturnValue( configuration, 4 );
165 archivaConfiguration.save( configuration );
166 archivaConfigurationControl.replay();
168 RepositoryGroupConfiguration repoGroup =
169 (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
170 java.util.List<String> repositories = repoGroup.getRepositories();
172 assertEquals( 3, repositories.size() );
173 assertEquals( REPO1_ID, repositories.get( 0 ) );
174 assertEquals( REPO2_ID, repositories.get( 1 ) );
175 assertEquals( REPO3_ID, repositories.get( 2 ) );
178 action.setRepoGroupId( repoGroup.getId() );
179 action.setTargetRepo( REPO3_ID );
181 String result = action.sortUp();
182 assertEquals( Action.SUCCESS, result );
184 repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
185 repositories = repoGroup.getRepositories();
186 assertEquals( 3, repositories.size() );
187 assertEquals( REPO1_ID, repositories.get( 0 ) );
188 assertEquals( REPO3_ID, repositories.get( 1 ) );
189 assertEquals( REPO2_ID, repositories.get( 2 ) );
192 public void testSortUpFirstRepository()
195 Configuration configuration = createInitialConfiguration();
197 archivaConfiguration.getConfiguration();
198 archivaConfigurationControl.setReturnValue( configuration, 4 );
199 archivaConfiguration.save( configuration );
200 archivaConfigurationControl.replay();
202 RepositoryGroupConfiguration repoGroup =
203 (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
204 java.util.List<String> repositories = repoGroup.getRepositories();
206 assertEquals( 3, repositories.size() );
207 assertEquals( REPO1_ID, repositories.get( 0 ) );
208 assertEquals( REPO2_ID, repositories.get( 1 ) );
209 assertEquals( REPO3_ID, repositories.get( 2 ) );
211 // sort up first repo
212 action.setRepoGroupId( repoGroup.getId() );
213 action.setTargetRepo( REPO1_ID );
215 String result = action.sortUp();
216 assertEquals( Action.SUCCESS, result );
218 repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
219 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 ) );
226 private Configuration createInitialConfiguration()
228 Configuration config = new Configuration();
230 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
231 repoGroup.setId( REPO_GROUP_ID );
232 repoGroup.addRepository( REPO1_ID );
233 repoGroup.addRepository( REPO2_ID );
234 repoGroup.addRepository( REPO3_ID );
236 config.addRepositoryGroup( repoGroup );