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 org.apache.maven.archiva.configuration.ArchivaConfiguration;
23 import org.apache.maven.archiva.configuration.Configuration;
24 import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration;
25 import org.apache.struts2.StrutsSpringTestCase;
26 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
27 import org.codehaus.redback.integration.interceptor.SecureActionException;
28 import org.easymock.MockControl;
30 import com.opensymphony.xwork2.Action;
33 * SortRepositoriesActionTest
37 public class SortRepositoriesActionTest
38 extends StrutsSpringTestCase
40 private static final String REPO_GROUP_ID = "repo-group-ident";
42 private static final String REPO1_ID = "managed-repo-ident-1";
44 private static final String REPO2_ID = "managed-repo-ident-2";
46 private static final String REPO3_ID = "managed-repo-ident-3";
48 private MockControl archivaConfigurationControl;
50 private ArchivaConfiguration archivaConfiguration;
52 private SortRepositoriesAction action;
55 protected String[] getContextLocations()
57 return new String[]{ "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" };
60 protected void setUp()
65 //action = (SortRepositoriesAction) lookup( Action.class.getName(), "sortRepositoriesAction" );
67 action = (SortRepositoriesAction) getActionProxy( "sortDownRepositoryFromGroup.action" ).getAction();
68 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
69 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
70 action.setArchivaConfiguration( archivaConfiguration );
73 public void testSecureActionBundle()
74 throws SecureActionException
76 archivaConfiguration.getConfiguration();
77 archivaConfigurationControl.setReturnValue( new Configuration() );
78 archivaConfigurationControl.replay();
80 SecureActionBundle bundle = action.getSecureActionBundle();
81 assertTrue( bundle.requiresAuthentication() );
82 assertEquals( 1, bundle.getAuthorizationTuples().size() );
85 public void testSortDownFirstRepository()
88 Configuration configuration = createInitialConfiguration();
90 archivaConfiguration.getConfiguration();
91 archivaConfigurationControl.setReturnValue( configuration, 4 );
92 archivaConfiguration.save( configuration );
93 archivaConfigurationControl.replay();
95 RepositoryGroupConfiguration repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
96 java.util.List<String> repositories = repoGroup.getRepositories();
98 assertEquals( 3, repositories.size() );
99 assertEquals( REPO1_ID, repositories.get( 0 ) );
100 assertEquals( REPO2_ID, repositories.get( 1 ) );
101 assertEquals( REPO3_ID, repositories.get( 2 ) );
103 // sort down first repo
104 action.setRepoGroupId( repoGroup.getId() );
105 action.setTargetRepo( REPO1_ID );
107 String result = action.sortDown();
108 assertEquals( Action.SUCCESS, result );
110 repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
111 repositories = repoGroup.getRepositories();
112 assertEquals( 3, repositories.size() );
113 assertEquals( REPO2_ID, repositories.get( 0 ) );
114 assertEquals( REPO1_ID, repositories.get( 1 ) );
115 assertEquals( REPO3_ID, repositories.get( 2 ) );
118 public void testSortDownLastRepository()
121 Configuration configuration = createInitialConfiguration();
123 archivaConfiguration.getConfiguration();
124 archivaConfigurationControl.setReturnValue( configuration, 4 );
125 archivaConfiguration.save( configuration );
126 archivaConfigurationControl.replay();
128 RepositoryGroupConfiguration repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
129 java.util.List<String> repositories = repoGroup.getRepositories();
131 assertEquals( 3, repositories.size() );
132 assertEquals( REPO1_ID, repositories.get( 0 ) );
133 assertEquals( REPO2_ID, repositories.get( 1 ) );
134 assertEquals( REPO3_ID, repositories.get( 2 ) );
136 // sort down last repo
137 action.setRepoGroupId( repoGroup.getId() );
138 action.setTargetRepo( REPO3_ID );
140 String result = action.sortDown();
141 assertEquals( Action.SUCCESS, result );
143 repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
144 repositories = repoGroup.getRepositories();
145 assertEquals( 3, repositories.size() );
146 assertEquals( REPO1_ID, repositories.get( 0 ) );
147 assertEquals( REPO2_ID, repositories.get( 1 ) );
148 assertEquals( REPO3_ID, repositories.get( 2 ) );
151 public void testSortUpLastRepository()
154 Configuration configuration = createInitialConfiguration();
156 archivaConfiguration.getConfiguration();
157 archivaConfigurationControl.setReturnValue( configuration, 4 );
158 archivaConfiguration.save( configuration );
159 archivaConfigurationControl.replay();
161 RepositoryGroupConfiguration repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
162 java.util.List<String> 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 ) );
170 action.setRepoGroupId( repoGroup.getId() );
171 action.setTargetRepo( REPO3_ID );
173 String result = action.sortUp();
174 assertEquals( Action.SUCCESS, result );
176 repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
177 repositories = repoGroup.getRepositories();
178 assertEquals( 3, repositories.size() );
179 assertEquals( REPO1_ID, repositories.get( 0 ) );
180 assertEquals( REPO3_ID, repositories.get( 1 ) );
181 assertEquals( REPO2_ID, repositories.get( 2 ) );
184 public void testSortUpFirstRepository()
187 Configuration configuration = createInitialConfiguration();
189 archivaConfiguration.getConfiguration();
190 archivaConfigurationControl.setReturnValue( configuration, 4 );
191 archivaConfiguration.save( configuration );
192 archivaConfigurationControl.replay();
194 RepositoryGroupConfiguration repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
195 java.util.List<String> repositories = repoGroup.getRepositories();
197 assertEquals( 3, repositories.size() );
198 assertEquals( REPO1_ID, repositories.get( 0 ) );
199 assertEquals( REPO2_ID, repositories.get( 1 ) );
200 assertEquals( REPO3_ID, repositories.get( 2 ) );
202 // sort up first repo
203 action.setRepoGroupId( repoGroup.getId() );
204 action.setTargetRepo( REPO1_ID );
206 String result = action.sortUp();
207 assertEquals( Action.SUCCESS, result );
209 repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
210 repositories = repoGroup.getRepositories();
211 assertEquals( 3, repositories.size() );
212 assertEquals( REPO1_ID, repositories.get( 0 ) );
213 assertEquals( REPO2_ID, repositories.get( 1 ) );
214 assertEquals( REPO3_ID, repositories.get( 2 ) );
217 private Configuration createInitialConfiguration()
219 Configuration config = new Configuration();
221 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
222 repoGroup.setId( REPO_GROUP_ID );
223 repoGroup.addRepository( REPO1_ID );
224 repoGroup.addRepository( REPO2_ID );
225 repoGroup.addRepository( REPO3_ID );
227 config.addRepositoryGroup( repoGroup );