1 package org.apache.archiva.admin.repository.group;
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import org.apache.archiva.admin.model.RepositoryAdminException;
22 import org.apache.archiva.admin.model.beans.ManagedRepository;
23 import org.apache.archiva.admin.model.beans.RepositoryGroup;
24 import org.apache.archiva.admin.model.group.RepositoryGroupAdmin;
25 import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest;
26 import org.apache.archiva.metadata.model.facets.AuditEvent;
27 import org.apache.archiva.repository.Repository;
28 import org.apache.archiva.repository.RepositoryRegistry;
29 import org.apache.archiva.repository.base.RepositoryGroupHandler;
30 import org.junit.Test;
32 import javax.inject.Inject;
33 import java.nio.file.Paths;
34 import java.util.Arrays;
37 * @author Olivier Lamy
39 public class RepositoryGroupAdminTest
40 extends AbstractRepositoryAdminTest
43 RepositoryGroupAdmin repositoryGroupAdmin;
46 RepositoryRegistry repositoryRegistry;
49 RepositoryGroupHandler repositoryGroupHandler;
52 public void addAndDeleteGroup()
57 Repository repo = repositoryRegistry.getRepository("test-new-one");
59 repositoryRegistry.removeRepository(repo);
61 repo = repositoryRegistry.getRepository("test-new-two");
63 repositoryRegistry.removeRepository(repo);
65 ManagedRepository managedRepositoryOne =
66 getTestManagedRepository( "test-new-one", Paths.get(APPSERVER_BASE_PATH,"test-new-one" ).toString());
68 ManagedRepository managedRepositoryTwo =
69 getTestManagedRepository( "test-new-two", Paths.get(APPSERVER_BASE_PATH, "test-new-two" ).toString());
71 managedRepositoryAdmin.addManagedRepository( managedRepositoryOne, false, getFakeAuditInformation() );
73 managedRepositoryAdmin.addManagedRepository( managedRepositoryTwo, false, getFakeAuditInformation() );
76 RepositoryGroup repositoryGroup =
77 new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one", "test-new-two" ) );
78 // repositoryGroupAdmin.deleteRepositoryGroup("repo-group-one", null);
80 mockAuditListener.clearEvents();
82 repositoryGroupAdmin.addRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
84 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() );
85 assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() );
86 assertEquals( 2, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
87 assertEquals( Arrays.asList( "test-new-one", "test-new-two" ),
88 repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
90 // verify if default values were saved
91 assertEquals(30, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexTtl() );
92 assertEquals(".indexer", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexPath() );
94 repositoryGroupAdmin.deleteRepositoryGroup( "repo-group-one", getFakeAuditInformation() );
96 assertEquals( 0, repositoryGroupAdmin.getRepositoriesGroups().size() );
98 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
100 assertEquals( AuditEvent.ADD_REPO_GROUP, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
101 assertEquals( AuditEvent.DELETE_REPO_GROUP, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
105 mockAuditListener.clearEvents();
106 repositoryRegistry.removeRepository(repositoryRegistry.getManagedRepository("test-new-one"));
107 repositoryRegistry.removeRepository(repositoryRegistry.getManagedRepository("test-new-two"));
112 public void addAndUpdateAndDeleteGroup()
117 ManagedRepository managedRepositoryOne =
118 getTestManagedRepository( "test-new-one", Paths.get(APPSERVER_BASE_PATH,"test-new-one" ).toString());
120 ManagedRepository managedRepositoryTwo =
121 getTestManagedRepository( "test-new-two", Paths.get(APPSERVER_BASE_PATH, "test-new-two" ).toString());
123 managedRepositoryAdmin.addManagedRepository( managedRepositoryOne, false, getFakeAuditInformation() );
125 managedRepositoryAdmin.addManagedRepository( managedRepositoryTwo, false, getFakeAuditInformation() );
127 RepositoryGroup repositoryGroup = new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one" ) )
128 .mergedIndexTtl( 20 ).mergedIndexPath( "/.nonDefaultPath" );
130 mockAuditListener.clearEvents();
132 repositoryGroupAdmin.addRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
134 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() );
135 assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() );
136 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
137 assertEquals( Arrays.asList( "test-new-one" ),
138 repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
139 assertEquals( 20, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexTtl() );
140 assertEquals( "/.nonDefaultPath", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexPath() );
142 repositoryGroup = repositoryGroupAdmin.getRepositoryGroup( "repo-group-one" );
143 assertNotNull( repositoryGroup );
145 repositoryGroup.addRepository( managedRepositoryTwo.getId() );
147 repositoryGroupAdmin.updateRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
149 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() );
150 assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() );
151 assertEquals( 2, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
152 assertEquals( Arrays.asList( "test-new-one", "test-new-two" ),
153 repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
155 repositoryGroupAdmin.deleteRepositoryGroup( "repo-group-one", getFakeAuditInformation() );
157 assertEquals( 0, repositoryGroupAdmin.getRepositoriesGroups().size() );
159 assertEquals( 3, mockAuditListener.getAuditEvents().size() );
161 assertEquals( AuditEvent.ADD_REPO_GROUP, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
162 assertEquals( AuditEvent.MODIFY_REPO_GROUP, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
163 assertEquals( AuditEvent.DELETE_REPO_GROUP, mockAuditListener.getAuditEvents().get( 2 ).getAction() );
167 mockAuditListener.clearEvents();
168 managedRepositoryAdmin.deleteManagedRepository( "test-new-one", getFakeAuditInformation(), true );
169 managedRepositoryAdmin.deleteManagedRepository( "test-new-two", getFakeAuditInformation(), true );
174 public void addAndDeleteGroupWithRemovedManagedRepo()
179 ManagedRepository managedRepositoryOne =
180 getTestManagedRepository( "test-new-one", Paths.get(APPSERVER_BASE_PATH , "test-new-one" ).toString());
182 ManagedRepository managedRepositoryTwo =
183 getTestManagedRepository( "test-new-two", Paths.get(APPSERVER_BASE_PATH ,"test-new-two" ).toString());
185 managedRepositoryAdmin.addManagedRepository( managedRepositoryOne, false, getFakeAuditInformation() );
187 managedRepositoryAdmin.addManagedRepository( managedRepositoryTwo, false, getFakeAuditInformation() );
189 RepositoryGroup repositoryGroup =
190 new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one", "test-new-two" ) );
192 mockAuditListener.clearEvents();
194 repositoryGroupAdmin.addRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
196 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() );
197 assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() );
198 assertEquals( 2, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
199 assertEquals( Arrays.asList( "test-new-one", "test-new-two" ),
200 repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
202 // deleting a managed repo to validate repogroup correctly updated !
203 managedRepositoryAdmin.deleteManagedRepository( "test-new-one", getFakeAuditInformation(), true );
205 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() );
206 assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() );
207 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
208 assertEquals( Arrays.asList( "test-new-two" ),
209 repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
211 repositoryGroupAdmin.deleteRepositoryGroup( "repo-group-one", getFakeAuditInformation() );
213 assertEquals( 0, repositoryGroupAdmin.getRepositoriesGroups().size() );
215 assertEquals( 3, mockAuditListener.getAuditEvents().size() );
217 assertEquals( AuditEvent.ADD_REPO_GROUP, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
218 assertEquals( AuditEvent.DELETE_MANAGED_REPO, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
219 assertEquals( AuditEvent.DELETE_REPO_GROUP, mockAuditListener.getAuditEvents().get( 2 ).getAction() );
223 mockAuditListener.clearEvents();
224 repositoryRegistry.removeRepository(repositoryRegistry.getRepository("test-new-two"));
228 @Test( expected = RepositoryAdminException.class )
229 public void testAddGroupWithInvalidMergedIndexTtl() throws Exception {
231 ManagedRepository managedRepositoryOne =
232 getTestManagedRepository( "test-new-one", Paths.get(APPSERVER_BASE_PATH , "test-new-one" ).toString());
234 ManagedRepository managedRepositoryTwo =
235 getTestManagedRepository( "test-new-two", Paths.get(APPSERVER_BASE_PATH , "test-new-two" ).toString());
237 managedRepositoryAdmin.addManagedRepository( managedRepositoryOne, false, getFakeAuditInformation() );
239 managedRepositoryAdmin.addManagedRepository( managedRepositoryTwo, false, getFakeAuditInformation() );
241 RepositoryGroup repositoryGroup =
242 new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one", "test-new-two" ) )
243 .mergedIndexTtl( -1 );
245 mockAuditListener.clearEvents();
247 repositoryGroupAdmin.addRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
251 mockAuditListener.clearEvents();
252 repositoryRegistry.removeRepository(repositoryRegistry.getRepository("test-new-one"));
253 repositoryRegistry.removeRepository(repositoryRegistry.getRepository("test-new-two"));
257 @Test( expected = RepositoryAdminException.class )
258 public void testAddAndUpdateGroupWithInvalidMergedIndexTtl() throws Exception {
260 ManagedRepository managedRepositoryOne =
261 getTestManagedRepository( "test-new-one", Paths.get(APPSERVER_BASE_PATH , "test-new-one" ).toString());
263 ManagedRepository managedRepositoryTwo =
264 getTestManagedRepository( "test-new-two", Paths.get(APPSERVER_BASE_PATH , "test-new-two" ).toString());
266 managedRepositoryAdmin.addManagedRepository( managedRepositoryOne, false, getFakeAuditInformation() );
268 managedRepositoryAdmin.addManagedRepository( managedRepositoryTwo, false, getFakeAuditInformation() );
270 RepositoryGroup repositoryGroup =
271 new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one", "test-new-two" ) );
273 mockAuditListener.clearEvents();
275 repositoryGroupAdmin.addRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
277 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() );
278 assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() );
279 assertEquals( 2, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
280 assertEquals( Arrays.asList( "test-new-one", "test-new-two" ),
281 repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
283 // verify if default values were saved
284 assertEquals(30, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexTtl() );
285 assertEquals(".indexer", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexPath() );
287 repositoryGroup = repositoryGroupAdmin.getRepositoryGroup( "repo-group-one" );
288 assertNotNull( repositoryGroup );
290 repositoryGroup.mergedIndexTtl( -1 );
292 repositoryGroupAdmin.updateRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
296 mockAuditListener.clearEvents();
297 managedRepositoryAdmin.deleteManagedRepository( "test-new-one", getFakeAuditInformation(), true );
298 managedRepositoryAdmin.deleteManagedRepository( "test-new-two", getFakeAuditInformation(), true );