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.junit.Test;
29 import javax.inject.Inject;
31 import java.util.Arrays;
34 * @author Olivier Lamy
36 public class RepositoryGroupAdminTest
37 extends AbstractRepositoryAdminTest
40 RepositoryGroupAdmin repositoryGroupAdmin;
43 public void addAndDeleteGroup()
48 ManagedRepository managedRepositoryOne =
49 getTestManagedRepository( "test-new-one", APPSERVER_BASE_PATH + File.separator + "test-new-one" );
51 ManagedRepository managedRepositoryTwo =
52 getTestManagedRepository( "test-new-two", APPSERVER_BASE_PATH + File.separator + "test-new-two" );
54 managedRepositoryAdmin.addManagedRepository( managedRepositoryOne, false, getFakeAuditInformation() );
56 managedRepositoryAdmin.addManagedRepository( managedRepositoryTwo, false, getFakeAuditInformation() );
58 RepositoryGroup repositoryGroup =
59 new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one", "test-new-two" ) );
61 mockAuditListener.clearEvents();
63 repositoryGroupAdmin.addRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
65 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() );
66 assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() );
67 assertEquals( 2, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
68 assertEquals( Arrays.asList( "test-new-one", "test-new-two" ),
69 repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
71 // verify if default values were saved
72 assertEquals(30, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexTtl() );
73 assertEquals(".indexer", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexPath() );
75 repositoryGroupAdmin.deleteRepositoryGroup( "repo-group-one", getFakeAuditInformation() );
77 assertEquals( 0, repositoryGroupAdmin.getRepositoriesGroups().size() );
79 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
81 assertEquals( AuditEvent.ADD_REPO_GROUP, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
82 assertEquals( AuditEvent.DELETE_REPO_GROUP, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
86 mockAuditListener.clearEvents();
87 managedRepositoryAdmin.deleteManagedRepository( "test-new-one", getFakeAuditInformation(), true );
88 managedRepositoryAdmin.deleteManagedRepository( "test-new-two", getFakeAuditInformation(), true );
93 public void addAndUpdateAndDeleteGroup()
98 ManagedRepository managedRepositoryOne =
99 getTestManagedRepository( "test-new-one", APPSERVER_BASE_PATH + File.separator + "test-new-one" );
101 ManagedRepository managedRepositoryTwo =
102 getTestManagedRepository( "test-new-two", APPSERVER_BASE_PATH + File.separator + "test-new-two" );
104 managedRepositoryAdmin.addManagedRepository( managedRepositoryOne, false, getFakeAuditInformation() );
106 managedRepositoryAdmin.addManagedRepository( managedRepositoryTwo, false, getFakeAuditInformation() );
108 RepositoryGroup repositoryGroup = new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one" ) )
109 .mergedIndexTtl( 20 ).mergedIndexPath( "/.nonDefaultPath" );
111 mockAuditListener.clearEvents();
113 repositoryGroupAdmin.addRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
115 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() );
116 assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() );
117 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
118 assertEquals( Arrays.asList( "test-new-one" ),
119 repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
120 assertEquals( 20, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexTtl() );
121 assertEquals( "/.nonDefaultPath", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexPath() );
123 repositoryGroup = repositoryGroupAdmin.getRepositoryGroup( "repo-group-one" );
124 assertNotNull( repositoryGroup );
126 repositoryGroup.addRepository( managedRepositoryTwo.getId() );
128 repositoryGroupAdmin.updateRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
130 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() );
131 assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() );
132 assertEquals( 2, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
133 assertEquals( Arrays.asList( "test-new-one", "test-new-two" ),
134 repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
136 repositoryGroupAdmin.deleteRepositoryGroup( "repo-group-one", getFakeAuditInformation() );
138 assertEquals( 0, repositoryGroupAdmin.getRepositoriesGroups().size() );
140 assertEquals( 3, mockAuditListener.getAuditEvents().size() );
142 assertEquals( AuditEvent.ADD_REPO_GROUP, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
143 assertEquals( AuditEvent.MODIFY_REPO_GROUP, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
144 assertEquals( AuditEvent.DELETE_REPO_GROUP, mockAuditListener.getAuditEvents().get( 2 ).getAction() );
148 mockAuditListener.clearEvents();
149 managedRepositoryAdmin.deleteManagedRepository( "test-new-one", getFakeAuditInformation(), true );
150 managedRepositoryAdmin.deleteManagedRepository( "test-new-two", getFakeAuditInformation(), true );
155 public void addAndDeleteGroupWithRemovedManagedRepo()
160 ManagedRepository managedRepositoryOne =
161 getTestManagedRepository( "test-new-one", APPSERVER_BASE_PATH + File.separator + "test-new-one" );
163 ManagedRepository managedRepositoryTwo =
164 getTestManagedRepository( "test-new-two", APPSERVER_BASE_PATH + File.separator + "test-new-two" );
166 managedRepositoryAdmin.addManagedRepository( managedRepositoryOne, false, getFakeAuditInformation() );
168 managedRepositoryAdmin.addManagedRepository( managedRepositoryTwo, false, getFakeAuditInformation() );
170 RepositoryGroup repositoryGroup =
171 new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one", "test-new-two" ) );
173 mockAuditListener.clearEvents();
175 repositoryGroupAdmin.addRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
177 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() );
178 assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() );
179 assertEquals( 2, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
180 assertEquals( Arrays.asList( "test-new-one", "test-new-two" ),
181 repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
183 // deleting a managed repo to validate repogroup correctly updated !
184 managedRepositoryAdmin.deleteManagedRepository( "test-new-one", getFakeAuditInformation(), true );
186 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() );
187 assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() );
188 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
189 assertEquals( Arrays.asList( "test-new-two" ),
190 repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
192 repositoryGroupAdmin.deleteRepositoryGroup( "repo-group-one", getFakeAuditInformation() );
194 assertEquals( 0, repositoryGroupAdmin.getRepositoriesGroups().size() );
196 assertEquals( 3, mockAuditListener.getAuditEvents().size() );
198 assertEquals( AuditEvent.ADD_REPO_GROUP, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
199 assertEquals( AuditEvent.DELETE_MANAGED_REPO, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
200 assertEquals( AuditEvent.DELETE_REPO_GROUP, mockAuditListener.getAuditEvents().get( 2 ).getAction() );
204 mockAuditListener.clearEvents();
206 managedRepositoryAdmin.deleteManagedRepository( "test-new-two", getFakeAuditInformation(), true );
210 @Test( expected = RepositoryAdminException.class )
211 public void testAddGroupWithInvalidMergedIndexTtl() throws Exception {
213 ManagedRepository managedRepositoryOne =
214 getTestManagedRepository( "test-new-one", APPSERVER_BASE_PATH + File.separator + "test-new-one" );
216 ManagedRepository managedRepositoryTwo =
217 getTestManagedRepository( "test-new-two", APPSERVER_BASE_PATH + File.separator + "test-new-two" );
219 managedRepositoryAdmin.addManagedRepository( managedRepositoryOne, false, getFakeAuditInformation() );
221 managedRepositoryAdmin.addManagedRepository( managedRepositoryTwo, false, getFakeAuditInformation() );
223 RepositoryGroup repositoryGroup =
224 new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one", "test-new-two" ) )
225 .mergedIndexTtl( -1 );
227 mockAuditListener.clearEvents();
229 repositoryGroupAdmin.addRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
233 mockAuditListener.clearEvents();
234 managedRepositoryAdmin.deleteManagedRepository( "test-new-one", getFakeAuditInformation(), true );
235 managedRepositoryAdmin.deleteManagedRepository( "test-new-two", getFakeAuditInformation(), true );
239 @Test( expected = RepositoryAdminException.class )
240 public void testAddAndUpdateGroupWithInvalidMergedIndexTtl() throws Exception {
242 ManagedRepository managedRepositoryOne =
243 getTestManagedRepository( "test-new-one", APPSERVER_BASE_PATH + File.separator + "test-new-one" );
245 ManagedRepository managedRepositoryTwo =
246 getTestManagedRepository( "test-new-two", APPSERVER_BASE_PATH + File.separator + "test-new-two" );
248 managedRepositoryAdmin.addManagedRepository( managedRepositoryOne, false, getFakeAuditInformation() );
250 managedRepositoryAdmin.addManagedRepository( managedRepositoryTwo, false, getFakeAuditInformation() );
252 RepositoryGroup repositoryGroup =
253 new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one", "test-new-two" ) );
255 mockAuditListener.clearEvents();
257 repositoryGroupAdmin.addRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
259 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() );
260 assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() );
261 assertEquals( 2, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
262 assertEquals( Arrays.asList( "test-new-one", "test-new-two" ),
263 repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
265 // verify if default values were saved
266 assertEquals(30, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexTtl() );
267 assertEquals(".indexer", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getMergedIndexPath() );
269 repositoryGroup = repositoryGroupAdmin.getRepositoryGroup( "repo-group-one" );
270 assertNotNull( repositoryGroup );
272 repositoryGroup.mergedIndexTtl( -1 );
274 repositoryGroupAdmin.updateRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
278 mockAuditListener.clearEvents();
279 managedRepositoryAdmin.deleteManagedRepository( "test-new-one", getFakeAuditInformation(), true );
280 managedRepositoryAdmin.deleteManagedRepository( "test-new-two", getFakeAuditInformation(), true );