@Test
public void removeUnusedSnapshots()
throws Exception
{
final MavenHostedRepository repository = repositories()
.create(MavenHostedRepository.class, repositoryIdForTest())
.withRepoPolicy("SNAPSHOT")
.excludeFromSearchResults()
.save();
final long today = System.currentTimeMillis();
final long fiveDaysAgo = today - Time.days(5).toMillis();
tasks().copy().directory(file(testData().resolveFile("removeUnusedSnapshots-storage")))
.to().directory(file(new File(nexus().getWorkDirectory(), "storage/" + repository.id())))
.filterUsing("today", String.valueOf(today))
.filterUsing("fiveDaysAgo", String.valueOf(fiveDaysAgo))
.run();
final Map<String, String> taskProperties = Maps.newHashMap();
taskProperties.put("repositoryId", repository.id());
taskProperties.put("daysSinceLastRequested", "4");
scheduler().run("UnusedSnapshotRemoverTask", taskProperties);
// the following have requested timestamp = today
assertExists(repository.id(), "20130102.120000-2.pom");
assertExists(repository.id(), "20130102.120000-2.jar");
assertExists(repository.id(), "20130102.120000-2-copy.jar");
// the following have requested timestamp = fiveDaysAgo
assertDoesNotExists(repository.id(), "20130101.120000-1.pom");
assertDoesNotExists(repository.id(), "20130101.120000-1.jar");
assertDoesNotExists(repository.id(), "20130101.120000-1-copy.jar");
// the following have requested timestamp = fiveDaysAgo
assertDoesNotExists(repository.id(), "20130103.120000-3.pom");
}