1 package org.apache.maven.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
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
28 import org.apache.maven.archiva.consumers.core.repository.stubs.LuceneRepositoryContentIndexStub;
29 import org.apache.maven.archiva.indexer.RepositoryContentIndex;
32 * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
34 public class DaysOldRepositoryPurgeTest
35 extends AbstractRepositoryPurgeTest
38 private Map<String, RepositoryContentIndex> map;
40 protected void setUp()
45 map = new HashMap<String, RepositoryContentIndex>();
46 map.put( "filecontent", new LuceneRepositoryContentIndexStub() );
47 map.put( "hashcodes", new LuceneRepositoryContentIndexStub() );
48 map.put( "bytecode", new LuceneRepositoryContentIndexStub() );
52 private void setLastModified( String dirPath )
54 File dir = new File( dirPath );
55 File[] contents = dir.listFiles();
56 for ( int i = 0; i < contents.length; i++ )
58 contents[i].setLastModified( 1179382029 );
62 public void testByLastModified()
66 new DaysOldRepositoryPurge( getRepository(), dao, getRepoConfiguration().getDaysOlder(),
69 populateDbForTestByLastModified();
71 String repoRoot = prepareTestRepo();
73 String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-install-plugin";
75 setLastModified( projectRoot + "/2.2-SNAPSHOT/" );
77 repoPurge.process( PATH_TO_BY_DAYS_OLD_ARTIFACT );
79 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar" );
80 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.md5" );
81 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.sha1" );
82 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom" );
83 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.md5" );
84 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.sha1" );
87 public void testMetadataDrivenSnapshots()
91 new DaysOldRepositoryPurge( getRepository(), dao, getRepoConfiguration().getDaysOlder(),
92 getRepoConfiguration().getRetentionCount(), map );
94 populateDbForTestMetadataDrivenSnapshots();
96 String repoRoot = prepareTestRepo();
98 repoPurge.process( PATH_TO_BY_DAYS_OLD_METADATA_DRIVEN_ARTIFACT );
100 String versionRoot = repoRoot + "/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT";
102 // this should be deleted since the filename version (timestamp) is older than
103 // 100 days even if the last modified date was <100 days ago
104 assertDeleted( versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.jar" );
105 assertDeleted( versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.jar.sha1" );
106 assertDeleted( versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.pom" );
107 assertDeleted( versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.pom.sha1" );
109 // musn't be deleted since the filename version (timestamp) is not older than 100 days
110 assertExists( versionRoot + "/plexus-utils-1.4.3-20070618.102615-5.jar" );
111 assertExists( versionRoot + "/plexus-utils-1.4.3-20070618.102615-5.jar.sha1" );
112 assertExists( versionRoot + "/plexus-utils-1.4.3-20070618.102615-5.pom" );
113 assertExists( versionRoot + "/plexus-utils-1.4.3-20070618.102615-5.pom.sha1" );
115 assertExists( versionRoot + "/plexus-utils-1.4.3-20070630.113158-6.jar" );
116 assertExists( versionRoot + "/plexus-utils-1.4.3-20070630.113158-6.jar.sha1" );
117 assertExists( versionRoot + "/plexus-utils-1.4.3-20070630.113158-6.pom" );
118 assertExists( versionRoot + "/plexus-utils-1.4.3-20070630.113158-6.pom.sha1" );
120 assertExists( versionRoot + "/plexus-utils-1.4.3-20070707.122114-7.jar" );
121 assertExists( versionRoot + "/plexus-utils-1.4.3-20070707.122114-7.jar.sha1" );
122 assertExists( versionRoot + "/plexus-utils-1.4.3-20070707.122114-7.pom" );
123 assertExists( versionRoot + "/plexus-utils-1.4.3-20070707.122114-7.pom.sha1" );
125 // mustn't be deleted since the last modified date is <100 days (this is not a timestamped version)
126 assertExists( versionRoot + "/plexus-utils-1.4.3-SNAPSHOT.jar" );
127 assertExists( versionRoot + "/plexus-utils-1.4.3-SNAPSHOT.pom" );
130 protected void tearDown()
137 private void populateDbForTestByLastModified()
140 List<String> versions = new ArrayList<String>();
141 versions.add( "2.2-SNAPSHOT" );
143 populateDb( "org.apache.maven.plugins", "maven-install-plugin", versions );
146 private void populateDbForTestMetadataDrivenSnapshots()
149 List<String> versions = new ArrayList<String>();
150 versions.add( "1.4.3-20070113.163208-4" );
151 versions.add( "1.4.3-20070618.102615-5" );
152 versions.add( "1.4.3-20070630.113158-6" );
153 versions.add( "1.4.3-20070707.122114-7" );
154 versions.add( "1.4.3-SNAPSHOT" );
156 populateDb( "org.codehaus.plexus", "plexus-utils", versions );