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