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.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.repository.base.ArchivaRepositoryRegistry;
31 import org.apache.archiva.repository.RepositoryRegistry;
32 import org.apache.archiva.repository.features.ArtifactCleanupFeature;
33 import org.junit.After;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.mockito.ArgumentCaptor;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39 import org.springframework.test.context.ContextConfiguration;
40 import org.xmlunit.assertj3.XmlAssert;
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;
53 import static org.junit.Assert.*;
54 import static org.mockito.ArgumentMatchers.any;
55 import static org.mockito.ArgumentMatchers.eq;
56 import static org.mockito.Mockito.*;
60 @ContextConfiguration (
61 locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-purge-consumer-test.xml" } )
62 public class RepositoryPurgeConsumerTest
63 extends AbstractRepositoryPurgeTest
65 private static final Logger log = LoggerFactory.getLogger( RepositoryPurgeConsumerTest.class );
78 public void tearDown()
85 public void testConsumption()
88 assertNotConsumed( "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata.xml" );
93 public void testConsumptionOfOtherMetadata()
96 assertNotConsumed( "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata-central.xml" );
100 private void cleanupFileTypes()
102 ArchivaConfiguration archivaConfiguration =
103 applicationContext.getBean( "archivaConfiguration#default", ArchivaConfiguration.class );
105 FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
106 fileType.removePattern( "**/*.xml" );
109 @SuppressWarnings( "deprecation" )
110 private void assertNotConsumed( String path )
113 ArchivaConfiguration archivaConfiguration =
114 applicationContext.getBean( "archivaConfiguration#default", ArchivaConfiguration.class );
116 FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
117 assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
118 fileType.addPattern( "**/*.xml" );
121 //FileTypes fileTypes = applicationContext.getBean( FileTypes.class );
122 for ( FileTypes fileTypes : applicationContext.getBeansOfType( FileTypes.class ).values() )
124 fileTypes.afterConfigurationChange( null, "repositoryScanning.fileTypes", null );
126 KnownRepositoryContentConsumer repoPurgeConsumer =
127 applicationContext.getBean( "knownRepositoryContentConsumer#repository-purge",
128 KnownRepositoryContentConsumer.class );
130 Path repoLocation = Paths.get( "target/test-" + getName() + "/test-repo" );
132 Path localFile = repoLocation.resolve( path );
134 ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
135 BaseFile baseFile = new BaseFile( repoLocation.toFile(), localFile.toFile() );
136 predicate.setBasefile( baseFile );
138 assertFalse( predicate.evaluate( repoPurgeConsumer ) );
141 private void setLastModified( String path ) throws IOException
143 Path dir = Paths.get( path );
147 contents = Files.list( dir ).toArray(Path[]::new);
149 catch ( IOException e )
151 log.error("Could not list files {}: {}", dir, e.getMessage(), e);
152 contents = new Path[0];
154 for ( Path content : contents )
156 Files.setLastModifiedTime( content, FileTime.fromMillis( 1179382029 ) );
161 public void testConsumerByRetentionCount()
164 RepositoryPurgeConsumer repoPurgeConsumer =
165 applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-retention-count",
166 RepositoryPurgeConsumer.class );
167 repoPurgeConsumer.setRepositorySessionFactory( sessionFactory );
168 org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME );
169 ArtifactCleanupFeature atf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get();
170 atf.setRetentionPeriod( Period.ofDays( 0 ) ); // force days older off to allow retention count purge to execute.
171 atf.setRetentionCount( TEST_RETENTION_COUNT );
172 addRepoToConfiguration( "retention-count", repoConfiguration );
174 when( sessionFactory.createSession( ) ).thenReturn( repositorySession );
175 when( repositorySession.getRepository()).thenReturn( metadataRepository );
176 repositorySession.save();
178 repoPurgeConsumer.beginScan( repoConfiguration, null );
180 String repoRoot = prepareTestRepos();
181 String projectNs = "org.jruby.plugins";
182 String projectPath = projectNs.replaceAll("\\.","/");
183 String projectName = "jruby-rake-plugin";
184 String projectVersion = "1.0RC1-SNAPSHOT";
185 String projectRoot = repoRoot + "/" + projectPath+"/"+projectName;
186 String versionRoot = projectRoot + "/" + projectVersion;
188 Path repo = getTestRepoRootPath();
189 Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
191 // Provide the metadata list
192 List<ArtifactMetadata> ml = getArtifactMetadataFromDir( TEST_REPO_ID, projectName, repo, vDir );
196 when(metadataRepository.getArtifacts( repositorySession, TEST_REPO_ID,
197 projectNs, projectName, projectVersion )).thenReturn(ml);
198 Set<String> deletedVersions = new HashSet<>();
199 deletedVersions.add("1.0RC1-20070504.153317-1");
200 deletedVersions.add("1.0RC1-20070504.160758-2");
202 repoPurgeConsumer.processFile( PATH_TO_BY_RETENTION_COUNT_ARTIFACT );
204 // Verify the metadataRepository invocations
205 verify(metadataRepository, never()).removeProjectVersion( eq(repositorySession), eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
206 ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
207 verify(metadataRepository, times(2)).removeTimestampedArtifact( eq(repositorySession), metadataArg.capture(), eq(projectVersion) );
208 List<ArtifactMetadata> metaL = metadataArg.getAllValues();
209 for (ArtifactMetadata meta : metaL) {
210 assertTrue(meta.getId().startsWith(projectName));
211 assertTrue(deletedVersions.contains(meta.getVersion()));
216 // assert if removed from repo
217 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar" );
218 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1-javadoc.jar" );
219 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1-javadoc.zip" );
220 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.md5" );
221 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.sha1" );
222 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom" );
223 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.md5" );
224 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.sha1" );
226 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar" );
227 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2-javadoc.jar" );
228 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2-javadoc.zip" );
229 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.md5" );
230 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.sha1" );
231 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom" );
232 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.md5" );
233 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.sha1" );
235 // assert if not removed from repo
236 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar" );
237 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3-javadoc.jar" );
238 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3-javadoc.zip" );
239 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.md5" );
240 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.sha1" );
241 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom" );
242 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.md5" );
243 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.sha1" );
245 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar" );
246 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.md5" );
247 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.sha1" );
248 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom" );
249 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.md5" );
250 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.sha1" );
252 removeRepoFromConfiguration( "retention-count", repoConfiguration );
255 private void addRepoToConfiguration( String configHint, org.apache.archiva.repository.ManagedRepository repoConfiguration )
258 RepositoryRegistry repositoryRegistry = applicationContext.getBean( ArchivaRepositoryRegistry.class);
259 repositoryRegistry.putRepository( repoConfiguration );
262 private void removeRepoFromConfiguration( String configHint, org.apache.archiva.repository.ManagedRepository repoConfiguration )
265 RepositoryRegistry repositoryRegistry = applicationContext.getBean( ArchivaRepositoryRegistry.class);
266 repositoryRegistry.removeRepository( repoConfiguration );
270 public void testConsumerByDaysOld()
273 RepositoryPurgeConsumer repoPurgeConsumer =
274 applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-days-old",
275 RepositoryPurgeConsumer.class );
277 repoPurgeConsumer.setRepositorySessionFactory( sessionFactory );
279 org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME );
280 ArtifactCleanupFeature atf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get();
281 atf.setRetentionPeriod( Period.ofDays( TEST_DAYS_OLDER ) );
282 addRepoToConfiguration( "days-old", repoConfiguration );
284 when( sessionFactory.createSession( ) ).thenReturn( repositorySession );
285 when( repositorySession.getRepository()).thenReturn( metadataRepository );
286 repositorySession.save();
287 repoPurgeConsumer.beginScan( repoConfiguration, null );
289 String repoRoot = prepareTestRepos();
290 String projectNs = "org.apache.maven.plugins";
291 String projectPath = projectNs.replaceAll("\\.","/");
292 String projectName = "maven-install-plugin";
293 String projectVersion = "2.2-SNAPSHOT";
294 String projectRoot = repoRoot + "/" + projectPath+"/"+projectName;
296 setLastModified( projectRoot + "/"+projectVersion);
299 Path repo = getTestRepoRootPath();
300 Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
302 // Provide the metadata list
303 List<ArtifactMetadata> ml = getArtifactMetadataFromDir( TEST_REPO_ID, projectName, repo, vDir );
304 when(metadataRepository.getArtifacts( repositorySession, TEST_REPO_ID,
305 projectNs, projectName, projectVersion )).thenReturn(ml);
306 Set<String> deletedVersions = new HashSet<>();
307 deletedVersions.add("2.2-SNAPSHOT");
308 deletedVersions.add("2.2-20061118.060401-2");
310 repoPurgeConsumer.processFile( PATH_TO_BY_DAYS_OLD_ARTIFACT );
312 // Verify the metadataRepository invocations
313 verify(metadataRepository, never()).removeProjectVersion( eq(repositorySession), eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
314 ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
315 verify(metadataRepository, times(2)).removeTimestampedArtifact( eq(repositorySession), metadataArg.capture(), eq(projectVersion) );
316 List<ArtifactMetadata> metaL = metadataArg.getAllValues();
317 assertTrue( metaL.size( ) > 0 );
318 for (ArtifactMetadata meta : metaL) {
319 assertTrue(meta.getId().startsWith(projectName));
320 assertTrue(deletedVersions.contains(meta.getVersion()));
323 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar" );
324 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.md5" );
325 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.sha1" );
326 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom" );
327 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.md5" );
328 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.sha1" );
330 // shouldn't be deleted because even if older than 30 days (because retention count = 2)
331 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar" );
332 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar.md5" );
333 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar.sha1" );
334 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom" );
335 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.md5" );
336 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.sha1" );
338 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar" );
339 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.md5" );
340 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.sha1" );
341 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom" );
342 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.md5" );
343 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.sha1" );
345 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar" );
346 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.md5" );
347 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.sha1" );
348 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom" );
349 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.md5" );
350 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.sha1" );
352 removeRepoFromConfiguration( "days-old", repoConfiguration );
356 * Test the snapshot clean consumer on a repository set to NOT clean/delete snapshots based on released versions.
361 public void testReleasedSnapshotsWereNotCleaned()
364 KnownRepositoryContentConsumer repoPurgeConsumer =
365 applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-retention-count",
366 KnownRepositoryContentConsumer.class );
368 org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME );
369 ArtifactCleanupFeature acf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get();
370 acf.setDeleteReleasedSnapshots( false ); // Set to NOT delete released snapshots.
371 addRepoToConfiguration( "retention-count", repoConfiguration );
373 repoPurgeConsumer.beginScan( repoConfiguration, null );
375 String repoRoot = prepareTestRepos();
376 String projectNs = "org.apache.maven.plugins";
377 String projectPath = projectNs.replaceAll("\\.","/");
378 String projectName = "maven-plugin-plugin";
379 String projectVersion = "2.3-SNAPSHOT";
380 String projectRoot = repoRoot + "/" + projectPath+"/"+projectName;
382 Path repo = getTestRepoRootPath();
383 Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
385 // Provide the metadata list
386 List<ArtifactMetadata> ml = getArtifactMetadataFromDir( TEST_REPO_ID, projectName, repo, vDir );
387 when(metadataRepository.getArtifacts( repositorySession, TEST_REPO_ID,
388 projectNs, projectName, projectVersion )).thenReturn(ml);
390 repoPurgeConsumer.processFile(
391 CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO );
393 verify(metadataRepository, never()).removeProjectVersion( eq(repositorySession), eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
394 verify(metadataRepository, never()).removeTimestampedArtifact( eq(repositorySession), any(), any() );
395 verify(metadataRepository, never()).removeFacetFromArtifact( eq(repositorySession), any(), any(), any(), any(), any(MetadataFacet.class) );
397 // check if the snapshot wasn't removed
399 assertExists( projectRoot + "/2.3-SNAPSHOT" );
400 assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar" );
401 assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.md5" );
402 assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.sha1" );
403 assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom" );
404 assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.md5" );
405 assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.sha1" );
407 // check if metadata file wasn't updated
408 Path artifactMetadataFile = Paths.get( projectRoot + "/maven-metadata.xml" );
410 String metadataXml = org.apache.archiva.common.utils.FileUtils.readFileToString( artifactMetadataFile, Charset.defaultCharset() );
412 XmlAssert.assertThat( metadataXml ).valueByXPath( "//metadata/versioning/latest" ).isEqualTo( "2.3-SNAPSHOT" );
413 XmlAssert.assertThat( metadataXml ).valueByXPath( "//metadata/versioning/versions/version" ).isEqualTo( "2.3-SNAPSHOT" );
414 XmlAssert.assertThat(metadataXml).valueByXPath("//metadata/versioning/lastUpdated").isEqualTo ( "20070315032817" );
416 removeRepoFromConfiguration( "retention-count", repoConfiguration );
420 public void testReleasedSnapshotsWereCleaned()
423 RepositoryPurgeConsumer repoPurgeConsumer =
424 applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-days-old",
425 RepositoryPurgeConsumer.class );
426 repoPurgeConsumer.setRepositorySessionFactory( sessionFactory );
427 org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME );
428 ArtifactCleanupFeature acf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get();
429 acf.setDeleteReleasedSnapshots( true );
430 addRepoToConfiguration( "days-old", repoConfiguration );
432 when( sessionFactory.createSession( ) ).thenReturn( repositorySession );
433 when( repositorySession.getRepository()).thenReturn( metadataRepository );
434 repositorySession.save();
435 repoPurgeConsumer.beginScan( repoConfiguration, null );
437 String repoRoot = prepareTestRepos();
438 String projectNs = "org.apache.maven.plugins";
439 String projectPath = projectNs.replaceAll("\\.","/");
440 String projectName = "maven-plugin-plugin";
441 String projectVersion = "2.3-SNAPSHOT";
442 String projectRoot = repoRoot + "/" + projectPath+"/"+projectName;
443 Path repo = getTestRepoRootPath();
444 Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
446 // Provide the metadata list
447 List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
448 when(metadataRepository.getArtifacts( repositorySession, TEST_REPO_ID,
449 projectNs, projectName, projectVersion )).thenReturn(ml);
451 repoPurgeConsumer.processFile(
452 CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO );
454 verify(metadataRepository, times(1)).removeProjectVersion( eq(repositorySession), eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
455 verify(metadataRepository, never()).removeTimestampedArtifact( eq(repositorySession), any(), any() );
457 // check if the snapshot was removed
458 assertDeleted( projectRoot + "/2.3-SNAPSHOT" );
459 assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar" );
460 assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.md5" );
461 assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.sha1" );
462 assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom" );
463 assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.md5" );
464 assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.sha1" );
466 // check if metadata file was updated
467 Path artifactMetadataFile = Paths.get( projectRoot + "/maven-metadata.xml" );
469 String metadataXml = org.apache.archiva.common.utils.FileUtils.readFileToString( artifactMetadataFile, Charset.defaultCharset() );
471 XmlAssert.assertThat( metadataXml ).valueByXPath( "//metadata/versioning/latest" ).isEqualTo( "2.3" );
472 // XMLAssert.assertXpathEvaluatesTo( "2.3", "//metadata/versioning/latest", metadataXml );
473 XmlAssert.assertThat( metadataXml ).nodesByXPath( "//metadata/versioning/versions/version" ).hasSize( 2 );
474 XmlAssert.assertThat( metadataXml ).valueByXPath( "//metadata/versioning/versions/version[1]" ).isEqualTo( "2.2" );
475 XmlAssert.assertThat( metadataXml ).valueByXPath( "//metadata/versioning/versions/version[2]" ).isEqualTo( "2.3" );
476 // XMLAssert.assertXpathsEqual( "//expected/versions/version", expectedVersions,
477 // "//metadata/versioning/versions/version", metadataXml );
479 XmlAssert.assertThat( metadataXml ).valueByXPath( "//metadata/versioning/lastUpdated" ).isEqualTo( "20070315032817" );
480 //XMLAssert.assertXpathEvaluatesTo( "20070315032817", "//metadata/versioning/lastUpdated", metadataXml );
482 removeRepoFromConfiguration( "days-old", repoConfiguration );