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.mock.MockRepositorySessionFactory;
36 import org.apache.commons.io.FileUtils;
37 import org.custommonkey.xmlunit.XMLAssert;
38 import org.junit.After;
39 import org.junit.Before;
40 import org.junit.Test;
41 import org.mockito.ArgumentCaptor;
42 import org.springframework.test.context.ContextConfiguration;
45 import java.nio.charset.Charset;
46 import java.nio.file.Path;
47 import java.util.HashSet;
48 import java.util.List;
51 import static org.junit.Assert.*;
52 import static org.mockito.Matchers.any;
53 import static org.mockito.Matchers.eq;
54 import static org.mockito.Mockito.*;
58 @ContextConfiguration (
59 locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-purge-consumer-test.xml" } )
60 public class RepositoryPurgeConsumerTest
61 extends AbstractRepositoryPurgeTest
70 MockRepositorySessionFactory factory = applicationContext.getBean( MockRepositorySessionFactory.class );
71 factory.setRepository( metadataRepository );
76 public void tearDown()
83 public void testConsumption()
86 assertNotConsumed( "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata.xml" );
91 public void testConsumptionOfOtherMetadata()
94 assertNotConsumed( "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata-central.xml" );
98 private void cleanupFileTypes()
100 ArchivaConfiguration archivaConfiguration =
101 applicationContext.getBean( "archivaConfiguration#default", ArchivaConfiguration.class );
103 FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
104 fileType.removePattern( "**/*.xml" );
107 private void assertNotConsumed( String path )
110 ArchivaConfiguration archivaConfiguration =
111 applicationContext.getBean( "archivaConfiguration#default", ArchivaConfiguration.class );
113 FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
114 assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
115 fileType.addPattern( "**/*.xml" );
118 //FileTypes fileTypes = applicationContext.getBean( FileTypes.class );
119 for ( FileTypes fileTypes : applicationContext.getBeansOfType( FileTypes.class ).values() )
121 fileTypes.afterConfigurationChange( null, "repositoryScanning.fileTypes", null );
123 KnownRepositoryContentConsumer repoPurgeConsumer =
124 applicationContext.getBean( "knownRepositoryContentConsumer#repository-purge",
125 KnownRepositoryContentConsumer.class );
127 File repoLocation = new File( "target/test-" + getName() + "/test-repo" );
129 File localFile = new File( repoLocation, path );
131 ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
132 BaseFile baseFile = new BaseFile( repoLocation, localFile );
133 predicate.setBasefile( baseFile );
135 assertFalse( predicate.evaluate( repoPurgeConsumer ) );
138 private void setLastModified( String path )
140 File dir = new File( path );
141 File[] contents = dir.listFiles();
142 for ( int i = 0; i < contents.length; i++ )
144 contents[i].setLastModified( 1179382029 );
149 public void testConsumerByRetentionCount()
152 KnownRepositoryContentConsumer repoPurgeConsumer =
153 applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-retention-count",
154 KnownRepositoryContentConsumer.class );
156 ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME );
157 repoConfiguration.setDaysOlder( 0 ); // force days older off to allow retention count purge to execute.
158 repoConfiguration.setRetentionCount( TEST_RETENTION_COUNT );
159 addRepoToConfiguration( "retention-count", repoConfiguration );
161 repoPurgeConsumer.beginScan( repoConfiguration, null );
163 String repoRoot = prepareTestRepos();
164 String projectNs = "org.jruby.plugins";
165 String projectPath = projectNs.replaceAll("\\.","/");
166 String projectName = "jruby-rake-plugin";
167 String projectVersion = "1.0RC1-SNAPSHOT";
168 String projectRoot = repoRoot + "/" + projectPath+"/"+projectName;
169 String versionRoot = projectRoot + "/" + projectVersion;
171 Path repo = getTestRepoRootPath();
172 Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
174 // Provide the metadata list
175 List<ArtifactMetadata> ml = getArtifactMetadataFromDir( TEST_REPO_ID, projectName, repo, vDir );
176 when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs,
177 projectName, projectVersion)).thenReturn(ml);
178 Set<String> deletedVersions = new HashSet<>();
179 deletedVersions.add("1.0RC1-20070504.153317-1");
180 deletedVersions.add("1.0RC1-20070504.160758-2");
182 repoPurgeConsumer.processFile( PATH_TO_BY_RETENTION_COUNT_ARTIFACT );
184 // Verify the metadataRepository invocations
185 verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
186 ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
187 verify(metadataRepository, times(2)).removeArtifact(metadataArg.capture(), eq(projectVersion));
188 List<ArtifactMetadata> metaL = metadataArg.getAllValues();
189 for (ArtifactMetadata meta : metaL) {
190 assertTrue(meta.getId().startsWith(projectName));
191 assertTrue(deletedVersions.contains(meta.getVersion()));
196 // assert if removed from repo
197 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar" );
198 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1-javadoc.jar" );
199 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1-javadoc.zip" );
200 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.md5" );
201 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.sha1" );
202 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom" );
203 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.md5" );
204 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.sha1" );
206 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar" );
207 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2-javadoc.jar" );
208 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2-javadoc.zip" );
209 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.md5" );
210 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.sha1" );
211 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom" );
212 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.md5" );
213 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.sha1" );
215 // assert if not removed from repo
216 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar" );
217 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3-javadoc.jar" );
218 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3-javadoc.zip" );
219 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.md5" );
220 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.sha1" );
221 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom" );
222 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.md5" );
223 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.sha1" );
225 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar" );
226 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.md5" );
227 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.sha1" );
228 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom" );
229 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.md5" );
230 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.sha1" );
232 removeRepoFromConfiguration( "retention-count", repoConfiguration );
235 private void addRepoToConfiguration( String configHint, ManagedRepository repoConfiguration )
238 ArchivaConfiguration archivaConfiguration =
239 applicationContext.getBean( "archivaConfiguration#" + configHint, ArchivaConfiguration.class );
240 ( (DefaultManagedRepositoryAdmin) applicationContext.getBean(
241 ManagedRepositoryAdmin.class ) ).setArchivaConfiguration( archivaConfiguration );
242 // skygo: Default Validator was not looking at same config
243 ( (DefaultRepositoryCommonValidator) applicationContext.getBean(
244 RepositoryCommonValidator.class ) ).setArchivaConfiguration( archivaConfiguration );
245 ManagedRepositoryAdmin managedRepositoryAdmin = applicationContext.getBean( ManagedRepositoryAdmin.class );
246 if ( managedRepositoryAdmin.getManagedRepository( repoConfiguration.getId() ) != null )
248 managedRepositoryAdmin.deleteManagedRepository( repoConfiguration.getId(), null, false );
250 managedRepositoryAdmin.addManagedRepository( repoConfiguration, false, null );
253 private void removeRepoFromConfiguration( String configHint, ManagedRepository repoConfiguration )
256 ArchivaConfiguration archivaConfiguration =
257 applicationContext.getBean( "archivaConfiguration#" + configHint, ArchivaConfiguration.class );
259 ( (DefaultManagedRepositoryAdmin) applicationContext.getBean(
260 ManagedRepositoryAdmin.class ) ).setArchivaConfiguration( archivaConfiguration );
261 // skygo: Default Validator was not looking at same config
262 ( (DefaultRepositoryCommonValidator) applicationContext.getBean(
263 RepositoryCommonValidator.class ) ).setArchivaConfiguration( archivaConfiguration );
264 ManagedRepositoryAdmin managedRepositoryAdmin = applicationContext.getBean( ManagedRepositoryAdmin.class );
265 if ( managedRepositoryAdmin.getManagedRepository( repoConfiguration.getId() ) != null )
267 managedRepositoryAdmin.deleteManagedRepository( repoConfiguration.getId(), null, true );
272 public void testConsumerByDaysOld()
275 KnownRepositoryContentConsumer repoPurgeConsumer =
276 applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-days-old",
277 KnownRepositoryContentConsumer.class );
279 ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME );
280 repoConfiguration.setDaysOlder( TEST_DAYS_OLDER );
281 addRepoToConfiguration( "days-old", repoConfiguration );
283 repoPurgeConsumer.beginScan( repoConfiguration, null );
285 String repoRoot = prepareTestRepos();
286 String projectNs = "org.apache.maven.plugins";
287 String projectPath = projectNs.replaceAll("\\.","/");
288 String projectName = "maven-install-plugin";
289 String projectVersion = "2.2-SNAPSHOT";
290 String projectRoot = repoRoot + "/" + projectPath+"/"+projectName;
292 setLastModified( projectRoot + "/"+projectVersion);
295 Path repo = getTestRepoRootPath();
296 Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
298 // Provide the metadata list
299 List<ArtifactMetadata> ml = getArtifactMetadataFromDir( TEST_REPO_ID, projectName, repo, vDir );
300 when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs,
301 projectName, projectVersion)).thenReturn(ml);
302 Set<String> deletedVersions = new HashSet<>();
303 deletedVersions.add("2.2-SNAPSHOT");
304 deletedVersions.add("2.2-20061118.060401-2");
306 repoPurgeConsumer.processFile( PATH_TO_BY_DAYS_OLD_ARTIFACT );
308 // Verify the metadataRepository invocations
309 verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
310 ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
311 verify(metadataRepository, times(2)).removeArtifact(metadataArg.capture(), eq(projectVersion));
312 List<ArtifactMetadata> metaL = metadataArg.getAllValues();
313 for (ArtifactMetadata meta : metaL) {
314 assertTrue(meta.getId().startsWith(projectName));
315 assertTrue(deletedVersions.contains(meta.getVersion()));
318 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar" );
319 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.md5" );
320 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.sha1" );
321 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom" );
322 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.md5" );
323 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.sha1" );
325 // shouldn't be deleted because even if older than 30 days (because retention count = 2)
326 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar" );
327 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar.md5" );
328 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar.sha1" );
329 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom" );
330 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.md5" );
331 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.sha1" );
333 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar" );
334 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.md5" );
335 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.sha1" );
336 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom" );
337 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.md5" );
338 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.sha1" );
340 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar" );
341 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.md5" );
342 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.sha1" );
343 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom" );
344 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.md5" );
345 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.sha1" );
347 removeRepoFromConfiguration( "days-old", repoConfiguration );
351 * Test the snapshot clean consumer on a repository set to NOT clean/delete snapshots based on released versions.
356 public void testReleasedSnapshotsWereNotCleaned()
359 KnownRepositoryContentConsumer repoPurgeConsumer =
360 applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-retention-count",
361 KnownRepositoryContentConsumer.class );
363 ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME );
364 repoConfiguration.setDeleteReleasedSnapshots( false ); // Set to NOT delete released snapshots.
365 addRepoToConfiguration( "retention-count", repoConfiguration );
367 repoPurgeConsumer.beginScan( repoConfiguration, null );
369 String repoRoot = prepareTestRepos();
370 String projectNs = "org.apache.maven.plugins";
371 String projectPath = projectNs.replaceAll("\\.","/");
372 String projectName = "maven-plugin-plugin";
373 String projectVersion = "2.3-SNAPSHOT";
374 String projectRoot = repoRoot + "/" + projectPath+"/"+projectName;
376 Path repo = getTestRepoRootPath();
377 Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
379 // Provide the metadata list
380 List<ArtifactMetadata> ml = getArtifactMetadataFromDir( TEST_REPO_ID, projectName, repo, vDir );
381 when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs,
382 projectName, projectVersion)).thenReturn(ml);
384 repoPurgeConsumer.processFile(
385 CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO );
387 verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
388 ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
389 verify(metadataRepository, never()).removeArtifact(any(), any());
390 verify(metadataRepository, never()).removeArtifact( any(), any(), any(), any(), any(MetadataFacet.class) );
392 // check if the snapshot wasn't removed
394 assertExists( projectRoot + "/2.3-SNAPSHOT" );
395 assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar" );
396 assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.md5" );
397 assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.sha1" );
398 assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom" );
399 assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.md5" );
400 assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.sha1" );
402 // check if metadata file wasn't updated
403 File artifactMetadataFile = new File( projectRoot + "/maven-metadata.xml" );
405 String metadataXml = FileUtils.readFileToString( artifactMetadataFile, Charset.defaultCharset() );
407 String expectedVersions = "<expected><versions><version>2.3-SNAPSHOT</version></versions></expected>";
409 XMLAssert.assertXpathEvaluatesTo( "2.3-SNAPSHOT", "//metadata/versioning/latest", metadataXml );
410 XMLAssert.assertXpathsEqual( "//expected/versions/version", expectedVersions,
411 "//metadata/versioning/versions/version", metadataXml );
412 XMLAssert.assertXpathEvaluatesTo( "20070315032817", "//metadata/versioning/lastUpdated", metadataXml );
414 removeRepoFromConfiguration( "retention-count", repoConfiguration );
418 public void testReleasedSnapshotsWereCleaned()
421 KnownRepositoryContentConsumer repoPurgeConsumer =
422 applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-days-old",
423 KnownRepositoryContentConsumer.class );
425 ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME );
426 repoConfiguration.setDeleteReleasedSnapshots( true );
427 addRepoToConfiguration( "days-old", repoConfiguration );
429 repoPurgeConsumer.beginScan( repoConfiguration, null );
431 String repoRoot = prepareTestRepos();
432 String projectNs = "org.apache.maven.plugins";
433 String projectPath = projectNs.replaceAll("\\.","/");
434 String projectName = "maven-plugin-plugin";
435 String projectVersion = "2.3-SNAPSHOT";
436 String projectRoot = repoRoot + "/" + projectPath+"/"+projectName;
437 Path repo = getTestRepoRootPath();
438 Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
440 // Provide the metadata list
441 List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
442 when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs,
443 projectName, projectVersion)).thenReturn(ml);
445 repoPurgeConsumer.processFile(
446 CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO );
448 verify(metadataRepository, times(1)).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
449 ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
450 verify(metadataRepository, never()).removeArtifact(any(), any());
452 // check if the snapshot was removed
453 assertDeleted( projectRoot + "/2.3-SNAPSHOT" );
454 assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar" );
455 assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.md5" );
456 assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.sha1" );
457 assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom" );
458 assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.md5" );
459 assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.sha1" );
461 // check if metadata file was updated
462 File artifactMetadataFile = new File( projectRoot + "/maven-metadata.xml" );
464 String metadataXml = FileUtils.readFileToString( artifactMetadataFile, Charset.defaultCharset() );
466 String expectedVersions =
467 "<expected><versions><version>2.2</version>" + "<version>2.3</version></versions></expected>";
469 XMLAssert.assertXpathEvaluatesTo( "2.3", "//metadata/versioning/latest", metadataXml );
470 XMLAssert.assertXpathsEqual( "//expected/versions/version", expectedVersions,
471 "//metadata/versioning/versions/version", metadataXml );
472 XMLAssert.assertXpathEvaluatesTo( "20070315032817", "//metadata/versioning/lastUpdated", metadataXml );
474 removeRepoFromConfiguration( "days-old", repoConfiguration );