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 org.apache.archiva.admin.model.RepositoryCommonValidator;
23 import org.apache.archiva.admin.model.beans.ManagedRepository;
24 import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
25 import org.apache.archiva.admin.repository.DefaultRepositoryCommonValidator;
26 import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
27 import org.apache.archiva.common.utils.BaseFile;
28 import org.apache.archiva.configuration.ArchivaConfiguration;
29 import org.apache.archiva.configuration.FileType;
30 import org.apache.archiva.configuration.FileTypes;
31 import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
32 import org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate;
33 import org.apache.archiva.metadata.model.ArtifactMetadata;
34 import org.apache.archiva.metadata.model.MetadataFacet;
35 import org.apache.archiva.metadata.model.facets.RepositoryProblemFacet;
36 import org.apache.archiva.mock.MockRepositorySessionFactory;
37 import org.apache.commons.io.FileUtils;
38 import org.custommonkey.xmlunit.XMLAssert;
39 import org.junit.After;
40 import org.junit.Before;
41 import org.junit.Test;
42 import org.mockito.ArgumentCaptor;
43 import org.springframework.test.context.ContextConfiguration;
44 import sun.awt.image.ImageWatched;
47 import java.io.IOException;
48 import java.nio.charset.Charset;
49 import java.nio.file.Files;
50 import java.nio.file.LinkOption;
51 import java.nio.file.Path;
52 import java.util.ArrayList;
53 import java.util.HashSet;
54 import java.util.List;
56 import java.util.stream.Collectors;
58 import static com.sun.imageio.plugins.jpeg.JPEG.version;
59 import static org.junit.Assert.assertEquals;
60 import static org.junit.Assert.assertFalse;
61 import static org.junit.Assert.assertTrue;
62 import static org.mockito.Matchers.any;
63 import static org.mockito.Matchers.eq;
64 import static org.mockito.Mockito.*;
68 @ContextConfiguration (
69 locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-purge-consumer-test.xml" } )
70 public class RepositoryPurgeConsumerTest
71 extends AbstractRepositoryPurgeTest
80 MockRepositorySessionFactory factory = applicationContext.getBean( MockRepositorySessionFactory.class );
81 factory.setRepository( metadataRepository );
86 public void tearDown()
93 public void testConsumption()
96 assertNotConsumed( "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata.xml" );
101 public void testConsumptionOfOtherMetadata()
104 assertNotConsumed( "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata-central.xml" );
108 private void cleanupFileTypes()
110 ArchivaConfiguration archivaConfiguration =
111 applicationContext.getBean( "archivaConfiguration#default", ArchivaConfiguration.class );
113 FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
114 fileType.removePattern( "**/*.xml" );
117 private void assertNotConsumed( String path )
120 ArchivaConfiguration archivaConfiguration =
121 applicationContext.getBean( "archivaConfiguration#default", ArchivaConfiguration.class );
123 FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
124 assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
125 fileType.addPattern( "**/*.xml" );
128 //FileTypes fileTypes = applicationContext.getBean( FileTypes.class );
129 for ( FileTypes fileTypes : applicationContext.getBeansOfType( FileTypes.class ).values() )
131 fileTypes.afterConfigurationChange( null, "repositoryScanning.fileTypes", null );
133 KnownRepositoryContentConsumer repoPurgeConsumer =
134 applicationContext.getBean( "knownRepositoryContentConsumer#repository-purge",
135 KnownRepositoryContentConsumer.class );
137 File repoLocation = new File( "target/test-" + getName() + "/test-repo" );
139 File localFile = new File( repoLocation, path );
141 ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
142 BaseFile baseFile = new BaseFile( repoLocation, localFile );
143 predicate.setBasefile( baseFile );
145 assertFalse( predicate.evaluate( repoPurgeConsumer ) );
148 private void setLastModified( String path )
150 File dir = new File( path );
151 File[] contents = dir.listFiles();
152 for ( int i = 0; i < contents.length; i++ )
154 contents[i].setLastModified( 1179382029 );
159 public void testConsumerByRetentionCount()
162 KnownRepositoryContentConsumer repoPurgeConsumer =
163 applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-retention-count",
164 KnownRepositoryContentConsumer.class );
166 ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME );
167 repoConfiguration.setDaysOlder( 0 ); // force days older off to allow retention count purge to execute.
168 repoConfiguration.setRetentionCount( TEST_RETENTION_COUNT );
169 addRepoToConfiguration( "retention-count", repoConfiguration );
171 repoPurgeConsumer.beginScan( repoConfiguration, null );
173 String repoRoot = prepareTestRepos();
174 String projectNs = "org.jruby.plugins";
175 String projectPath = projectNs.replaceAll("\\.","/");
176 String projectName = "jruby-rake-plugin";
177 String projectVersion = "1.0RC1-SNAPSHOT";
178 String projectRoot = repoRoot + "/" + projectPath+"/"+projectName;
179 String versionRoot = projectRoot + "/" + projectVersion;
181 Path repo = getTestRepoRootPath();
182 Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
184 // Provide the metadata list
185 List<ArtifactMetadata> ml = getArtifactMetadataFromDir( TEST_REPO_ID, projectName, repo, vDir );
186 when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs,
187 projectName, projectVersion)).thenReturn(ml);
188 Set<String> deletedVersions = new HashSet<>();
189 deletedVersions.add("1.0RC1-20070504.153317-1");
190 deletedVersions.add("1.0RC1-20070504.160758-2");
192 repoPurgeConsumer.processFile( PATH_TO_BY_RETENTION_COUNT_ARTIFACT );
194 // Verify the metadataRepository invocations
195 verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
196 ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
197 verify(metadataRepository, times(2)).removeArtifact(metadataArg.capture(), eq(projectVersion));
198 List<ArtifactMetadata> metaL = metadataArg.getAllValues();
199 for (ArtifactMetadata meta : metaL) {
200 assertTrue(meta.getId().startsWith(projectName));
201 assertTrue(deletedVersions.contains(meta.getVersion()));
206 // assert if removed from repo
207 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar" );
208 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1-javadoc.jar" );
209 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1-javadoc.zip" );
210 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.md5" );
211 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.sha1" );
212 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom" );
213 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.md5" );
214 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.sha1" );
216 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar" );
217 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2-javadoc.jar" );
218 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2-javadoc.zip" );
219 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.md5" );
220 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.sha1" );
221 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom" );
222 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.md5" );
223 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.sha1" );
225 // assert if not removed from repo
226 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar" );
227 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3-javadoc.jar" );
228 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3-javadoc.zip" );
229 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.md5" );
230 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.sha1" );
231 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom" );
232 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.md5" );
233 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.sha1" );
235 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar" );
236 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.md5" );
237 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.sha1" );
238 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom" );
239 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.md5" );
240 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.sha1" );
242 removeRepoFromConfiguration( "retention-count", repoConfiguration );
245 private void addRepoToConfiguration( String configHint, ManagedRepository repoConfiguration )
248 ArchivaConfiguration archivaConfiguration =
249 applicationContext.getBean( "archivaConfiguration#" + configHint, ArchivaConfiguration.class );
250 ( (DefaultManagedRepositoryAdmin) applicationContext.getBean(
251 ManagedRepositoryAdmin.class ) ).setArchivaConfiguration( archivaConfiguration );
252 // skygo: Default Validator was not looking at same config
253 ( (DefaultRepositoryCommonValidator) applicationContext.getBean(
254 RepositoryCommonValidator.class ) ).setArchivaConfiguration( archivaConfiguration );
255 ManagedRepositoryAdmin managedRepositoryAdmin = applicationContext.getBean( ManagedRepositoryAdmin.class );
256 if ( managedRepositoryAdmin.getManagedRepository( repoConfiguration.getId() ) != null )
258 managedRepositoryAdmin.deleteManagedRepository( repoConfiguration.getId(), null, false );
260 managedRepositoryAdmin.addManagedRepository( repoConfiguration, false, null );
263 private void removeRepoFromConfiguration( String configHint, ManagedRepository repoConfiguration )
266 ArchivaConfiguration archivaConfiguration =
267 applicationContext.getBean( "archivaConfiguration#" + configHint, ArchivaConfiguration.class );
269 ( (DefaultManagedRepositoryAdmin) applicationContext.getBean(
270 ManagedRepositoryAdmin.class ) ).setArchivaConfiguration( archivaConfiguration );
271 // skygo: Default Validator was not looking at same config
272 ( (DefaultRepositoryCommonValidator) applicationContext.getBean(
273 RepositoryCommonValidator.class ) ).setArchivaConfiguration( archivaConfiguration );
274 ManagedRepositoryAdmin managedRepositoryAdmin = applicationContext.getBean( ManagedRepositoryAdmin.class );
275 if ( managedRepositoryAdmin.getManagedRepository( repoConfiguration.getId() ) != null )
277 managedRepositoryAdmin.deleteManagedRepository( repoConfiguration.getId(), null, true );
282 public void testConsumerByDaysOld()
285 KnownRepositoryContentConsumer repoPurgeConsumer =
286 applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-days-old",
287 KnownRepositoryContentConsumer.class );
289 ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME );
290 repoConfiguration.setDaysOlder( TEST_DAYS_OLDER );
291 addRepoToConfiguration( "days-old", repoConfiguration );
293 repoPurgeConsumer.beginScan( repoConfiguration, null );
295 String repoRoot = prepareTestRepos();
296 String projectNs = "org.apache.maven.plugins";
297 String projectPath = projectNs.replaceAll("\\.","/");
298 String projectName = "maven-install-plugin";
299 String projectVersion = "2.2-SNAPSHOT";
300 String projectRoot = repoRoot + "/" + projectPath+"/"+projectName;
302 setLastModified( projectRoot + "/"+projectVersion);
305 Path repo = getTestRepoRootPath();
306 Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
308 // Provide the metadata list
309 List<ArtifactMetadata> ml = getArtifactMetadataFromDir( TEST_REPO_ID, projectName, repo, vDir );
310 when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs,
311 projectName, projectVersion)).thenReturn(ml);
312 Set<String> deletedVersions = new HashSet<>();
313 deletedVersions.add("2.2-SNAPSHOT");
314 deletedVersions.add("2.2-20061118.060401-2");
316 repoPurgeConsumer.processFile( PATH_TO_BY_DAYS_OLD_ARTIFACT );
318 // Verify the metadataRepository invocations
319 verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
320 ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
321 verify(metadataRepository, times(2)).removeArtifact(metadataArg.capture(), eq(projectVersion));
322 List<ArtifactMetadata> metaL = metadataArg.getAllValues();
323 for (ArtifactMetadata meta : metaL) {
324 assertTrue(meta.getId().startsWith(projectName));
325 assertTrue(deletedVersions.contains(meta.getVersion()));
328 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar" );
329 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.md5" );
330 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.sha1" );
331 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom" );
332 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.md5" );
333 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.sha1" );
335 // shouldn't be deleted because even if older than 30 days (because retention count = 2)
336 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar" );
337 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar.md5" );
338 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar.sha1" );
339 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom" );
340 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.md5" );
341 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.sha1" );
343 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar" );
344 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.md5" );
345 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.sha1" );
346 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom" );
347 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.md5" );
348 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.sha1" );
350 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar" );
351 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.md5" );
352 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.sha1" );
353 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom" );
354 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.md5" );
355 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.sha1" );
357 removeRepoFromConfiguration( "days-old", repoConfiguration );
361 * Test the snapshot clean consumer on a repository set to NOT clean/delete snapshots based on released versions.
366 public void testReleasedSnapshotsWereNotCleaned()
369 KnownRepositoryContentConsumer repoPurgeConsumer =
370 applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-retention-count",
371 KnownRepositoryContentConsumer.class );
373 ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME );
374 repoConfiguration.setDeleteReleasedSnapshots( false ); // Set to NOT delete released snapshots.
375 addRepoToConfiguration( "retention-count", repoConfiguration );
377 repoPurgeConsumer.beginScan( repoConfiguration, null );
379 String repoRoot = prepareTestRepos();
380 String projectNs = "org.apache.maven.plugins";
381 String projectPath = projectNs.replaceAll("\\.","/");
382 String projectName = "maven-plugin-plugin";
383 String projectVersion = "2.3-SNAPSHOT";
384 String projectRoot = repoRoot + "/" + projectPath+"/"+projectName;
386 Path repo = getTestRepoRootPath();
387 Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
389 // Provide the metadata list
390 List<ArtifactMetadata> ml = getArtifactMetadataFromDir( TEST_REPO_ID, projectName, repo, vDir );
391 when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs,
392 projectName, projectVersion)).thenReturn(ml);
394 repoPurgeConsumer.processFile(
395 CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO );
397 verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
398 ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
399 verify(metadataRepository, never()).removeArtifact(any(), any());
400 verify(metadataRepository, never()).removeArtifact( any(), any(), any(), any(), any(MetadataFacet.class) );
402 // check if the snapshot wasn't removed
404 assertExists( projectRoot + "/2.3-SNAPSHOT" );
405 assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar" );
406 assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.md5" );
407 assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.sha1" );
408 assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom" );
409 assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.md5" );
410 assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.sha1" );
412 // check if metadata file wasn't updated
413 File artifactMetadataFile = new File( projectRoot + "/maven-metadata.xml" );
415 String metadataXml = FileUtils.readFileToString( artifactMetadataFile, Charset.defaultCharset() );
417 String expectedVersions = "<expected><versions><version>2.3-SNAPSHOT</version></versions></expected>";
419 XMLAssert.assertXpathEvaluatesTo( "2.3-SNAPSHOT", "//metadata/versioning/latest", metadataXml );
420 XMLAssert.assertXpathsEqual( "//expected/versions/version", expectedVersions,
421 "//metadata/versioning/versions/version", metadataXml );
422 XMLAssert.assertXpathEvaluatesTo( "20070315032817", "//metadata/versioning/lastUpdated", metadataXml );
424 removeRepoFromConfiguration( "retention-count", repoConfiguration );
428 public void testReleasedSnapshotsWereCleaned()
431 KnownRepositoryContentConsumer repoPurgeConsumer =
432 applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-days-old",
433 KnownRepositoryContentConsumer.class );
435 ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME );
436 repoConfiguration.setDeleteReleasedSnapshots( true );
437 addRepoToConfiguration( "days-old", repoConfiguration );
439 repoPurgeConsumer.beginScan( repoConfiguration, null );
441 String repoRoot = prepareTestRepos();
442 String projectNs = "org.apache.maven.plugins";
443 String projectPath = projectNs.replaceAll("\\.","/");
444 String projectName = "maven-plugin-plugin";
445 String projectVersion = "2.3-SNAPSHOT";
446 String projectRoot = repoRoot + "/" + projectPath+"/"+projectName;
447 Path repo = getTestRepoRootPath();
448 Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
450 // Provide the metadata list
451 List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
452 when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs,
453 projectName, projectVersion)).thenReturn(ml);
455 repoPurgeConsumer.processFile(
456 CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO );
458 verify(metadataRepository, times(1)).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
459 ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
460 verify(metadataRepository, never()).removeArtifact(any(), any());
462 // check if the snapshot was removed
463 assertDeleted( projectRoot + "/2.3-SNAPSHOT" );
464 assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar" );
465 assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.md5" );
466 assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.sha1" );
467 assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom" );
468 assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.md5" );
469 assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.sha1" );
471 // check if metadata file was updated
472 File artifactMetadataFile = new File( projectRoot + "/maven-metadata.xml" );
474 String metadataXml = FileUtils.readFileToString( artifactMetadataFile, Charset.defaultCharset() );
476 String expectedVersions =
477 "<expected><versions><version>2.2</version>" + "<version>2.3</version></versions></expected>";
479 XMLAssert.assertXpathEvaluatesTo( "2.3", "//metadata/versioning/latest", metadataXml );
480 XMLAssert.assertXpathsEqual( "//expected/versions/version", expectedVersions,
481 "//metadata/versioning/versions/version", metadataXml );
482 XMLAssert.assertXpathEvaluatesTo( "20070315032817", "//metadata/versioning/lastUpdated", metadataXml );
484 removeRepoFromConfiguration( "days-old", repoConfiguration );