]> source.dussan.org Git - archiva.git/blob
73677e1186089ab4eae0581293d471fa2e880793
[archiva.git] /
1 package org.apache.maven.archiva.web.action.admin.repositories;
2
3 /*
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
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  * under the License.
20  */
21
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;
29
30 import com.opensymphony.xwork2.Action;
31
32 /**
33  * SortRepositoriesActionTest
34  * 
35  * @version
36  */
37 public class SortRepositoriesActionTest 
38     extends StrutsSpringTestCase
39 {
40     private static final String REPO_GROUP_ID = "repo-group-ident";
41         
42     private static final String REPO1_ID = "managed-repo-ident-1";
43         
44     private static final String REPO2_ID = "managed-repo-ident-2";
45         
46     private static final String REPO3_ID = "managed-repo-ident-3";
47         
48     private MockControl archivaConfigurationControl;
49
50     private ArchivaConfiguration archivaConfiguration;
51     
52     private SortRepositoriesAction action;
53
54     @Override
55     protected String[] getContextLocations()
56     {
57         return new String[]{ "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" };
58     }
59
60     protected void setUp()
61         throws Exception
62     {
63         super.setUp();
64             
65         //action = (SortRepositoriesAction) lookup( Action.class.getName(), "sortRepositoriesAction" );
66
67         action = (SortRepositoriesAction) getActionProxy( "sortDownRepositoryFromGroup.action" ).getAction();
68         archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
69         archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
70         action.setArchivaConfiguration( archivaConfiguration );
71     }
72     
73     public void testSecureActionBundle()
74         throws SecureActionException
75     {
76         archivaConfiguration.getConfiguration();
77         archivaConfigurationControl.setReturnValue( new Configuration() );
78         archivaConfigurationControl.replay();
79         
80         SecureActionBundle bundle = action.getSecureActionBundle();
81         assertTrue( bundle.requiresAuthentication() );
82         assertEquals( 1, bundle.getAuthorizationTuples().size() );
83     }
84     
85     public void testSortDownFirstRepository()
86         throws Exception
87     {
88         Configuration configuration = createInitialConfiguration();
89         
90         archivaConfiguration.getConfiguration();
91         archivaConfigurationControl.setReturnValue( configuration, 4 );
92         archivaConfiguration.save( configuration );
93         archivaConfigurationControl.replay();
94         
95         RepositoryGroupConfiguration repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
96         java.util.List<String> repositories = repoGroup.getRepositories();
97         
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 ) );
102         
103         // sort down first repo
104         action.setRepoGroupId( repoGroup.getId() );
105         action.setTargetRepo( REPO1_ID );
106         
107         String result = action.sortDown();
108         assertEquals( Action.SUCCESS, result );
109         
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 ) );
116     }
117     
118     public void testSortDownLastRepository()
119         throws Exception
120     {
121         Configuration configuration = createInitialConfiguration();
122         
123         archivaConfiguration.getConfiguration();
124         archivaConfigurationControl.setReturnValue( configuration, 4 );
125         archivaConfiguration.save( configuration );
126         archivaConfigurationControl.replay();
127         
128         RepositoryGroupConfiguration repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
129         java.util.List<String> repositories = repoGroup.getRepositories();
130         
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 ) );
135         
136         // sort down last repo
137         action.setRepoGroupId( repoGroup.getId() );
138         action.setTargetRepo( REPO3_ID );
139         
140         String result = action.sortDown();
141         assertEquals( Action.SUCCESS, result );
142         
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 ) );
149     }
150     
151     public void testSortUpLastRepository()
152         throws Exception
153     {
154         Configuration configuration = createInitialConfiguration();
155         
156         archivaConfiguration.getConfiguration();
157         archivaConfigurationControl.setReturnValue( configuration, 4 );
158         archivaConfiguration.save( configuration );
159         archivaConfigurationControl.replay();
160         
161         RepositoryGroupConfiguration repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
162         java.util.List<String> repositories = repoGroup.getRepositories();
163         
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 ) );
168         
169         // sort up last repo
170         action.setRepoGroupId( repoGroup.getId() );
171         action.setTargetRepo( REPO3_ID );
172         
173         String result = action.sortUp();
174         assertEquals( Action.SUCCESS, result );
175         
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 ) );
182     }
183     
184     public void testSortUpFirstRepository()
185         throws Exception
186     {
187         Configuration configuration = createInitialConfiguration();
188         
189         archivaConfiguration.getConfiguration();
190         archivaConfigurationControl.setReturnValue( configuration, 4 );
191         archivaConfiguration.save( configuration );
192         archivaConfigurationControl.replay();
193         
194         RepositoryGroupConfiguration repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
195         java.util.List<String> repositories = repoGroup.getRepositories();
196         
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 ) );
201         
202         // sort up first repo
203         action.setRepoGroupId( repoGroup.getId() );
204         action.setTargetRepo( REPO1_ID );
205         
206         String result = action.sortUp();
207         assertEquals( Action.SUCCESS, result );
208         
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 ) );
215     }
216     
217     private Configuration createInitialConfiguration()
218     {
219         Configuration config = new Configuration();
220         
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 );
226                 
227         config.addRepositoryGroup( repoGroup );
228         
229         return config;
230     }
231 }