]> source.dussan.org Git - archiva.git/blob
bf0f21f0e573f7c6de4dcd47efd1bfb9dc508009
[archiva.git] /
1 package org.apache.maven.archiva.consumers.core.repository;
2
3 /*
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
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  * under the License.
20  */
21
22 import java.io.File;
23 import java.util.ArrayList;
24 import java.util.List;
25
26 /**
27  * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
28  */
29 public class DaysOldRepositoryPurgeTest
30     extends AbstractRepositoryPurgeTest
31 {
32
33     protected void setUp()
34         throws Exception
35     {
36         super.setUp();
37
38         repoPurge =
39             new DaysOldRepositoryPurge( getRepository(), dao, getRepoConfiguration().getDaysOlder() );
40     }
41
42     private void setLastModified( String dirPath )
43     {
44         File dir = new File( dirPath );
45         File[] contents = dir.listFiles();
46         for ( int i = 0; i < contents.length; i++ )
47         {
48             contents[i].setLastModified( 1179382029 );
49         }
50     }
51
52     public void testByLastModified()
53         throws Exception
54     {
55         populateDbForTestByLastModified();
56
57         String repoRoot = prepareTestRepo();
58
59         String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-install-plugin";
60         
61         setLastModified( projectRoot + "/2.2-SNAPSHOT/" );
62
63         repoPurge.process( PATH_TO_BY_DAYS_OLD_ARTIFACT );
64
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" );
71     }
72
73     public void testMetadataDrivenSnapshots()
74         throws Exception
75     {
76         populateDbForTestMetadataDrivenSnapshots();
77
78         String repoRoot = prepareTestRepo();
79
80         repoPurge.process( PATH_TO_BY_DAYS_OLD_METADATA_DRIVEN_ARTIFACT );
81
82         String versionRoot = repoRoot + "/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT";
83         
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" );
90
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" );
96
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" );
101
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" );
106
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" );
110     }
111
112     protected void tearDown()
113         throws Exception
114     {
115         super.tearDown();
116         repoPurge = null;
117     }
118
119     private void populateDbForTestByLastModified()
120         throws Exception
121     {
122         List<String> versions = new ArrayList<String>();
123         versions.add( "2.2-SNAPSHOT" );
124
125         populateDb( "org.apache.maven.plugins", "maven-install-plugin", versions );
126     }
127
128     private void populateDbForTestMetadataDrivenSnapshots()
129         throws Exception
130     {
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" );
137
138         populateDb( "org.codehaus.plexus", "plexus-utils", versions );
139     }
140 }