]> source.dussan.org Git - archiva.git/blob
2f488a7c91f5224f2be73dacab9ef6c4df2e8980
[archiva.git] /
1 package org.apache.maven.archiva.consumers.core.repository;
2
3 import java.util.Collections;
4
5 /*
6  * Licensed to the Apache Software Foundation (ASF) under one
7  * or more contributor license agreements.  See the NOTICE file
8  * distributed with this work for additional information
9  * regarding copyright ownership.  The ASF licenses this file
10  * to you under the Apache License, Version 2.0 (the
11  * "License"); you may not use this file except in compliance
12  * with the License.  You may obtain a copy of the License at
13  *
14  *   http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing,
17  * software distributed under the License is distributed on an
18  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19  * KIND, either express or implied.  See the License for the
20  * specific language governing permissions and limitations
21  * under the License.
22  */
23
24 /**
25  * Test RetentionsCountRepositoryPurgeTest
26  *
27  */
28 public class RetentionCountRepositoryPurgeTest
29     extends AbstractRepositoryPurgeTest
30 {
31
32     protected void setUp()
33         throws Exception
34     {
35         super.setUp();
36
37         repoPurge =
38             new RetentionCountRepositoryPurge(
39                                                getRepository(),
40                                                getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ).getRetentionCount(),
41                                                Collections.singletonList( listener ) );
42     }
43
44     /**
45      * Test if the artifact to be processed was a jar.
46      */
47     public void testIfAJarWasFound()
48         throws Exception
49     {
50         String repoRoot = prepareTestRepos();
51
52         // test listeners for the correct artifacts
53         listener.deleteArtifact( getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
54                                  "1.0RC1-20070504.153317-1", "jruby-rake-plugin-1.0RC1-20070504.153317-1.jar" );
55         listener.deleteArtifact( getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
56                                  "1.0RC1-20070504.153317-1", "jruby-rake-plugin-1.0RC1-20070504.153317-1.pom" );
57         listener.deleteArtifact( getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
58                                  "1.0RC1-20070504.160758-2", "jruby-rake-plugin-1.0RC1-20070504.160758-2.jar" );
59         listener.deleteArtifact( getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
60                                  "1.0RC1-20070504.160758-2", "jruby-rake-plugin-1.0RC1-20070504.160758-2.pom" );
61         listenerControl.replay();
62         
63         repoPurge.process( PATH_TO_BY_RETENTION_COUNT_ARTIFACT );
64         
65         listenerControl.verify();
66
67         String versionRoot = repoRoot + "/org/jruby/plugins/jruby-rake-plugin/1.0RC1-SNAPSHOT";
68
69         // assert if removed from repo
70         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar" );
71         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.md5" );
72         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.sha1" );
73         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom" );
74         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.md5" );
75         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.sha1" );
76
77         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar" );
78         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.md5" );
79         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.sha1" );
80         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom" );
81         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.md5" );
82         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.sha1" );
83
84         // assert if not removed from repo
85         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar" );
86         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.md5" );
87         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.sha1" );
88         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom" );
89         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.md5" );
90         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.sha1" );
91
92         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar" );
93         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.md5" );
94         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.sha1" );
95         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom" );
96         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.md5" );
97         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.sha1" );
98     }
99
100     /**
101      * Test if the artifact to be processed is a pom
102      */
103     public void testIfAPomWasFound()
104         throws Exception
105     {
106         String repoRoot = prepareTestRepos();
107
108         // test listeners for the correct artifacts
109         listener.deleteArtifact( getRepository().getId(), "org.codehaus.castor", "castor-anttasks",
110                                  "1.1.2-20070427.065136-1", "castor-anttasks-1.1.2-20070427.065136-1.jar" );
111         listener.deleteArtifact( getRepository().getId(), "org.codehaus.castor", "castor-anttasks",
112                                  "1.1.2-20070427.065136-1", "castor-anttasks-1.1.2-20070427.065136-1.pom" );
113         listenerControl.replay();
114         
115         repoPurge.process( PATH_TO_BY_RETENTION_COUNT_POM );
116         
117         listenerControl.verify();
118
119         String versionRoot = repoRoot + "/org/codehaus/castor/castor-anttasks/1.1.2-SNAPSHOT";
120         
121         // assert if removed from repo
122         assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar" );
123         assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar.md5" );
124         assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar.sha1" );
125         assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom" );
126         assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom.md5" );
127         assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom.sha1" );
128
129         // assert if not removed from repo
130         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom" );
131         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom.md5" );
132         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom.sha1" );
133         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar" );
134         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar.md5" );
135         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar.sha1" );
136         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar" );
137         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar.md5" );
138         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar.sha1" );
139
140         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom" );
141         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom.md5" );
142         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom.sha1" );
143         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar" );
144         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar.md5" );
145         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar.sha1" );
146         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar" );
147         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar.md5" );
148         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar.sha1" );
149     }
150
151     public void testOrderOfDeletion()
152         throws Exception
153     {
154         String repoRoot = prepareTestRepos();
155
156         // test listeners for the correct artifacts
157         listener.deleteArtifact( getRepository().getId(), "org.apache.maven.plugins", "maven-assembly-plugin",
158                                  "1.1.2-20070427.065136-1", "maven-assembly-plugin-1.1.2-20070427.065136-1.jar" );
159         listener.deleteArtifact( getRepository().getId(), "org.apache.maven.plugins", "maven-assembly-plugin",
160                                  "1.1.2-20070427.065136-1", "maven-assembly-plugin-1.1.2-20070427.065136-1.pom" );
161         listenerControl.replay();
162         
163         repoPurge.process( PATH_TO_TEST_ORDER_OF_DELETION );
164
165         listenerControl.verify();
166
167         String versionRoot = repoRoot + 
168             "/org/apache/maven/plugins/maven-assembly-plugin/1.1.2-SNAPSHOT";
169         
170         assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar" );
171         assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.sha1" );
172         assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.md5" );
173         assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.pom" );
174         assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.sha1" );
175         assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.md5" );
176
177         // the following should not have been deleted
178         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.jar" );
179         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.sha1" );
180         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.md5" );
181         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.pom" );
182         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.sha1" );
183         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.md5" );
184
185         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.jar" );
186         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.sha1" );
187         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.md5" );
188         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.pom" );
189         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.sha1" );
190         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.md5" );
191     }
192 }