1 package org.apache.archiva.consumers.core.repository;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import org.apache.archiva.admin.model.beans.ManagedRepository;
23 import org.apache.archiva.repository.events.RepositoryListener;
24 import org.junit.Before;
25 import org.junit.Test;
27 import java.util.Collections;
28 import java.util.List;
31 * Test RetentionsCountRepositoryPurgeTest
33 public class RetentionCountRepositoryPurgeTest
34 extends AbstractRepositoryPurgeTest
42 ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME );
43 List<RepositoryListener> listeners = Collections.singletonList( listener );
44 repoPurge = new RetentionCountRepositoryPurge( getRepository(), repoConfiguration.getRetentionCount(),
45 repositorySession, listeners );
49 * Test if the artifact to be processed was a jar.
52 public void testIfAJarWasFound()
55 String repoRoot = prepareTestRepos();
57 // test listeners for the correct artifacts
58 listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
59 "1.0RC1-20070504.153317-1", "jruby-rake-plugin-1.0RC1-20070504.153317-1.jar" );
60 listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
61 "1.0RC1-20070504.153317-1", "jruby-rake-plugin-1.0RC1-20070504.153317-1.pom" );
62 listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
63 "1.0RC1-20070504.160758-2", "jruby-rake-plugin-1.0RC1-20070504.160758-2.jar" );
64 listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
65 "1.0RC1-20070504.160758-2", "jruby-rake-plugin-1.0RC1-20070504.160758-2.pom" );
66 listenerControl.replay();
68 repoPurge.process( PATH_TO_BY_RETENTION_COUNT_ARTIFACT );
70 listenerControl.verify();
72 String versionRoot = repoRoot + "/org/jruby/plugins/jruby-rake-plugin/1.0RC1-SNAPSHOT";
74 // assert if removed from repo
75 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar" );
76 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.md5" );
77 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.sha1" );
78 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom" );
79 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.md5" );
80 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.sha1" );
82 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar" );
83 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.md5" );
84 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.sha1" );
85 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom" );
86 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.md5" );
87 assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.sha1" );
89 // assert if not removed from repo
90 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar" );
91 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.md5" );
92 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.sha1" );
93 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom" );
94 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.md5" );
95 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.sha1" );
97 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar" );
98 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.md5" );
99 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.sha1" );
100 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom" );
101 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.md5" );
102 assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.sha1" );
106 * Test if the artifact to be processed is a pom
109 public void testIfAPomWasFound()
112 String repoRoot = prepareTestRepos();
114 // test listeners for the correct artifacts
115 listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.castor", "castor-anttasks",
116 "1.1.2-20070427.065136-1", "castor-anttasks-1.1.2-20070427.065136-1.jar" );
117 listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.castor", "castor-anttasks",
118 "1.1.2-20070427.065136-1", "castor-anttasks-1.1.2-20070427.065136-1.pom" );
119 listenerControl.replay();
121 repoPurge.process( PATH_TO_BY_RETENTION_COUNT_POM );
123 listenerControl.verify();
125 String versionRoot = repoRoot + "/org/codehaus/castor/castor-anttasks/1.1.2-SNAPSHOT";
127 // assert if removed from repo
128 assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar" );
129 assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar.md5" );
130 assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar.sha1" );
131 assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom" );
132 assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom.md5" );
133 assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom.sha1" );
135 // assert if not removed from repo
136 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom" );
137 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom.md5" );
138 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom.sha1" );
139 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar" );
140 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar.md5" );
141 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar.sha1" );
142 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar" );
143 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar.md5" );
144 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar.sha1" );
146 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom" );
147 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom.md5" );
148 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom.sha1" );
149 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar" );
150 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar.md5" );
151 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar.sha1" );
152 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar" );
153 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar.md5" );
154 assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar.sha1" );
158 public void testOrderOfDeletion()
161 String repoRoot = prepareTestRepos();
163 // test listeners for the correct artifacts
164 listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins",
165 "maven-assembly-plugin", "1.1.2-20070427.065136-1",
166 "maven-assembly-plugin-1.1.2-20070427.065136-1.jar" );
167 listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins",
168 "maven-assembly-plugin", "1.1.2-20070427.065136-1",
169 "maven-assembly-plugin-1.1.2-20070427.065136-1.pom" );
170 listenerControl.replay();
172 repoPurge.process( PATH_TO_TEST_ORDER_OF_DELETION );
174 listenerControl.verify();
176 String versionRoot = repoRoot + "/org/apache/maven/plugins/maven-assembly-plugin/1.1.2-SNAPSHOT";
178 assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar" );
179 assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.sha1" );
180 assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.md5" );
181 assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.pom" );
182 assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.sha1" );
183 assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.md5" );
185 // the following should not have been deleted
186 assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.jar" );
187 assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.sha1" );
188 assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.md5" );
189 assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.pom" );
190 assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.sha1" );
191 assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.md5" );
193 assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.jar" );
194 assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.sha1" );
195 assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.md5" );
196 assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.pom" );
197 assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.sha1" );
198 assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.md5" );