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.junit.Test;
31 import javax.inject.Inject;
32 import java.nio.file.Paths;
33 import java.util.Arrays;
36 * @author Olivier Lamy
38 public class RepositoryGroupAdminTest
39 extends AbstractRepositoryAdminTest
42 RepositoryGroupAdmin repositoryGroupAdmin;
45 RepositoryRegistry repositoryRegistry;
48 public void addAndDeleteGroup()
53 Repository repo = repositoryRegistry.getRepository("test-new-one");
55 repositoryRegistry.removeRepository(repo);
57 repo = repositoryRegistry.getRepository("test-new-two");
59 repositoryRegistry.removeRepository(repo);
61 ManagedRepository managedRepositoryOne =
62 getTestManagedRepository( "test-new-one", Paths.get(APPSERVER_BASE_PATH,"test-new-one" ).toString());
64 ManagedRepository managedRepositoryTwo =
65 getTestManagedRepository( "test-new-two", Paths.get(APPSERVER_BASE_PATH, "test-new-two" ).toString());
67 managedRepositoryAdmin.addManagedRepository( managedRepositoryOne, false, getFakeAuditInformation() );
69 managedRepositoryAdmin.addManagedRepository( managedRepositoryTwo, false, getFakeAuditInformation() );
72 RepositoryGroup repositoryGroup =
73 new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one", "test-new-two" ) );
74 // repositoryGroupAdmin.deleteRepositoryGroup("repo-group-one", null);
76 mockAuditListener.clearEvents();
78 repositoryGroupAdmin.addRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
80 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() );
81 assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() );
82 assertEquals( 2, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
83 assertEquals( Arrays.asList( "test-new-one", "test-new-two" ),
84 repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
86 // verify if default values were saved
87 assertEquals(30, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexTtl() );
88 assertEquals(".indexer", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexPath() );
90 repositoryGroupAdmin.deleteRepositoryGroup( "repo-group-one", getFakeAuditInformation() );
92 assertEquals( 0, repositoryGroupAdmin.getRepositoriesGroups().size() );
94 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
96 assertEquals( AuditEvent.ADD_REPO_GROUP, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
97 assertEquals( AuditEvent.DELETE_REPO_GROUP, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
101 mockAuditListener.clearEvents();
102 repositoryRegistry.removeRepository(repositoryRegistry.getManagedRepository("test-new-one"));
103 repositoryRegistry.removeRepository(repositoryRegistry.getManagedRepository("test-new-two"));
108 public void addAndUpdateAndDeleteGroup()
113 ManagedRepository managedRepositoryOne =
114 getTestManagedRepository( "test-new-one", Paths.get(APPSERVER_BASE_PATH,"test-new-one" ).toString());
116 ManagedRepository managedRepositoryTwo =
117 getTestManagedRepository( "test-new-two", Paths.get(APPSERVER_BASE_PATH, "test-new-two" ).toString());
119 managedRepositoryAdmin.addManagedRepository( managedRepositoryOne, false, getFakeAuditInformation() );
121 managedRepositoryAdmin.addManagedRepository( managedRepositoryTwo, false, getFakeAuditInformation() );
123 RepositoryGroup repositoryGroup = new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one" ) )
124 .mergedIndexTtl( 20 ).mergedIndexPath( "/.nonDefaultPath" );
126 mockAuditListener.clearEvents();
128 repositoryGroupAdmin.addRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
130 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() );
131 assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() );
132 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
133 assertEquals( Arrays.asList( "test-new-one" ),
134 repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
135 assertEquals( 20, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexTtl() );
136 assertEquals( "/.nonDefaultPath", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexPath() );
138 repositoryGroup = repositoryGroupAdmin.getRepositoryGroup( "repo-group-one" );
139 assertNotNull( repositoryGroup );
141 repositoryGroup.addRepository( managedRepositoryTwo.getId() );
143 repositoryGroupAdmin.updateRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
145 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() );
146 assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() );
147 assertEquals( 2, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
148 assertEquals( Arrays.asList( "test-new-one", "test-new-two" ),
149 repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
151 repositoryGroupAdmin.deleteRepositoryGroup( "repo-group-one", getFakeAuditInformation() );
153 assertEquals( 0, repositoryGroupAdmin.getRepositoriesGroups().size() );
155 assertEquals( 3, mockAuditListener.getAuditEvents().size() );
157 assertEquals( AuditEvent.ADD_REPO_GROUP, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
158 assertEquals( AuditEvent.MODIFY_REPO_GROUP, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
159 assertEquals( AuditEvent.DELETE_REPO_GROUP, mockAuditListener.getAuditEvents().get( 2 ).getAction() );
163 mockAuditListener.clearEvents();
164 managedRepositoryAdmin.deleteManagedRepository( "test-new-one", getFakeAuditInformation(), true );
165 managedRepositoryAdmin.deleteManagedRepository( "test-new-two", getFakeAuditInformation(), true );
170 public void addAndDeleteGroupWithRemovedManagedRepo()
175 ManagedRepository managedRepositoryOne =
176 getTestManagedRepository( "test-new-one", Paths.get(APPSERVER_BASE_PATH , "test-new-one" ).toString());
178 ManagedRepository managedRepositoryTwo =
179 getTestManagedRepository( "test-new-two", Paths.get(APPSERVER_BASE_PATH ,"test-new-two" ).toString());
181 managedRepositoryAdmin.addManagedRepository( managedRepositoryOne, false, getFakeAuditInformation() );
183 managedRepositoryAdmin.addManagedRepository( managedRepositoryTwo, false, getFakeAuditInformation() );
185 RepositoryGroup repositoryGroup =
186 new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one", "test-new-two" ) );
188 mockAuditListener.clearEvents();
190 repositoryGroupAdmin.addRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
192 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() );
193 assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() );
194 assertEquals( 2, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
195 assertEquals( Arrays.asList( "test-new-one", "test-new-two" ),
196 repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
198 // deleting a managed repo to validate repogroup correctly updated !
199 managedRepositoryAdmin.deleteManagedRepository( "test-new-one", getFakeAuditInformation(), true );
201 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() );
202 assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() );
203 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
204 assertEquals( Arrays.asList( "test-new-two" ),
205 repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
207 repositoryGroupAdmin.deleteRepositoryGroup( "repo-group-one", getFakeAuditInformation() );
209 assertEquals( 0, repositoryGroupAdmin.getRepositoriesGroups().size() );
211 assertEquals( 3, mockAuditListener.getAuditEvents().size() );
213 assertEquals( AuditEvent.ADD_REPO_GROUP, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
214 assertEquals( AuditEvent.DELETE_MANAGED_REPO, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
215 assertEquals( AuditEvent.DELETE_REPO_GROUP, mockAuditListener.getAuditEvents().get( 2 ).getAction() );
219 mockAuditListener.clearEvents();
220 repositoryRegistry.removeRepository(repositoryRegistry.getRepository("test-new-two"));
224 @Test( expected = RepositoryAdminException.class )
225 public void testAddGroupWithInvalidMergedIndexTtl() throws Exception {
227 ManagedRepository managedRepositoryOne =
228 getTestManagedRepository( "test-new-one", Paths.get(APPSERVER_BASE_PATH , "test-new-one" ).toString());
230 ManagedRepository managedRepositoryTwo =
231 getTestManagedRepository( "test-new-two", Paths.get(APPSERVER_BASE_PATH , "test-new-two" ).toString());
233 managedRepositoryAdmin.addManagedRepository( managedRepositoryOne, false, getFakeAuditInformation() );
235 managedRepositoryAdmin.addManagedRepository( managedRepositoryTwo, false, getFakeAuditInformation() );
237 RepositoryGroup repositoryGroup =
238 new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one", "test-new-two" ) )
239 .mergedIndexTtl( -1 );
241 mockAuditListener.clearEvents();
243 repositoryGroupAdmin.addRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
247 mockAuditListener.clearEvents();
248 repositoryRegistry.removeRepository(repositoryRegistry.getRepository("test-new-one"));
249 repositoryRegistry.removeRepository(repositoryRegistry.getRepository("test-new-two"));
253 @Test( expected = RepositoryAdminException.class )
254 public void testAddAndUpdateGroupWithInvalidMergedIndexTtl() throws Exception {
256 ManagedRepository managedRepositoryOne =
257 getTestManagedRepository( "test-new-one", Paths.get(APPSERVER_BASE_PATH , "test-new-one" ).toString());
259 ManagedRepository managedRepositoryTwo =
260 getTestManagedRepository( "test-new-two", Paths.get(APPSERVER_BASE_PATH , "test-new-two" ).toString());
262 managedRepositoryAdmin.addManagedRepository( managedRepositoryOne, false, getFakeAuditInformation() );
264 managedRepositoryAdmin.addManagedRepository( managedRepositoryTwo, false, getFakeAuditInformation() );
266 RepositoryGroup repositoryGroup =
267 new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one", "test-new-two" ) );
269 mockAuditListener.clearEvents();
271 repositoryGroupAdmin.addRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
273 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() );
274 assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() );
275 assertEquals( 2, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
276 assertEquals( Arrays.asList( "test-new-one", "test-new-two" ),
277 repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
279 // verify if default values were saved
280 assertEquals(30, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexTtl() );
281 assertEquals(".indexer", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexPath() );
283 repositoryGroup = repositoryGroupAdmin.getRepositoryGroup( "repo-group-one" );
284 assertNotNull( repositoryGroup );
286 repositoryGroup.mergedIndexTtl( -1 );
288 repositoryGroupAdmin.updateRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
292 mockAuditListener.clearEvents();
293 managedRepositoryAdmin.deleteManagedRepository( "test-new-one", getFakeAuditInformation(), true );
294 managedRepositoryAdmin.deleteManagedRepository( "test-new-two", getFakeAuditInformation(), true );