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.repository.AbstractRepositoryAdminTest;
22 import org.apache.archiva.admin.repository.managed.ManagedRepository;
23 import org.apache.archiva.audit.AuditEvent;
24 import org.junit.Test;
26 import javax.inject.Inject;
28 import java.util.Arrays;
31 * @author Olivier Lamy
33 public class RepositoryGroupAdminTest
34 extends AbstractRepositoryAdminTest
37 RepositoryGroupAdmin repositoryGroupAdmin;
40 public void addAndDeleteGroup()
45 ManagedRepository managedRepositoryOne =
46 getTestManagedRepository( "test-new-one", APPSERVER_BASE_PATH + File.separator + "test-new-one" );
48 ManagedRepository managedRepositoryTwo =
49 getTestManagedRepository( "test-new-two", APPSERVER_BASE_PATH + File.separator + "test-new-two" );
51 managedRepositoryAdmin.addManagedRepository( managedRepositoryOne, false, getFakeAuditInformation() );
53 managedRepositoryAdmin.addManagedRepository( managedRepositoryTwo, false, getFakeAuditInformation() );
55 RepositoryGroup repositoryGroup =
56 new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one", "test-new-two" ) );
58 mockAuditListener.clearEvents();
60 repositoryGroupAdmin.addRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
62 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() );
63 assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() );
64 assertEquals( 2, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
65 assertEquals( Arrays.asList( "test-new-one", "test-new-two" ),
66 repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
68 repositoryGroupAdmin.deleteRepositoryGroup( "repo-group-one", getFakeAuditInformation() );
70 assertEquals( 0, repositoryGroupAdmin.getRepositoriesGroups().size() );
72 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
74 assertEquals( AuditEvent.ADD_REPO_GROUP, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
75 assertEquals( AuditEvent.DELETE_REPO_GROUP, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
79 mockAuditListener.clearEvents();
80 managedRepositoryAdmin.deleteManagedRepository( "test-new-one", getFakeAuditInformation(), true );
81 managedRepositoryAdmin.deleteManagedRepository( "test-new-two", getFakeAuditInformation(), true );
86 public void addAndUpdateAndDeleteGroup()
91 ManagedRepository managedRepositoryOne =
92 getTestManagedRepository( "test-new-one", APPSERVER_BASE_PATH + File.separator + "test-new-one" );
94 ManagedRepository managedRepositoryTwo =
95 getTestManagedRepository( "test-new-two", APPSERVER_BASE_PATH + File.separator + "test-new-two" );
97 managedRepositoryAdmin.addManagedRepository( managedRepositoryOne, false, getFakeAuditInformation() );
99 managedRepositoryAdmin.addManagedRepository( managedRepositoryTwo, false, getFakeAuditInformation() );
101 RepositoryGroup repositoryGroup = new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one" ) );
103 mockAuditListener.clearEvents();
105 repositoryGroupAdmin.addRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
107 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() );
108 assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() );
109 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
110 assertEquals( Arrays.asList( "test-new-one" ),
111 repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
113 repositoryGroup = repositoryGroupAdmin.getRepositoryGroup( "repo-group-one" );
114 assertNotNull( repositoryGroup );
116 repositoryGroup.addRepository( managedRepositoryTwo.getId() );
118 repositoryGroupAdmin.updateRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
120 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() );
121 assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() );
122 assertEquals( 2, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
123 assertEquals( Arrays.asList( "test-new-one", "test-new-two" ),
124 repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
126 repositoryGroupAdmin.deleteRepositoryGroup( "repo-group-one", getFakeAuditInformation() );
128 assertEquals( 0, repositoryGroupAdmin.getRepositoriesGroups().size() );
130 assertEquals( 3, mockAuditListener.getAuditEvents().size() );
132 assertEquals( AuditEvent.ADD_REPO_GROUP, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
133 assertEquals( AuditEvent.MODIFY_REPO_GROUP, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
134 assertEquals( AuditEvent.DELETE_REPO_GROUP, mockAuditListener.getAuditEvents().get( 2 ).getAction() );
138 mockAuditListener.clearEvents();
139 managedRepositoryAdmin.deleteManagedRepository( "test-new-one", getFakeAuditInformation(), true );
140 managedRepositoryAdmin.deleteManagedRepository( "test-new-two", getFakeAuditInformation(), true );
146 public void addAndDeleteGroupWithRemowingManagedRepo()
151 ManagedRepository managedRepositoryOne =
152 getTestManagedRepository( "test-new-one", APPSERVER_BASE_PATH + File.separator + "test-new-one" );
154 ManagedRepository managedRepositoryTwo =
155 getTestManagedRepository( "test-new-two", APPSERVER_BASE_PATH + File.separator + "test-new-two" );
157 managedRepositoryAdmin.addManagedRepository( managedRepositoryOne, false, getFakeAuditInformation() );
159 managedRepositoryAdmin.addManagedRepository( managedRepositoryTwo, false, getFakeAuditInformation() );
161 RepositoryGroup repositoryGroup =
162 new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one", "test-new-two" ) );
164 mockAuditListener.clearEvents();
166 repositoryGroupAdmin.addRepositoryGroup( repositoryGroup, getFakeAuditInformation() );
168 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() );
169 assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() );
170 assertEquals( 2, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
171 assertEquals( Arrays.asList( "test-new-one", "test-new-two" ),
172 repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
174 // deleting a managed repo to validate repogroup correctly updated !
175 managedRepositoryAdmin.deleteManagedRepository( "test-new-one", getFakeAuditInformation(), true );
177 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() );
178 assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() );
179 assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() );
180 assertEquals( Arrays.asList( "test-new-two" ),
181 repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() );
183 repositoryGroupAdmin.deleteRepositoryGroup( "repo-group-one", getFakeAuditInformation() );
185 assertEquals( 0, repositoryGroupAdmin.getRepositoriesGroups().size() );
187 assertEquals( 3, mockAuditListener.getAuditEvents().size() );
189 assertEquals( AuditEvent.ADD_REPO_GROUP, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
190 assertEquals( AuditEvent.DELETE_MANAGED_REPO, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
191 assertEquals( AuditEvent.DELETE_REPO_GROUP, mockAuditListener.getAuditEvents().get( 2 ).getAction() );
195 mockAuditListener.clearEvents();
197 managedRepositoryAdmin.deleteManagedRepository( "test-new-two", getFakeAuditInformation(), true );