]> source.dussan.org Git - archiva.git/blob
65047eeb0b8c58f53c5d59729e4307f3a3c93698
[archiva.git] /
1 package org.apache.archiva.consumers.core.repository;
2
3 /*
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
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  * under the License.
20  */
21
22 import org.apache.archiva.common.utils.BaseFile;
23 import org.apache.archiva.configuration.ArchivaConfiguration;
24 import org.apache.archiva.configuration.FileType;
25 import org.apache.archiva.configuration.FileTypes;
26 import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
27 import org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate;
28 import org.apache.archiva.metadata.model.ArtifactMetadata;
29 import org.apache.archiva.metadata.model.MetadataFacet;
30 import org.apache.archiva.mock.MockRepositorySessionFactory;
31 import org.apache.archiva.repository.RepositoryRegistry;
32 import org.apache.archiva.repository.features.ArtifactCleanupFeature;
33 import org.custommonkey.xmlunit.XMLAssert;
34 import org.junit.After;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.mockito.ArgumentCaptor;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import org.springframework.test.context.ContextConfiguration;
41
42 import java.io.IOException;
43 import java.nio.charset.Charset;
44 import java.nio.file.Files;
45 import java.nio.file.Path;
46 import java.nio.file.Paths;
47 import java.nio.file.attribute.FileTime;
48 import java.time.Period;
49 import java.util.HashSet;
50 import java.util.List;
51 import java.util.Set;
52
53 import static org.junit.Assert.*;
54 import static org.mockito.Matchers.any;
55 import static org.mockito.Matchers.eq;
56 import static org.mockito.Mockito.*;
57
58 /**
59  */
60 @ContextConfiguration (
61     locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-purge-consumer-test.xml" } )
62 public class RepositoryPurgeConsumerTest
63     extends AbstractRepositoryPurgeTest
64 {
65     private static final Logger log = LoggerFactory.getLogger( RepositoryPurgeConsumerTest.class );
66
67     @Before
68     @Override
69     public void setUp()
70         throws Exception
71     {
72         super.setUp();
73
74         MockRepositorySessionFactory factory = applicationContext.getBean( MockRepositorySessionFactory.class );
75         factory.setRepository( metadataRepository );
76     }
77
78     @After
79     @Override
80     public void tearDown()
81         throws Exception
82     {
83         super.tearDown();
84     }
85
86     @Test
87     public void testConsumption()
88         throws Exception
89     {
90         assertNotConsumed( "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata.xml" );
91         cleanupFileTypes();
92     }
93
94     @Test
95     public void testConsumptionOfOtherMetadata()
96         throws Exception
97     {
98         assertNotConsumed( "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata-central.xml" );
99         cleanupFileTypes();
100     }
101
102     private void cleanupFileTypes()
103     {
104         ArchivaConfiguration archivaConfiguration =
105             applicationContext.getBean( "archivaConfiguration#default", ArchivaConfiguration.class );
106
107         FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
108         fileType.removePattern( "**/*.xml" );
109     }
110
111     private void assertNotConsumed( String path )
112         throws Exception
113     {
114         ArchivaConfiguration archivaConfiguration =
115             applicationContext.getBean( "archivaConfiguration#default", ArchivaConfiguration.class );
116
117         FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
118         assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
119         fileType.addPattern( "**/*.xml" );
120
121         // trigger reload
122         //FileTypes fileTypes = applicationContext.getBean( FileTypes.class );
123         for ( FileTypes fileTypes : applicationContext.getBeansOfType( FileTypes.class ).values() )
124         {
125             fileTypes.afterConfigurationChange( null, "repositoryScanning.fileTypes", null );
126         }
127         KnownRepositoryContentConsumer repoPurgeConsumer =
128             applicationContext.getBean( "knownRepositoryContentConsumer#repository-purge",
129                                         KnownRepositoryContentConsumer.class );
130
131         Path repoLocation = Paths.get( "target/test-" + getName() + "/test-repo" );
132
133         Path localFile = repoLocation.resolve( path );
134
135         ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
136         BaseFile baseFile = new BaseFile( repoLocation.toFile(), localFile.toFile() );
137         predicate.setBasefile( baseFile );
138
139         assertFalse( predicate.evaluate( repoPurgeConsumer ) );
140     }
141
142     private void setLastModified( String path ) throws IOException
143     {
144         Path dir = Paths.get( path );
145         Path[] contents = new Path[0];
146         try
147         {
148             contents = Files.list( dir ).toArray(Path[]::new);
149         }
150         catch ( IOException e )
151         {
152             log.error("Could not list files {}: {}", dir, e.getMessage(), e);
153             contents = new Path[0];
154         }
155         for ( int i = 0; i < contents.length; i++ )
156         {
157             Files.setLastModifiedTime( contents[i], FileTime.fromMillis( 1179382029 ) );
158         }
159     }
160
161     @Test
162     public void testConsumerByRetentionCount()
163         throws Exception
164     {
165         KnownRepositoryContentConsumer repoPurgeConsumer =
166             applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-retention-count",
167                                         KnownRepositoryContentConsumer.class );
168
169         org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME );
170         ArtifactCleanupFeature atf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get();
171         atf.setRetentionPeriod( Period.ofDays( 0 ) ); // force days older off to allow retention count purge to execute.
172         atf.setRetentionCount( TEST_RETENTION_COUNT );
173         addRepoToConfiguration( "retention-count", repoConfiguration );
174
175         repoPurgeConsumer.beginScan( repoConfiguration, null );
176
177         String repoRoot = prepareTestRepos();
178         String projectNs = "org.jruby.plugins";
179         String projectPath = projectNs.replaceAll("\\.","/");
180         String projectName = "jruby-rake-plugin";
181         String projectVersion = "1.0RC1-SNAPSHOT";
182         String projectRoot = repoRoot + "/" + projectPath+"/"+projectName;
183         String versionRoot = projectRoot + "/" + projectVersion;
184
185         Path repo = getTestRepoRootPath();
186         Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
187
188         // Provide the metadata list
189         List<ArtifactMetadata> ml = getArtifactMetadataFromDir( TEST_REPO_ID, projectName, repo, vDir );
190         when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs,
191             projectName, projectVersion)).thenReturn(ml);
192         Set<String> deletedVersions = new HashSet<>();
193         deletedVersions.add("1.0RC1-20070504.153317-1");
194         deletedVersions.add("1.0RC1-20070504.160758-2");
195
196         repoPurgeConsumer.processFile( PATH_TO_BY_RETENTION_COUNT_ARTIFACT );
197
198         // Verify the metadataRepository invocations
199         verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
200         ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
201         verify(metadataRepository, times(2)).removeArtifact(metadataArg.capture(), eq(projectVersion));
202         List<ArtifactMetadata> metaL = metadataArg.getAllValues();
203         for (ArtifactMetadata meta : metaL) {
204             assertTrue(meta.getId().startsWith(projectName));
205             assertTrue(deletedVersions.contains(meta.getVersion()));
206         }
207
208
209
210         // assert if removed from repo
211         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar" );
212         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1-javadoc.jar" );
213         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1-javadoc.zip" );
214         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.md5" );
215         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.sha1" );
216         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom" );
217         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.md5" );
218         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.sha1" );
219
220         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar" );
221         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2-javadoc.jar" );
222         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2-javadoc.zip" );
223         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.md5" );
224         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.sha1" );
225         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom" );
226         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.md5" );
227         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.sha1" );
228
229         // assert if not removed from repo
230         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar" );
231         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3-javadoc.jar" );
232         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3-javadoc.zip" );
233         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.md5" );
234         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.sha1" );
235         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom" );
236         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.md5" );
237         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.sha1" );
238
239         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar" );
240         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.md5" );
241         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.sha1" );
242         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom" );
243         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.md5" );
244         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.sha1" );
245
246         removeRepoFromConfiguration( "retention-count", repoConfiguration );
247     }
248
249     private void addRepoToConfiguration( String configHint, org.apache.archiva.repository.ManagedRepository repoConfiguration )
250         throws Exception
251     {
252         RepositoryRegistry repositoryRegistry = applicationContext.getBean(RepositoryRegistry.class);
253         repositoryRegistry.putRepository( repoConfiguration );
254     }
255
256     private void removeRepoFromConfiguration( String configHint, org.apache.archiva.repository.ManagedRepository repoConfiguration )
257         throws Exception
258     {
259         RepositoryRegistry repositoryRegistry = applicationContext.getBean(RepositoryRegistry.class);
260         repositoryRegistry.removeRepository( repoConfiguration );
261     }
262
263     @Test
264     public void testConsumerByDaysOld()
265         throws Exception
266     {
267         KnownRepositoryContentConsumer repoPurgeConsumer =
268             applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-days-old",
269                                         KnownRepositoryContentConsumer.class );
270
271         org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME );
272         ArtifactCleanupFeature atf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get();
273         atf.setRetentionPeriod( Period.ofDays( TEST_DAYS_OLDER ) );
274         addRepoToConfiguration( "days-old", repoConfiguration );
275
276         repoPurgeConsumer.beginScan( repoConfiguration, null );
277
278         String repoRoot = prepareTestRepos();
279         String projectNs = "org.apache.maven.plugins";
280         String projectPath = projectNs.replaceAll("\\.","/");
281         String projectName = "maven-install-plugin";
282         String projectVersion = "2.2-SNAPSHOT";
283         String projectRoot = repoRoot + "/" + projectPath+"/"+projectName;
284
285         setLastModified( projectRoot + "/"+projectVersion);
286
287
288         Path repo = getTestRepoRootPath();
289         Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
290
291         // Provide the metadata list
292         List<ArtifactMetadata> ml = getArtifactMetadataFromDir( TEST_REPO_ID, projectName, repo, vDir );
293         when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs,
294                 projectName, projectVersion)).thenReturn(ml);
295         Set<String> deletedVersions = new HashSet<>();
296         deletedVersions.add("2.2-SNAPSHOT");
297         deletedVersions.add("2.2-20061118.060401-2");
298
299         repoPurgeConsumer.processFile( PATH_TO_BY_DAYS_OLD_ARTIFACT );
300
301         // Verify the metadataRepository invocations
302         verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
303         ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
304         verify(metadataRepository, times(2)).removeArtifact(metadataArg.capture(), eq(projectVersion));
305         List<ArtifactMetadata> metaL = metadataArg.getAllValues();
306         for (ArtifactMetadata meta : metaL) {
307             assertTrue(meta.getId().startsWith(projectName));
308             assertTrue(deletedVersions.contains(meta.getVersion()));
309         }
310
311         assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar" );
312         assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.md5" );
313         assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.sha1" );
314         assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom" );
315         assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.md5" );
316         assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.sha1" );
317
318         // shouldn't be deleted because even if older than 30 days (because retention count = 2)
319         assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar" );
320         assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar.md5" );
321         assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar.sha1" );
322         assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom" );
323         assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.md5" );
324         assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.sha1" );
325
326         assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar" );
327         assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.md5" );
328         assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.sha1" );
329         assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom" );
330         assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.md5" );
331         assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.sha1" );
332
333         assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar" );
334         assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.md5" );
335         assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.sha1" );
336         assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom" );
337         assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.md5" );
338         assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.sha1" );
339
340         removeRepoFromConfiguration( "days-old", repoConfiguration );
341     }
342
343     /**
344      * Test the snapshot clean consumer on a repository set to NOT clean/delete snapshots based on released versions.
345      *
346      * @throws Exception
347      */
348     @Test
349     public void testReleasedSnapshotsWereNotCleaned()
350         throws Exception
351     {
352         KnownRepositoryContentConsumer repoPurgeConsumer =
353             applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-retention-count",
354                                         KnownRepositoryContentConsumer.class );
355
356         org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME );
357         ArtifactCleanupFeature acf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get();
358         acf.setDeleteReleasedSnapshots( false ); // Set to NOT delete released snapshots.
359         addRepoToConfiguration( "retention-count", repoConfiguration );
360
361         repoPurgeConsumer.beginScan( repoConfiguration, null );
362
363         String repoRoot = prepareTestRepos();
364         String projectNs = "org.apache.maven.plugins";
365         String projectPath = projectNs.replaceAll("\\.","/");
366         String projectName = "maven-plugin-plugin";
367         String projectVersion = "2.3-SNAPSHOT";
368         String projectRoot = repoRoot + "/" + projectPath+"/"+projectName;
369
370         Path repo = getTestRepoRootPath();
371         Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
372
373         // Provide the metadata list
374         List<ArtifactMetadata> ml = getArtifactMetadataFromDir( TEST_REPO_ID, projectName, repo, vDir );
375         when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs,
376             projectName, projectVersion)).thenReturn(ml);
377
378         repoPurgeConsumer.processFile(
379             CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO );
380
381         verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
382         ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
383         verify(metadataRepository, never()).removeArtifact(any(), any());
384         verify(metadataRepository, never()).removeArtifact( any(), any(), any(), any(), any(MetadataFacet.class) );
385
386         // check if the snapshot wasn't removed
387
388         assertExists( projectRoot + "/2.3-SNAPSHOT" );
389         assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar" );
390         assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.md5" );
391         assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.sha1" );
392         assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom" );
393         assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.md5" );
394         assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.sha1" );
395
396         // check if metadata file wasn't updated
397         Path artifactMetadataFile = Paths.get( projectRoot + "/maven-metadata.xml" );
398
399         String metadataXml = org.apache.archiva.common.utils.FileUtils.readFileToString( artifactMetadataFile, Charset.defaultCharset() );
400
401         String expectedVersions = "<expected><versions><version>2.3-SNAPSHOT</version></versions></expected>";
402
403         XMLAssert.assertXpathEvaluatesTo( "2.3-SNAPSHOT", "//metadata/versioning/latest", metadataXml );
404         XMLAssert.assertXpathsEqual( "//expected/versions/version", expectedVersions,
405                                      "//metadata/versioning/versions/version", metadataXml );
406         XMLAssert.assertXpathEvaluatesTo( "20070315032817", "//metadata/versioning/lastUpdated", metadataXml );
407
408         removeRepoFromConfiguration( "retention-count", repoConfiguration );
409     }
410
411     @Test
412     public void testReleasedSnapshotsWereCleaned()
413         throws Exception
414     {
415         KnownRepositoryContentConsumer repoPurgeConsumer =
416             applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-days-old",
417                                         KnownRepositoryContentConsumer.class );
418
419         org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME );
420         ArtifactCleanupFeature acf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get();
421         acf.setDeleteReleasedSnapshots( true );
422         addRepoToConfiguration( "days-old", repoConfiguration );
423
424
425         repoPurgeConsumer.beginScan( repoConfiguration, null );
426
427         String repoRoot = prepareTestRepos();
428         String projectNs = "org.apache.maven.plugins";
429         String projectPath = projectNs.replaceAll("\\.","/");
430         String projectName = "maven-plugin-plugin";
431         String projectVersion = "2.3-SNAPSHOT";
432         String projectRoot = repoRoot + "/" + projectPath+"/"+projectName;
433         Path repo = getTestRepoRootPath();
434         Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
435
436         // Provide the metadata list
437         List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
438         when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs,
439             projectName, projectVersion)).thenReturn(ml);
440
441         repoPurgeConsumer.processFile(
442             CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO );
443
444         verify(metadataRepository, times(1)).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
445         ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
446         verify(metadataRepository, never()).removeArtifact(any(), any());
447
448         // check if the snapshot was removed
449         assertDeleted( projectRoot + "/2.3-SNAPSHOT" );
450         assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar" );
451         assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.md5" );
452         assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.sha1" );
453         assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom" );
454         assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.md5" );
455         assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.sha1" );
456
457         // check if metadata file was updated
458         Path artifactMetadataFile = Paths.get( projectRoot + "/maven-metadata.xml" );
459
460         String metadataXml = org.apache.archiva.common.utils.FileUtils.readFileToString( artifactMetadataFile, Charset.defaultCharset() );
461
462         String expectedVersions =
463             "<expected><versions><version>2.2</version>" + "<version>2.3</version></versions></expected>";
464
465         XMLAssert.assertXpathEvaluatesTo( "2.3", "//metadata/versioning/latest", metadataXml );
466         XMLAssert.assertXpathsEqual( "//expected/versions/version", expectedVersions,
467                                      "//metadata/versioning/versions/version", metadataXml );
468         XMLAssert.assertXpathEvaluatesTo( "20070315032817", "//metadata/versioning/lastUpdated", metadataXml );
469
470         removeRepoFromConfiguration( "days-old", repoConfiguration );
471     }
472 }