]> source.dussan.org Git - archiva.git/blob
55f53bf3c58d44aafd5836efcf58b6a5b2199096
[archiva.git] /
1 package org.apache.maven.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.commons.io.FileUtils;
23 import org.apache.maven.archiva.consumers.core.repository.stubs.LuceneRepositoryContentIndexStub;
24 import org.apache.maven.archiva.database.ArchivaDatabaseException;
25 import org.apache.maven.archiva.indexer.RepositoryContentIndex;
26 import org.apache.maven.archiva.repository.metadata.MetadataTools;
27 import org.custommonkey.xmlunit.XMLAssert;
28
29 import java.io.File;
30 import java.util.ArrayList;
31 import java.util.HashMap;
32 import java.util.List;
33 import java.util.Map;
34
35 /**
36  * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
37  */
38 public class CleanupReleasedSnapshotsRepositoryPurgeTest
39     extends AbstractRepositoryPurgeTest
40 {   
41     protected void setUp()
42         throws Exception
43     {
44         super.setUp();
45
46         Map<String, RepositoryContentIndex> map = new HashMap<String, RepositoryContentIndex>();
47         map.put( "filecontent", new LuceneRepositoryContentIndexStub() );
48         map.put( "hashcodes", new LuceneRepositoryContentIndexStub() );
49         map.put( "bytecode", new LuceneRepositoryContentIndexStub() );
50         
51         MetadataTools metadataTools = (MetadataTools) lookup( MetadataTools.class );
52         
53         repoPurge = new CleanupReleasedSnapshotsRepositoryPurge( getRepository(), dao, metadataTools, map );
54     }
55
56     public void testReleasedSnapshots()
57         throws Exception
58     {
59         populateReleasedSnapshotsTest();
60
61         String repoRoot = prepareTestRepo();
62         
63
64         repoPurge.process( PATH_TO_RELEASED_SNAPSHOT );
65
66         String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-plugin-plugin";
67         
68         // check if the snapshot was removed
69         assertDeleted( projectRoot + "/2.3-SNAPSHOT" );
70         assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar" );
71         assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.md5" );
72         assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.sha1" );
73         assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom" );
74         assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.md5" );
75         assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.sha1" );
76
77         // check if the released version was not removed
78         assertExists( projectRoot + "/2.3" );
79         assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3-sources.jar" );
80         assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3-sources.jar.md5" );
81         assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3-sources.jar.sha1" );
82         assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3.jar" );
83         assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3.jar.md5" );
84         assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3.jar.sha1" );
85         assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3.pom" );
86         assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3.pom.md5" );
87         assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3.pom.sha1" );
88
89         // check if metadata file was updated
90         File artifactMetadataFile = new File( projectRoot + "/maven-metadata.xml" );
91         
92         String metadataXml = FileUtils.readFileToString( artifactMetadataFile, null );
93         
94         String expectedVersions = "<expected><versions><version>2.2</version>" +
95                         "<version>2.3</version></versions></expected>";
96         
97         XMLAssert.assertXpathEvaluatesTo( "2.3", "//metadata/versioning/release", metadataXml );
98         XMLAssert.assertXpathEvaluatesTo( "2.3", "//metadata/versioning/latest", metadataXml );
99         XMLAssert.assertXpathsEqual( "//expected/versions/version", expectedVersions,
100                                      "//metadata/versioning/versions/version", metadataXml );
101         XMLAssert.assertXpathEvaluatesTo( "20070315032817", "//metadata/versioning/lastUpdated", metadataXml );
102     }
103
104     public void testHigherSnapshotExists()
105         throws Exception
106     {
107         populateHigherSnapshotExistsTest();
108
109         String repoRoot = prepareTestRepo();
110
111         repoPurge.process( PATH_TO_HIGHER_SNAPSHOT_EXISTS );
112         
113         String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-source-plugin";
114         
115         // check if the snapshot was not removed
116         assertExists( projectRoot + "/2.0.3-SNAPSHOT" );
117         assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar" );
118         assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar.md5" );
119         assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar.sha1" );
120         assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.pom" );
121         assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.pom.md5" );
122         assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.pom.sha1" );
123
124         // check if the released version was not removed
125         assertExists( projectRoot + "/2.0.4-SNAPSHOT" );
126         assertExists( projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.jar" );
127         assertExists( projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.jar.md5" );
128         assertExists( projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.jar.sha1" );
129         assertExists( projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.pom" );
130         assertExists( projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.pom.md5" );
131         assertExists( projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.pom.sha1" );
132
133         // check if metadata file was not updated (because nothing was removed)
134         File artifactMetadataFile = new File( projectRoot + "/maven-metadata.xml" );
135
136         String metadataXml = FileUtils.readFileToString( artifactMetadataFile, null );
137         
138         String expectedVersions = "<expected><versions><version>2.0.3-SNAPSHOT</version>" +
139                         "<version>2.0.4-SNAPSHOT</version></versions></expected>";
140         
141         XMLAssert.assertXpathEvaluatesTo( "2.0.4-SNAPSHOT", "//metadata/versioning/latest", metadataXml );
142         XMLAssert.assertXpathsEqual( "//expected/versions/version", expectedVersions,
143                                      "//metadata/versioning/versions/version", metadataXml );
144         XMLAssert.assertXpathEvaluatesTo( "20070427033345", "//metadata/versioning/lastUpdated", metadataXml );
145     }
146     
147     private void populateReleasedSnapshotsTest()
148         throws ArchivaDatabaseException
149     {
150         List<String> versions = new ArrayList<String>();
151         versions.add( "2.3-SNAPSHOT" );
152
153         populateDb( "org.apache.maven.plugins", "maven-plugin-plugin", versions );
154     }
155
156     private void populateHigherSnapshotExistsTest()
157         throws Exception
158     {
159         List<String> versions = new ArrayList<String>();
160         versions.add( "2.0.3-SNAPSHOT" );
161
162         populateDb( "org.apache.maven.plugins", "maven-source-plugin", versions );
163     }
164
165 }