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.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle;
26 import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException;
27 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
28 import org.easymock.MockControl;
30 import com.opensymphony.xwork.Action;
33 * SortRepositoriesActionTest
38 public class SortRepositoriesActionTest
39 extends PlexusInSpringTestCase
41 private static final String REPO_GROUP_ID = "repo-group-ident";
43 private static final String REPO1_ID = "managed-repo-ident-1";
45 private static final String REPO2_ID = "managed-repo-ident-2";
47 private static final String REPO3_ID = "managed-repo-ident-3";
49 private MockControl archivaConfigurationControl;
51 private ArchivaConfiguration archivaConfiguration;
53 private SortRepositoriesAction action;
55 protected void setUp()
60 action = (SortRepositoriesAction) lookup( Action.class.getName(), "sortRepositoriesAction" );
62 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
63 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
64 action.setArchivaConfiguration( archivaConfiguration );
67 public void testSecureActionBundle()
68 throws SecureActionException
70 archivaConfiguration.getConfiguration();
71 archivaConfigurationControl.setReturnValue( new Configuration() );
72 archivaConfigurationControl.replay();
74 SecureActionBundle bundle = action.getSecureActionBundle();
75 assertTrue( bundle.requiresAuthentication() );
76 assertEquals( 1, bundle.getAuthorizationTuples().size() );
79 public void testSortDownFirstRepository()
82 Configuration configuration = createInitialConfiguration();
84 archivaConfiguration.getConfiguration();
85 archivaConfigurationControl.setReturnValue( configuration, 4 );
86 archivaConfiguration.save( configuration );
87 archivaConfigurationControl.replay();
89 RepositoryGroupConfiguration repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
90 java.util.List<String> repositories = repoGroup.getRepositories();
92 assertEquals( 3, repositories.size() );
93 assertEquals( REPO1_ID, repositories.get( 0 ) );
94 assertEquals( REPO2_ID, repositories.get( 1 ) );
95 assertEquals( REPO3_ID, repositories.get( 2 ) );
97 // sort down first repo
98 action.setRepoGroupId( repoGroup.getId() );
99 action.setTargetRepo( REPO1_ID );
101 String result = action.sortDown();
102 assertEquals( Action.SUCCESS, result );
104 repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
105 repositories = repoGroup.getRepositories();
106 assertEquals( 3, repositories.size() );
107 assertEquals( REPO2_ID, repositories.get( 0 ) );
108 assertEquals( REPO1_ID, repositories.get( 1 ) );
109 assertEquals( REPO3_ID, repositories.get( 2 ) );
112 public void testSortDownLastRepository()
115 Configuration configuration = createInitialConfiguration();
117 archivaConfiguration.getConfiguration();
118 archivaConfigurationControl.setReturnValue( configuration, 4 );
119 archivaConfiguration.save( configuration );
120 archivaConfigurationControl.replay();
122 RepositoryGroupConfiguration repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
123 java.util.List<String> repositories = repoGroup.getRepositories();
125 assertEquals( 3, repositories.size() );
126 assertEquals( REPO1_ID, repositories.get( 0 ) );
127 assertEquals( REPO2_ID, repositories.get( 1 ) );
128 assertEquals( REPO3_ID, repositories.get( 2 ) );
130 // sort down last repo
131 action.setRepoGroupId( repoGroup.getId() );
132 action.setTargetRepo( REPO3_ID );
134 String result = action.sortDown();
135 assertEquals( Action.SUCCESS, result );
137 repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
138 repositories = repoGroup.getRepositories();
139 assertEquals( 3, repositories.size() );
140 assertEquals( REPO1_ID, repositories.get( 0 ) );
141 assertEquals( REPO2_ID, repositories.get( 1 ) );
142 assertEquals( REPO3_ID, repositories.get( 2 ) );
145 public void testSortUpLastRepository()
148 Configuration configuration = createInitialConfiguration();
150 archivaConfiguration.getConfiguration();
151 archivaConfigurationControl.setReturnValue( configuration, 4 );
152 archivaConfiguration.save( configuration );
153 archivaConfigurationControl.replay();
155 RepositoryGroupConfiguration repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
156 java.util.List<String> repositories = repoGroup.getRepositories();
158 assertEquals( 3, repositories.size() );
159 assertEquals( REPO1_ID, repositories.get( 0 ) );
160 assertEquals( REPO2_ID, repositories.get( 1 ) );
161 assertEquals( REPO3_ID, repositories.get( 2 ) );
164 action.setRepoGroupId( repoGroup.getId() );
165 action.setTargetRepo( REPO3_ID );
167 String result = action.sortUp();
168 assertEquals( Action.SUCCESS, result );
170 repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
171 repositories = repoGroup.getRepositories();
172 assertEquals( 3, repositories.size() );
173 assertEquals( REPO1_ID, repositories.get( 0 ) );
174 assertEquals( REPO3_ID, repositories.get( 1 ) );
175 assertEquals( REPO2_ID, repositories.get( 2 ) );
178 public void testSortUpFirstRepository()
181 Configuration configuration = createInitialConfiguration();
183 archivaConfiguration.getConfiguration();
184 archivaConfigurationControl.setReturnValue( configuration, 4 );
185 archivaConfiguration.save( configuration );
186 archivaConfigurationControl.replay();
188 RepositoryGroupConfiguration repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
189 java.util.List<String> repositories = repoGroup.getRepositories();
191 assertEquals( 3, repositories.size() );
192 assertEquals( REPO1_ID, repositories.get( 0 ) );
193 assertEquals( REPO2_ID, repositories.get( 1 ) );
194 assertEquals( REPO3_ID, repositories.get( 2 ) );
196 // sort up first repo
197 action.setRepoGroupId( repoGroup.getId() );
198 action.setTargetRepo( REPO1_ID );
200 String result = action.sortUp();
201 assertEquals( Action.SUCCESS, result );
203 repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
204 repositories = repoGroup.getRepositories();
205 assertEquals( 3, repositories.size() );
206 assertEquals( REPO1_ID, repositories.get( 0 ) );
207 assertEquals( REPO2_ID, repositories.get( 1 ) );
208 assertEquals( REPO3_ID, repositories.get( 2 ) );
211 private Configuration createInitialConfiguration()
213 Configuration config = new Configuration();
215 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
216 repoGroup.setId( REPO_GROUP_ID );
217 repoGroup.addRepository( REPO1_ID );
218 repoGroup.addRepository( REPO2_ID );
219 repoGroup.addRepository( REPO3_ID );
221 config.addRepositoryGroup( repoGroup );