]> source.dussan.org Git - archiva.git/blob
9cd3606406bd6c9e35a34ed4b290660ab89c4d41
[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.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;
29
30 import com.opensymphony.xwork.Action;
31
32 /**
33  * SortRepositoriesActionTest
34  * 
35  * @author
36  * @version
37  */
38 public class SortRepositoriesActionTest 
39     extends PlexusInSpringTestCase
40 {
41     private static final String REPO_GROUP_ID = "repo-group-ident";
42         
43     private static final String REPO1_ID = "managed-repo-ident-1";
44         
45     private static final String REPO2_ID = "managed-repo-ident-2";
46         
47     private static final String REPO3_ID = "managed-repo-ident-3";
48         
49     private MockControl archivaConfigurationControl;
50
51     private ArchivaConfiguration archivaConfiguration;
52     
53     private SortRepositoriesAction action;
54     
55     protected void setUp()
56         throws Exception
57     {
58         super.setUp();
59             
60         action = (SortRepositoriesAction) lookup( Action.class.getName(), "sortRepositoriesAction" );
61             
62         archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
63         archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
64         action.setArchivaConfiguration( archivaConfiguration );
65     }
66     
67     public void testSecureActionBundle()
68         throws SecureActionException
69     {
70         archivaConfiguration.getConfiguration();
71         archivaConfigurationControl.setReturnValue( new Configuration() );
72         archivaConfigurationControl.replay();
73         
74         SecureActionBundle bundle = action.getSecureActionBundle();
75         assertTrue( bundle.requiresAuthentication() );
76         assertEquals( 1, bundle.getAuthorizationTuples().size() );
77     }
78     
79     public void testSortDownFirstRepository()
80         throws Exception
81     {
82         Configuration configuration = createInitialConfiguration();
83         
84         archivaConfiguration.getConfiguration();
85         archivaConfigurationControl.setReturnValue( configuration, 4 );
86         archivaConfiguration.save( configuration );
87         archivaConfigurationControl.replay();
88         
89         RepositoryGroupConfiguration repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
90         java.util.List<String> repositories = repoGroup.getRepositories();
91         
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 ) );
96         
97         // sort down first repo
98         action.setRepoGroupId( repoGroup.getId() );
99         action.setTargetRepo( REPO1_ID );
100         
101         String result = action.sortDown();
102         assertEquals( Action.SUCCESS, result );
103         
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 ) );
110     }
111     
112     public void testSortDownLastRepository()
113         throws Exception
114     {
115         Configuration configuration = createInitialConfiguration();
116         
117         archivaConfiguration.getConfiguration();
118         archivaConfigurationControl.setReturnValue( configuration, 4 );
119         archivaConfiguration.save( configuration );
120         archivaConfigurationControl.replay();
121         
122         RepositoryGroupConfiguration repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
123         java.util.List<String> repositories = repoGroup.getRepositories();
124         
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 ) );
129         
130         // sort down last repo
131         action.setRepoGroupId( repoGroup.getId() );
132         action.setTargetRepo( REPO3_ID );
133         
134         String result = action.sortDown();
135         assertEquals( Action.SUCCESS, result );
136         
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 ) );
143     }
144     
145     public void testSortUpLastRepository()
146         throws Exception
147     {
148         Configuration configuration = createInitialConfiguration();
149         
150         archivaConfiguration.getConfiguration();
151         archivaConfigurationControl.setReturnValue( configuration, 4 );
152         archivaConfiguration.save( configuration );
153         archivaConfigurationControl.replay();
154         
155         RepositoryGroupConfiguration repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
156         java.util.List<String> repositories = repoGroup.getRepositories();
157         
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 ) );
162         
163         // sort up last repo
164         action.setRepoGroupId( repoGroup.getId() );
165         action.setTargetRepo( REPO3_ID );
166         
167         String result = action.sortUp();
168         assertEquals( Action.SUCCESS, result );
169         
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 ) );
176     }
177     
178     public void testSortUpFirstRepository()
179         throws Exception
180     {
181         Configuration configuration = createInitialConfiguration();
182         
183         archivaConfiguration.getConfiguration();
184         archivaConfigurationControl.setReturnValue( configuration, 4 );
185         archivaConfiguration.save( configuration );
186         archivaConfigurationControl.replay();
187         
188         RepositoryGroupConfiguration repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
189         java.util.List<String> repositories = repoGroup.getRepositories();
190         
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 ) );
195         
196         // sort up first repo
197         action.setRepoGroupId( repoGroup.getId() );
198         action.setTargetRepo( REPO1_ID );
199         
200         String result = action.sortUp();
201         assertEquals( Action.SUCCESS, result );
202         
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 ) );
209     }
210     
211     private Configuration createInitialConfiguration()
212     {
213         Configuration config = new Configuration();
214         
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 );
220                 
221         config.addRepositoryGroup( repoGroup );
222         
223         return config;
224     }
225 }