1 package org.apache.maven.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.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;
30 import java.util.ArrayList;
31 import java.util.HashMap;
32 import java.util.List;
36 * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
38 public class CleanupReleasedSnapshotsRepositoryPurgeTest
39 extends AbstractRepositoryPurgeTest
41 protected void setUp()
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() );
51 MetadataTools metadataTools = (MetadataTools) lookup( MetadataTools.class );
53 repoPurge = new CleanupReleasedSnapshotsRepositoryPurge( getRepository(), dao, metadataTools, map );
56 public void testReleasedSnapshots()
59 populateReleasedSnapshotsTest();
61 String repoRoot = prepareTestRepo();
64 repoPurge.process( PATH_TO_RELEASED_SNAPSHOT );
66 String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-plugin-plugin";
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" );
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" );
89 // check if metadata file was updated
90 File artifactMetadataFile = new File( projectRoot + "/maven-metadata.xml" );
92 String metadataXml = FileUtils.readFileToString( artifactMetadataFile, null );
94 String expectedVersions = "<expected><versions><version>2.2</version>" +
95 "<version>2.3</version></versions></expected>";
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 );
104 public void testHigherSnapshotExists()
107 populateHigherSnapshotExistsTest();
109 String repoRoot = prepareTestRepo();
111 repoPurge.process( PATH_TO_HIGHER_SNAPSHOT_EXISTS );
113 String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-source-plugin";
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" );
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" );
133 // check if metadata file was not updated (because nothing was removed)
134 File artifactMetadataFile = new File( projectRoot + "/maven-metadata.xml" );
136 String metadataXml = FileUtils.readFileToString( artifactMetadataFile, null );
138 String expectedVersions = "<expected><versions><version>2.0.3-SNAPSHOT</version>" +
139 "<version>2.0.4-SNAPSHOT</version></versions></expected>";
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 );
147 private void populateReleasedSnapshotsTest()
148 throws ArchivaDatabaseException
150 List<String> versions = new ArrayList<String>();
151 versions.add( "2.3-SNAPSHOT" );
153 populateDb( "org.apache.maven.plugins", "maven-plugin-plugin", versions );
156 private void populateHigherSnapshotExistsTest()
159 List<String> versions = new ArrayList<String>();
160 versions.add( "2.0.3-SNAPSHOT" );
162 populateDb( "org.apache.maven.plugins", "maven-source-plugin", versions );