1 package org.apache.maven.archiva.consumers.core.repository;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.commons.lang.time.DateUtils;
23
24 import java.io.File;
25 import java.text.SimpleDateFormat;
26 import java.util.ArrayList;
27 import java.util.Calendar;
28 import java.util.Collections;
29 import java.util.List;
30
31
32
33 public class DaysOldRepositoryPurgeTest
34 extends AbstractRepositoryPurgeTest
35 {
36 private static final int OLD_TIMESTAMP = 1179382029;
37
38 private void setLastModified( String dirPath, long lastModified )
39 {
40 File dir = new File( dirPath );
41 File[] contents = dir.listFiles();
42 for ( int i = 0; i < contents.length; i++ )
43 {
44 contents[i].setLastModified( lastModified );
45 }
46 }
47
48 public void testByLastModified()
49 throws Exception
50 {
51 repoPurge =
52 new DaysOldRepositoryPurge( getRepository(),
53 getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ).getDaysOlder(),
54 getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ).getRetentionCount(),
55 Collections.singletonList( listener ) );
56
57 String repoRoot = prepareTestRepos();
58
59 String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-install-plugin";
60
61 setLastModified( projectRoot + "/2.2-SNAPSHOT/", OLD_TIMESTAMP );
62
63
64 listener.deleteArtifact( getRepository(), createArtifact( "org.apache.maven.plugins", "maven-install-plugin",
65 "2.2-SNAPSHOT", "maven-plugin" ) );
66 listener.deleteArtifact( getRepository(), createArtifact( "org.apache.maven.plugins", "maven-install-plugin",
67 "2.2-SNAPSHOT", "pom" ) );
68 listener.deleteArtifact( getRepository(), createArtifact( "org.apache.maven.plugins", "maven-install-plugin",
69 "2.2-20061118.060401-2", "maven-plugin" ) );
70 listener.deleteArtifact( getRepository(), createArtifact( "org.apache.maven.plugins", "maven-install-plugin",
71 "2.2-20061118.060401-2", "pom" ) );
72 listenerControl.replay();
73
74 repoPurge.process( PATH_TO_BY_DAYS_OLD_ARTIFACT );
75
76 listenerControl.verify();
77
78 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar" );
79 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.md5" );
80 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.sha1" );
81 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom" );
82 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.md5" );
83 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.sha1" );
84
85
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-20070510.010101-4.jar" );
94 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.md5" );
95 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.sha1" );
96 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom" );
97 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.md5" );
98 assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.sha1" );
99
100 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar" );
101 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.md5" );
102 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.sha1" );
103 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom" );
104 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.md5" );
105 assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.sha1" );
106 }
107
108 public void testOrderOfDeletion()
109 throws Exception
110 {
111 repoPurge =
112 new DaysOldRepositoryPurge( getRepository(), getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ).getDaysOlder(),
113 getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ).getRetentionCount(),
114 Collections.singletonList( listener ) );
115
116 String repoRoot = prepareTestRepos();
117
118 String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-assembly-plugin";
119
120 setLastModified( projectRoot + "/1.1.2-SNAPSHOT/", OLD_TIMESTAMP );
121
122
123 listener.deleteArtifact( getRepository(), createArtifact( "org.apache.maven.plugins", "maven-assembly-plugin",
124 "1.1.2-20070427.065136-1", "maven-plugin" ) );
125 listener.deleteArtifact( getRepository(), createArtifact( "org.apache.maven.plugins", "maven-assembly-plugin",
126 "1.1.2-20070427.065136-1", "pom" ) );
127 listenerControl.replay();
128
129 repoPurge.process( PATH_TO_TEST_ORDER_OF_DELETION );
130
131 listenerControl.verify();
132
133 assertDeleted( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.jar" );
134 assertDeleted( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.sha1" );
135 assertDeleted( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.md5" );
136 assertDeleted( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.pom" );
137 assertDeleted( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.sha1" );
138 assertDeleted( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.md5" );
139
140
141 assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.jar" );
142 assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.sha1" );
143 assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.md5" );
144 assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.pom" );
145 assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.sha1" );
146 assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.md5" );
147
148 assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.jar" );
149 assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.sha1" );
150 assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.md5" );
151 assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.pom" );
152 assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.sha1" );
153 assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.md5" );
154 }
155
156 public void testMetadataDrivenSnapshots()
157 throws Exception
158 {
159 repoPurge =
160 new DaysOldRepositoryPurge( getRepository(),
161 getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ).getDaysOlder(),
162 getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ).getRetentionCount(),
163 Collections.singletonList( listener ) );
164
165 String repoRoot = prepareTestRepos();
166
167 String versionRoot = repoRoot + "/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT";
168
169 Calendar currentDate = Calendar.getInstance( DateUtils.UTC_TIME_ZONE );
170 setLastModified( versionRoot, currentDate.getTimeInMillis() );
171
172 String timestamp = new SimpleDateFormat( "yyyyMMdd.HHmmss" ).format( currentDate.getTime() );
173
174 for ( int i = 5; i <= 7; i++ )
175 {
176 File jarFile = new File( versionRoot, "/plexus-utils-1.4.3-" + timestamp + "-" + i + ".jar" );
177 jarFile.createNewFile();
178 File pomFile = new File( versionRoot, "/plexus-utils-1.4.3-" + timestamp + "-" + i + ".pom" );
179 pomFile.createNewFile();
180
181
182 if ( i == 5 )
183 {
184 jarFile.setLastModified( OLD_TIMESTAMP );
185 pomFile.setLastModified( OLD_TIMESTAMP );
186 }
187 }
188
189 List<String> versions = new ArrayList<String>();
190 versions.add( "1.4.3-20070113.163208-4" );
191 versions.add( "1.4.3-" + timestamp + "-5" );
192 versions.add( "1.4.3-" + timestamp + "-6" );
193 versions.add( "1.4.3-" + timestamp + "-7" );
194 versions.add( "1.4.3-SNAPSHOT" );
195
196
197 listener.deleteArtifact( getRepository(), createArtifact( "org.codehaus.plexus", "plexus-utils",
198 "1.4.3-20070113.163208-4", "jar" ) );
199 listener.deleteArtifact( getRepository(), createArtifact( "org.codehaus.plexus", "plexus-utils",
200 "1.4.3-20070113.163208-4", "pom" ) );
201 listenerControl.replay();
202
203 repoPurge.process( PATH_TO_BY_DAYS_OLD_METADATA_DRIVEN_ARTIFACT );
204
205 listenerControl.verify();
206
207
208
209 assertDeleted( versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.jar" );
210 assertDeleted( versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.jar.sha1" );
211 assertDeleted( versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.pom" );
212 assertDeleted( versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.pom.sha1" );
213
214
215 assertExists( versionRoot + "/plexus-utils-1.4.3-SNAPSHOT.jar" );
216 assertExists( versionRoot + "/plexus-utils-1.4.3-SNAPSHOT.pom" );
217
218 for ( int i = 5; i <= 7; i++ )
219 {
220 assertExists( versionRoot + "/plexus-utils-1.4.3-" + timestamp + "-" + i + ".jar" );
221 assertExists( versionRoot + "/plexus-utils-1.4.3-" + timestamp + "-" + i + ".pom" );
222 }
223 }
224
225 protected void tearDown()
226 throws Exception
227 {
228 super.tearDown();
229 repoPurge = null;
230 }
231 }