]> source.dussan.org Git - archiva.git/blob
b161a1bc52bd36dfbf7077c139a652edb5802cc8
[archiva.git] /
1 package org.apache.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.archiva.admin.model.beans.ManagedRepository;
23 import org.apache.archiva.repository.events.RepositoryListener;
24 import org.junit.After;
25 import org.junit.Before;
26 import org.junit.Test;
27
28 import java.util.Collections;
29 import java.util.List;
30
31 /**
32  * Test RetentionsCountRepositoryPurgeTest
33  */
34 public class RetentionCountRepositoryPurgeTest
35     extends AbstractRepositoryPurgeTest
36 {
37     @Before
38     public void setUp()
39         throws Exception
40     {
41         super.setUp();
42
43         ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME );
44         List<RepositoryListener> listeners = Collections.singletonList( listener );
45         repoPurge = new RetentionCountRepositoryPurge( getRepository(), repoConfiguration.getRetentionCount(),
46                                                        repositorySession, listeners );
47     }
48
49     @After
50     public void tearDown()
51         throws Exception
52     {
53         super.tearDown();
54     }
55
56     /**
57      * Test if the artifact to be processed was a jar.
58      */
59     @Test
60     public void testIfAJarWasFound()
61         throws Exception
62     {
63         String repoRoot = prepareTestRepos();
64
65         // test listeners for the correct artifacts
66         listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
67                                  "1.0RC1-20070504.153317-1", "jruby-rake-plugin-1.0RC1-20070504.153317-1.jar" );
68         listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
69                                  "1.0RC1-20070504.153317-1", "jruby-rake-plugin-1.0RC1-20070504.153317-1.pom" );
70         listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
71                                  "1.0RC1-20070504.153317-1", "jruby-rake-plugin-1.0RC1-20070504.153317-1-javadoc.jar" );
72
73         listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
74                                  "1.0RC1-20070504.153317-1", "jruby-rake-plugin-1.0RC1-20070504.153317-1-javadoc.zip" );
75
76         listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
77                                  "1.0RC1-20070504.160758-2", "jruby-rake-plugin-1.0RC1-20070504.160758-2.jar" );
78
79         listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
80                                  "1.0RC1-20070504.160758-2", "jruby-rake-plugin-1.0RC1-20070504.160758-2-javadoc.jar" );
81
82         listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
83                                  "1.0RC1-20070504.160758-2", "jruby-rake-plugin-1.0RC1-20070504.160758-2-javadoc.zip" );
84
85         listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
86                                  "1.0RC1-20070504.160758-2", "jruby-rake-plugin-1.0RC1-20070504.160758-2.pom" );
87         listenerControl.replay();
88
89         repoPurge.process( PATH_TO_BY_RETENTION_COUNT_ARTIFACT );
90
91         listenerControl.verify();
92
93         String versionRoot = repoRoot + "/org/jruby/plugins/jruby-rake-plugin/1.0RC1-SNAPSHOT";
94
95         // assert if removed from repo
96         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar" );
97         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.md5" );
98         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.sha1" );
99         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom" );
100         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.md5" );
101         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.sha1" );
102
103         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar" );
104         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.md5" );
105         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.sha1" );
106         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom" );
107         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.md5" );
108         assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.sha1" );
109
110         // assert if not removed from repo
111         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar" );
112         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.md5" );
113         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.sha1" );
114         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom" );
115         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.md5" );
116         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.sha1" );
117
118         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar" );
119         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.md5" );
120         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.sha1" );
121         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom" );
122         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.md5" );
123         assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.sha1" );
124     }
125
126     /**
127      * Test if the artifact to be processed is a pom
128      */
129     @Test
130     public void testIfAPomWasFound()
131         throws Exception
132     {
133         String repoRoot = prepareTestRepos();
134
135         // test listeners for the correct artifacts
136         listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.castor", "castor-anttasks",
137                                  "1.1.2-20070427.065136-1", "castor-anttasks-1.1.2-20070427.065136-1.jar" );
138         listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.castor", "castor-anttasks",
139                                  "1.1.2-20070427.065136-1", "castor-anttasks-1.1.2-20070427.065136-1.pom" );
140         listenerControl.replay();
141
142         repoPurge.process( PATH_TO_BY_RETENTION_COUNT_POM );
143
144         listenerControl.verify();
145
146         String versionRoot = repoRoot + "/org/codehaus/castor/castor-anttasks/1.1.2-SNAPSHOT";
147
148         // assert if removed from repo
149         assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar" );
150         assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar.md5" );
151         assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar.sha1" );
152         assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom" );
153         assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom.md5" );
154         assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom.sha1" );
155
156         // assert if not removed from repo
157         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom" );
158         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom.md5" );
159         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom.sha1" );
160         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar" );
161         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar.md5" );
162         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar.sha1" );
163         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar" );
164         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar.md5" );
165         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar.sha1" );
166
167         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom" );
168         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom.md5" );
169         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom.sha1" );
170         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar" );
171         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar.md5" );
172         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar.sha1" );
173         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar" );
174         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar.md5" );
175         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar.sha1" );
176     }
177
178     @Test
179     public void testOrderOfDeletion()
180         throws Exception
181     {
182         String repoRoot = prepareTestRepos();
183
184         // test listeners for the correct artifacts
185         listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins",
186                                  "maven-assembly-plugin", "1.1.2-20070427.065136-1",
187                                  "maven-assembly-plugin-1.1.2-20070427.065136-1.jar" );
188         listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins",
189                                  "maven-assembly-plugin", "1.1.2-20070427.065136-1",
190                                  "maven-assembly-plugin-1.1.2-20070427.065136-1.pom" );
191         listenerControl.replay();
192
193         repoPurge.process( PATH_TO_TEST_ORDER_OF_DELETION );
194
195         listenerControl.verify();
196
197         String versionRoot = repoRoot + "/org/apache/maven/plugins/maven-assembly-plugin/1.1.2-SNAPSHOT";
198
199         assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar" );
200         assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.sha1" );
201         assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.md5" );
202         assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.pom" );
203         assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.sha1" );
204         assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.md5" );
205
206         // the following should not have been deleted
207         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.jar" );
208         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.sha1" );
209         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.md5" );
210         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.pom" );
211         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.sha1" );
212         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.md5" );
213
214         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.jar" );
215         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.sha1" );
216         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.md5" );
217         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.pom" );
218         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.sha1" );
219         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.md5" );
220     }
221 }