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()
46 private void setLastModified( String dirPath )
48 File dir = new File( dirPath );
49 File[] contents = dir.listFiles();
50 for ( int i = 0; i < contents.length; i++ )
52 contents[i].setLastModified( 1179382029 );
56 public void testByLastModified()
59 map = new HashMap<String, RepositoryContentIndex>();
60 map.put( "filecontent", new LuceneRepositoryContentIndexStub( 2 ) );
61 map.put( "hashcodes", new LuceneRepositoryContentIndexStub( 2 ) );
62 map.put( "bytecode", new LuceneRepositoryContentIndexStub( 2 ) );
65 new DaysOldRepositoryPurge( getRepository(), dao, getRepoConfiguration().getDaysOlder(),
66 getRepoConfiguration().getRetentionCount(), map );
68 populateDbForTestByLastModified();
70 String repoRoot = prepareTestRepo();
72 String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-install-plugin";
74 setLastModified( projectRoot + "/2.2-SNAPSHOT/" );
76 repoPurge.process( PATH_TO_BY_DAYS_OLD_ARTIFACT );
78 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar" );
79 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.md5" );
80 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.sha1" );
81 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom" );
82 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.md5" );
83 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.sha1" );
85 // shouldn't be deleted because even if older than 30 days (because retention count = 2)
86 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar" );
87 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar.md5" );
88 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar.sha1" );
89 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom" );
90 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.md5" );
91 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.sha1" );
93 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar" );
94 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.md5" );
95 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.sha1" );
96 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom" );
97 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.md5" );
98 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.sha1" );
101 public void testMetadataDrivenSnapshots()
104 map = new HashMap<String, RepositoryContentIndex>();
105 map.put( "filecontent", new LuceneRepositoryContentIndexStub(2) );
106 map.put( "hashcodes", new LuceneRepositoryContentIndexStub(2) );
107 map.put( "bytecode", new LuceneRepositoryContentIndexStub(2) );
110 new DaysOldRepositoryPurge( getRepository(), dao, getRepoConfiguration().getDaysOlder(),
111 getRepoConfiguration().getRetentionCount(), map );
113 populateDbForTestMetadataDrivenSnapshots();
115 String repoRoot = prepareTestRepo();
117 repoPurge.process( PATH_TO_BY_DAYS_OLD_METADATA_DRIVEN_ARTIFACT );
119 String versionRoot = repoRoot + "/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT";
121 // this should be deleted since the filename version (timestamp) is older than
122 // 100 days even if the last modified date was <100 days ago
123 assertDeleted( versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.jar" );
124 assertDeleted( versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.jar.sha1" );
125 assertDeleted( versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.pom" );
126 assertDeleted( versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.pom.sha1" );
128 // musn't be deleted since the filename version (timestamp) is not older than 100 days
129 assertExists( versionRoot + "/plexus-utils-1.4.3-20070618.102615-5.jar" );
130 assertExists( versionRoot + "/plexus-utils-1.4.3-20070618.102615-5.jar.sha1" );
131 assertExists( versionRoot + "/plexus-utils-1.4.3-20070618.102615-5.pom" );
132 assertExists( versionRoot + "/plexus-utils-1.4.3-20070618.102615-5.pom.sha1" );
134 assertExists( versionRoot + "/plexus-utils-1.4.3-20070630.113158-6.jar" );
135 assertExists( versionRoot + "/plexus-utils-1.4.3-20070630.113158-6.jar.sha1" );
136 assertExists( versionRoot + "/plexus-utils-1.4.3-20070630.113158-6.pom" );
137 assertExists( versionRoot + "/plexus-utils-1.4.3-20070630.113158-6.pom.sha1" );
139 assertExists( versionRoot + "/plexus-utils-1.4.3-20070707.122114-7.jar" );
140 assertExists( versionRoot + "/plexus-utils-1.4.3-20070707.122114-7.jar.sha1" );
141 assertExists( versionRoot + "/plexus-utils-1.4.3-20070707.122114-7.pom" );
142 assertExists( versionRoot + "/plexus-utils-1.4.3-20070707.122114-7.pom.sha1" );
144 // mustn't be deleted since the last modified date is <100 days (this is not a timestamped version)
145 assertExists( versionRoot + "/plexus-utils-1.4.3-SNAPSHOT.jar" );
146 assertExists( versionRoot + "/plexus-utils-1.4.3-SNAPSHOT.pom" );
149 protected void tearDown()
156 private void populateDbForTestByLastModified()
159 List<String> versions = new ArrayList<String>();
160 versions.add( "2.2-20061118.060401-2" );
161 versions.add( "2.2-20070513.034619-5" );
162 versions.add( "2.2-SNAPSHOT" );
164 populateDb( "org.apache.maven.plugins", "maven-install-plugin", versions );
167 private void populateDbForTestMetadataDrivenSnapshots()
170 List<String> versions = new ArrayList<String>();
171 versions.add( "1.4.3-20070113.163208-4" );
172 versions.add( "1.4.3-20070618.102615-5" );
173 versions.add( "1.4.3-20070630.113158-6" );
174 versions.add( "1.4.3-20070707.122114-7" );
175 versions.add( "1.4.3-SNAPSHOT" );
177 populateDb( "org.codehaus.plexus", "plexus-utils", versions );