View Javadoc

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       * @throws Exception
48       */
49      public void testIfAJarWasFound()
50          throws Exception
51      {
52          String repoRoot = prepareTestRepos();
53  
54          // test listeners for the correct artifacts
55          listener.deleteArtifact( getRepository(), createArtifact( "org.jruby.plugins", "jruby-rake-plugin",
56                                                                    "1.0RC1-20070504.153317-1", "jar" ) );
57          listener.deleteArtifact( getRepository(), createArtifact( "org.jruby.plugins", "jruby-rake-plugin",
58                                                                    "1.0RC1-20070504.153317-1", "pom" ) );
59          listener.deleteArtifact( getRepository(), createArtifact( "org.jruby.plugins", "jruby-rake-plugin",
60                                                                    "1.0RC1-20070504.160758-2", "jar" ) );
61          listener.deleteArtifact( getRepository(), createArtifact( "org.jruby.plugins", "jruby-rake-plugin",
62                                                                    "1.0RC1-20070504.160758-2", "pom" ) );
63          listenerControl.replay();
64          
65          repoPurge.process( PATH_TO_BY_RETENTION_COUNT_ARTIFACT );
66          
67          listenerControl.verify();
68  
69          String versionRoot = repoRoot + "/org/jruby/plugins/jruby-rake-plugin/1.0RC1-SNAPSHOT";
70  
71          // assert if removed from repo
72          assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar" );
73          assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.md5" );
74          assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.sha1" );
75          assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom" );
76          assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.md5" );
77          assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.sha1" );
78  
79          assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar" );
80          assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.md5" );
81          assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.sha1" );
82          assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom" );
83          assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.md5" );
84          assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.sha1" );
85  
86          // assert if not removed from repo
87          assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar" );
88          assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.md5" );
89          assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.sha1" );
90          assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom" );
91          assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.md5" );
92          assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.sha1" );
93  
94          assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar" );
95          assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.md5" );
96          assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.sha1" );
97          assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom" );
98          assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.md5" );
99          assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.sha1" );
100     }
101 
102     /**
103      * Test if the artifact to be processed is a pom
104      *
105      * @throws Exception
106      */
107     public void testIfAPomWasFound()
108         throws Exception
109     {
110         String repoRoot = prepareTestRepos();
111 
112         // test listeners for the correct artifacts
113         listener.deleteArtifact( getRepository(), createArtifact( "org.codehaus.castor", "castor-anttasks",
114                                                                   "1.1.2-20070427.065136-1", "jar" ) );
115         listener.deleteArtifact( getRepository(), createArtifact( "org.codehaus.castor", "castor-anttasks",
116                                                                   "1.1.2-20070427.065136-1", "pom" ) );
117         listenerControl.replay();
118         
119         repoPurge.process( PATH_TO_BY_RETENTION_COUNT_POM );
120         
121         listenerControl.verify();
122 
123         String versionRoot = repoRoot + "/org/codehaus/castor/castor-anttasks/1.1.2-SNAPSHOT";
124         
125         // assert if removed from repo
126         assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar" );
127         assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar.md5" );
128         assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar.sha1" );
129         assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom" );
130         assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom.md5" );
131         assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom.sha1" );
132 
133         // assert if not removed from repo
134         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom" );
135         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom.md5" );
136         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom.sha1" );
137         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar" );
138         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar.md5" );
139         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar.sha1" );
140         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar" );
141         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar.md5" );
142         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar.sha1" );
143 
144         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom" );
145         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom.md5" );
146         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom.sha1" );
147         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar" );
148         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar.md5" );
149         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar.sha1" );
150         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar" );
151         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar.md5" );
152         assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar.sha1" );
153     }
154 
155     public void testOrderOfDeletion()
156         throws Exception
157     {
158         String repoRoot = prepareTestRepos();
159 
160         // test listeners for the correct artifacts
161         listener.deleteArtifact( getRepository(), createArtifact( "org.apache.maven.plugins", "maven-assembly-plugin",
162                                                                   "1.1.2-20070427.065136-1", "maven-plugin" ) );
163         listener.deleteArtifact( getRepository(), createArtifact( "org.apache.maven.plugins", "maven-assembly-plugin",
164                                                                   "1.1.2-20070427.065136-1", "pom" ) );
165         listenerControl.replay();
166         
167         repoPurge.process( PATH_TO_TEST_ORDER_OF_DELETION );
168 
169         listenerControl.verify();
170 
171         String versionRoot = repoRoot + 
172             "/org/apache/maven/plugins/maven-assembly-plugin/1.1.2-SNAPSHOT";
173         
174         assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar" );
175         assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.sha1" );
176         assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.md5" );
177         assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.pom" );
178         assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.sha1" );
179         assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.md5" );
180 
181         // the following should not have been deleted
182         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.jar" );
183         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.sha1" );
184         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.md5" );
185         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.pom" );
186         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.sha1" );
187         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.md5" );
188 
189         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.jar" );
190         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.sha1" );
191         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.md5" );
192         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.pom" );
193         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.sha1" );
194         assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.md5" );
195     }
196 }