]> source.dussan.org Git - archiva.git/blob
a96efa1e4bb1179137227b08d3cbb732161b1346
[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 org.apache.commons.io.FileUtils;
23
24 import java.util.List;
25 import java.util.ArrayList;
26 import java.io.File;
27
28 /**
29  * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
30  */
31 public class DaysOldRepositoryPurgeTest
32     extends AbstractRepositoryPurgeTest
33 {
34    
35     protected void setUp()
36         throws Exception
37     {
38         super.setUp();
39
40         repoPurge = new DaysOldRepositoryPurge( getRepository(), getLayout(), dao, getRepoConfiguration() );
41     }
42
43     private void setLastModified()
44     {
45         File dir =
46             new File( "target/test/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/" );
47         File[] contents = dir.listFiles();
48         for ( int i = 0; i < contents.length; i++ )
49         {
50             contents[i].setLastModified( 1179382029 );
51         }
52     }
53
54     public void testIfAJarIsFound()
55         throws Exception
56     {
57         populateDb();
58
59         File testDir = new File( "target/test" );
60         FileUtils.copyDirectoryToDirectory( new File( "target/test-classes/test-repo" ), testDir );
61
62         setLastModified();
63
64         repoPurge.process( PATH_TO_BY_DAYS_OLD_ARTIFACT );
65
66         assertFalse( new File(
67             "target/test/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar" ).exists() );
68         assertFalse( new File(
69             "target/test/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.md5" ).exists() );
70         assertFalse( new File(
71             "target/test/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.sha1" ).exists() );
72         assertFalse( new File(
73             "target/test/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom" ).exists() );
74         assertFalse( new File(
75             "target/test/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.md5" ).exists() );
76         assertFalse( new File(
77             "target/test/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.sha1" ).exists() );
78
79         FileUtils.deleteDirectory( testDir );
80     }
81
82     protected void tearDown()
83         throws Exception
84     {
85         super.tearDown();
86         repoPurge = null;
87     }
88
89     private void populateDb()
90         throws Exception
91     {
92         List versions = new ArrayList();
93         versions.add( "2.2-SNAPSHOT" );
94
95         populateDb( "org.apache.maven.plugins", "maven-install-plugin", versions );
96     }
97 }