1 package org.apache.archiva.consumers.core.repository;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import java.nio.file.Path;
23 import java.util.Collections;
24 import java.util.HashSet;
25 import java.util.List;
28 import org.apache.archiva.admin.model.beans.ManagedRepository;
29 import org.apache.archiva.metadata.model.ArtifactMetadata;
30 import org.apache.archiva.repository.events.RepositoryListener;
31 import org.junit.After;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.mockito.ArgumentCaptor;
36 import static org.junit.Assert.assertTrue;
37 import static org.mockito.Matchers.eq;
38 import static org.mockito.Mockito.*;
41 * Test RetentionsCountRepositoryPurgeTest
43 public class RetentionCountRepositoryPurgeTest
44 extends AbstractRepositoryPurgeTest
53 ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME );
54 List<RepositoryListener> listeners = Collections.singletonList( listener );
55 repoPurge = new RetentionCountRepositoryPurge( getRepository(), repoConfiguration.getRetentionCount(),
56 repositorySession, listeners );
61 public void tearDown()
68 * Test if the artifact to be processed was a jar.
71 public void testIfAJarWasFound()
74 String repoRoot = prepareTestRepos();
75 String projectNs = "org.jruby.plugins";
76 String projectPath = projectNs.replaceAll("\\.","/");
77 String projectName = "jruby-rake-plugin";
78 String projectVersion = "1.0RC1-SNAPSHOT";
79 String projectRoot = repoRoot + "/" + projectPath+"/"+projectName;
80 Path repo = getTestRepoRootPath();
81 Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
82 Set<String> deletedVersions = new HashSet<>();
83 deletedVersions.add("1.0RC1-20070504.153317-1");
84 deletedVersions.add("1.0RC1-20070504.160758-2");
85 String versionRoot = projectRoot + "/" + projectVersion;
87 // test listeners for the correct artifacts
88 listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
89 "1.0RC1-20070504.153317-1", "jruby-rake-plugin-1.0RC1-20070504.153317-1.jar" );
90 listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
91 "1.0RC1-20070504.153317-1", "jruby-rake-plugin-1.0RC1-20070504.153317-1.pom" );
92 listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
93 "1.0RC1-20070504.153317-1", "jruby-rake-plugin-1.0RC1-20070504.153317-1-javadoc.jar" );
95 listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
96 "1.0RC1-20070504.153317-1", "jruby-rake-plugin-1.0RC1-20070504.153317-1-javadoc.zip" );
98 listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
99 "1.0RC1-20070504.160758-2", "jruby-rake-plugin-1.0RC1-20070504.160758-2.jar" );
101 listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
102 "1.0RC1-20070504.160758-2", "jruby-rake-plugin-1.0RC1-20070504.160758-2-javadoc.jar" );
104 listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
105 "1.0RC1-20070504.160758-2", "jruby-rake-plugin-1.0RC1-20070504.160758-2-javadoc.zip" );
107 listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
108 "1.0RC1-20070504.160758-2", "jruby-rake-plugin-1.0RC1-20070504.160758-2.pom" );
109 listenerControl.replay();
111 // Provide the metadata list
112 List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
113 when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs,
114 projectName, projectVersion)).thenReturn(ml);
117 repoPurge.process( PATH_TO_BY_RETENTION_COUNT_ARTIFACT );
119 listenerControl.verify();
121 // Verify the metadataRepository invocations
122 verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
123 ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
124 verify(metadataRepository, times(deletedVersions.size())).removeArtifact(metadataArg.capture(), eq(projectVersion));
125 List<ArtifactMetadata> metaL = metadataArg.getAllValues();
126 for (ArtifactMetadata meta : metaL) {
127 assertTrue(meta.getId().startsWith(projectName));
128 assertTrue(deletedVersions.contains(meta.getVersion()));
132 // assert if removed from repo
133 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar" );
134 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.md5" );
135 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.sha1" );
136 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom" );
137 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.md5" );
138 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.sha1" );
140 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar" );
141 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.md5" );
142 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.sha1" );
143 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom" );
144 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.md5" );
145 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.sha1" );
147 // assert if not removed from repo
148 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar" );
149 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.md5" );
150 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.sha1" );
151 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom" );
152 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.md5" );
153 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.sha1" );
155 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar" );
156 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.md5" );
157 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.sha1" );
158 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom" );
159 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.md5" );
160 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.sha1" );
164 * Test if the artifact to be processed is a pom
167 public void testIfAPomWasFound()
170 String repoRoot = prepareTestRepos();
171 String projectNs = "org.codehaus.castor";
172 String projectPath = projectNs.replaceAll("\\.","/");
173 String projectName = "castor-anttasks";
174 String projectVersion = "1.1.2-SNAPSHOT";
175 String projectRoot = repoRoot + "/" + projectPath+"/"+projectName;
176 Path repo = getTestRepoRootPath();
177 Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
178 Set<String> deletedVersions = new HashSet<>();
179 deletedVersions.add("1.1.2-20070427.065136-1");
180 String versionRoot = projectRoot + "/" + projectVersion;
183 // test listeners for the correct artifacts
184 listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.castor", "castor-anttasks",
185 "1.1.2-20070427.065136-1", "castor-anttasks-1.1.2-20070427.065136-1.jar" );
186 listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.castor", "castor-anttasks",
187 "1.1.2-20070427.065136-1", "castor-anttasks-1.1.2-20070427.065136-1.pom" );
188 listenerControl.replay();
190 // Provide the metadata list
191 List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
192 when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs,
193 projectName, projectVersion)).thenReturn(ml);
195 repoPurge.process( PATH_TO_BY_RETENTION_COUNT_POM );
197 listenerControl.verify();
199 // Verify the metadataRepository invocations
200 verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
201 ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
202 verify(metadataRepository, times(deletedVersions.size())).removeArtifact(metadataArg.capture(), eq(projectVersion));
203 List<ArtifactMetadata> metaL = metadataArg.getAllValues();
204 for (ArtifactMetadata meta : metaL) {
205 assertTrue(meta.getId().startsWith(projectName));
206 assertTrue(deletedVersions.contains(meta.getVersion()));
210 // assert if removed from repo
211 assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar" );
212 assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar.md5" );
213 assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar.sha1" );
214 assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom" );
215 assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom.md5" );
216 assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom.sha1" );
218 // assert if not removed from repo
219 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom" );
220 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom.md5" );
221 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom.sha1" );
222 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar" );
223 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar.md5" );
224 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar.sha1" );
225 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar" );
226 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar.md5" );
227 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar.sha1" );
229 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom" );
230 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom.md5" );
231 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom.sha1" );
232 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar" );
233 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar.md5" );
234 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar.sha1" );
235 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar" );
236 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar.md5" );
237 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar.sha1" );
241 public void testOrderOfDeletion()
244 String repoRoot = prepareTestRepos();
245 String projectNs = "org.apache.maven.plugins";
246 String projectPath = projectNs.replaceAll("\\.","/");
247 String projectName = "maven-assembly-plugin";
248 String projectVersion = "1.1.2-SNAPSHOT";
249 String projectRoot = repoRoot + "/" + projectPath+"/"+projectName;
250 Path repo = getTestRepoRootPath();
251 Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
252 Set<String> deletedVersions = new HashSet<>();
253 deletedVersions.add("1.1.2-20070427.065136-1");
254 String versionRoot = projectRoot + "/" + projectVersion;
257 // test listeners for the correct artifacts
258 listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins",
259 "maven-assembly-plugin", "1.1.2-20070427.065136-1",
260 "maven-assembly-plugin-1.1.2-20070427.065136-1.jar" );
261 listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins",
262 "maven-assembly-plugin", "1.1.2-20070427.065136-1",
263 "maven-assembly-plugin-1.1.2-20070427.065136-1.pom" );
264 listenerControl.replay();
266 // Provide the metadata list
267 List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
268 when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs,
269 projectName, projectVersion)).thenReturn(ml);
271 repoPurge.process( PATH_TO_TEST_ORDER_OF_DELETION );
273 listenerControl.verify();
275 // Verify the metadataRepository invocations
276 verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
277 ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
278 verify(metadataRepository, times(deletedVersions.size())).removeArtifact(metadataArg.capture(), eq(projectVersion));
279 List<ArtifactMetadata> metaL = metadataArg.getAllValues();
280 for (ArtifactMetadata meta : metaL) {
281 assertTrue(meta.getId().startsWith(projectName));
282 assertTrue(deletedVersions.contains(meta.getVersion()));
286 assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar" );
287 assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.sha1" );
288 assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.md5" );
289 assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.pom" );
290 assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.sha1" );
291 assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.md5" );
293 // the following should not have been deleted
294 assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.jar" );
295 assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.sha1" );
296 assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.md5" );
297 assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.pom" );
298 assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.sha1" );
299 assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.md5" );
301 assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.jar" );
302 assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.sha1" );
303 assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.md5" );
304 assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.pom" );
305 assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.sha1" );
306 assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.md5" );