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.List;
27 * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
29 public class DaysOldRepositoryPurgeTest
30 extends AbstractRepositoryPurgeTest
33 protected void setUp()
39 new DaysOldRepositoryPurge( getRepository(), dao, getRepoConfiguration().getDaysOlder() );
42 private void setLastModified( String dirPath )
44 File dir = new File( dirPath );
45 File[] contents = dir.listFiles();
46 for ( int i = 0; i < contents.length; i++ )
48 contents[i].setLastModified( 1179382029 );
52 public void testByLastModified()
55 populateDbForTestByLastModified();
57 String repoRoot = prepareTestRepo();
59 String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-install-plugin";
61 setLastModified( projectRoot + "/2.2-SNAPSHOT/" );
63 repoPurge.process( PATH_TO_BY_DAYS_OLD_ARTIFACT );
65 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar" );
66 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.md5" );
67 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.sha1" );
68 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom" );
69 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.md5" );
70 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.sha1" );
73 public void testMetadataDrivenSnapshots()
76 populateDbForTestMetadataDrivenSnapshots();
78 String repoRoot = prepareTestRepo();
80 repoPurge.process( PATH_TO_BY_DAYS_OLD_METADATA_DRIVEN_ARTIFACT );
82 String versionRoot = repoRoot + "/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT";
84 // this should be deleted since the filename version (timestamp) is older than
85 // 100 days even if the last modified date was <100 days ago
86 assertDeleted( versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.jar" );
87 assertDeleted( versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.jar.sha1" );
88 assertDeleted( versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.pom" );
89 assertDeleted( versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.pom.sha1" );
91 // musn't be deleted since the filename version (timestamp) is not older than 100 days
92 assertExists( versionRoot + "/plexus-utils-1.4.3-20070618.102615-5.jar" );
93 assertExists( versionRoot + "/plexus-utils-1.4.3-20070618.102615-5.jar.sha1" );
94 assertExists( versionRoot + "/plexus-utils-1.4.3-20070618.102615-5.pom" );
95 assertExists( versionRoot + "/plexus-utils-1.4.3-20070618.102615-5.pom.sha1" );
97 assertExists( versionRoot + "/plexus-utils-1.4.3-20070630.113158-6.jar" );
98 assertExists( versionRoot + "/plexus-utils-1.4.3-20070630.113158-6.jar.sha1" );
99 assertExists( versionRoot + "/plexus-utils-1.4.3-20070630.113158-6.pom" );
100 assertExists( versionRoot + "/plexus-utils-1.4.3-20070630.113158-6.pom.sha1" );
102 assertExists( versionRoot + "/plexus-utils-1.4.3-20070707.122114-7.jar" );
103 assertExists( versionRoot + "/plexus-utils-1.4.3-20070707.122114-7.jar.sha1" );
104 assertExists( versionRoot + "/plexus-utils-1.4.3-20070707.122114-7.pom" );
105 assertExists( versionRoot + "/plexus-utils-1.4.3-20070707.122114-7.pom.sha1" );
107 // mustn't be deleted since the last modified date is <100 days (this is not a timestamped version)
108 assertExists( versionRoot + "/plexus-utils-1.4.3-SNAPSHOT.jar" );
109 assertExists( versionRoot + "/plexus-utils-1.4.3-SNAPSHOT.pom" );
112 protected void tearDown()
119 private void populateDbForTestByLastModified()
122 List<String> versions = new ArrayList<String>();
123 versions.add( "2.2-SNAPSHOT" );
125 populateDb( "org.apache.maven.plugins", "maven-install-plugin", versions );
128 private void populateDbForTestMetadataDrivenSnapshots()
131 List<String> versions = new ArrayList<String>();
132 versions.add( "1.4.3-20070113.163208-4" );
133 versions.add( "1.4.3-20070618.102615-5" );
134 versions.add( "1.4.3-20070630.113158-6" );
135 versions.add( "1.4.3-20070707.122114-7" );
136 versions.add( "1.4.3-SNAPSHOT" );
138 populateDb( "org.codehaus.plexus", "plexus-utils", versions );