]> source.dussan.org Git - archiva.git/blob
5468e8bc1db9152632f50d5f2e7a20c09b4787a7
[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.HashMap;
25 import java.util.List;
26 import java.util.Map;
27
28 import org.apache.maven.archiva.consumers.core.repository.stubs.LuceneRepositoryContentIndexStub;
29 import org.apache.maven.archiva.indexer.RepositoryContentIndex;
30
31 /**
32  * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
33  */
34 public class DaysOldRepositoryPurgeTest
35     extends AbstractRepositoryPurgeTest
36 {
37
38     private Map<String, RepositoryContentIndex> map;
39     
40     protected void setUp()
41         throws Exception
42     {
43         super.setUp();        
44     }
45
46     private void setLastModified( String dirPath )
47     {
48         File dir = new File( dirPath );
49         File[] contents = dir.listFiles();
50         for ( int i = 0; i < contents.length; i++ )
51         {
52             contents[i].setLastModified( 1179382029 );
53         }
54     }
55
56     public void testByLastModified()
57         throws Exception
58     {        
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 ) );        
63         
64         repoPurge =
65             new DaysOldRepositoryPurge( getRepository(), dao, getRepoConfiguration().getDaysOlder(), 
66                             getRepoConfiguration().getRetentionCount(), map );
67         
68         populateDbForTestByLastModified();
69
70         String repoRoot = prepareTestRepo();
71
72         String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-install-plugin";
73         
74         setLastModified( projectRoot + "/2.2-SNAPSHOT/" );
75
76         repoPurge.process( PATH_TO_BY_DAYS_OLD_ARTIFACT );
77         
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" );
84         
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" );
92         
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" );
99     }
100
101     public void testMetadataDrivenSnapshots()
102         throws Exception
103     {
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) );    
108         
109         repoPurge =
110             new DaysOldRepositoryPurge( getRepository(), dao, getRepoConfiguration().getDaysOlder(), 
111                             getRepoConfiguration().getRetentionCount(), map );
112         
113         populateDbForTestMetadataDrivenSnapshots();
114
115         String repoRoot = prepareTestRepo();
116
117         repoPurge.process( PATH_TO_BY_DAYS_OLD_METADATA_DRIVEN_ARTIFACT );
118
119         String versionRoot = repoRoot + "/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT";
120         
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" );
127
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" );
133
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" );
138
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" );
143
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" );
147     }
148
149     protected void tearDown()
150         throws Exception
151     {
152         super.tearDown();
153         repoPurge = null;
154     }
155
156     private void populateDbForTestByLastModified()
157         throws Exception
158     {
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" );
163
164         populateDb( "org.apache.maven.plugins", "maven-install-plugin", versions );
165     }
166
167     private void populateDbForTestMetadataDrivenSnapshots()
168         throws Exception
169     {
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" );
176
177         populateDb( "org.codehaus.plexus", "plexus-utils", versions );
178     }
179 }