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.database.ArchivaDatabaseException;
24 import org.apache.maven.archiva.repository.metadata.MetadataTools;
25 import org.custommonkey.xmlunit.XMLAssert;
28 import java.util.ArrayList;
29 import java.util.List;
32 * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
34 public class CleanupReleasedSnapshotsRepositoryPurgeTest
35 extends AbstractRepositoryPurgeTest
37 protected void setUp()
42 MetadataTools metadataTools = (MetadataTools) lookup( MetadataTools.class );
44 repoPurge = new CleanupReleasedSnapshotsRepositoryPurge( getRepository(), dao, metadataTools );
47 public void testReleasedSnapshots()
50 populateReleasedSnapshotsTest();
52 String repoRoot = prepareTestRepo();
54 repoPurge.process( PATH_TO_RELEASED_SNAPSHOT );
56 String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-plugin-plugin";
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" );
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" );
79 // check if metadata file was updated
80 File artifactMetadataFile = new File( projectRoot + "/maven-metadata.xml" );
82 String metadataXml = FileUtils.readFileToString( artifactMetadataFile, null );
84 String expectedVersions = "<expected><versions><version>2.2</version>" +
85 "<version>2.3</version></versions></expected>";
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 );
94 public void testHigherSnapshotExists()
97 populateHigherSnapshotExistsTest();
99 String repoRoot = prepareTestRepo();
101 repoPurge.process( PATH_TO_HIGHER_SNAPSHOT_EXISTS );
103 String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-source-plugin";
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" );
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" );
123 // check if metadata file was updated
124 File artifactMetadataFile = new File( projectRoot + "/maven-metadata.xml" );
126 String metadataXml = FileUtils.readFileToString( artifactMetadataFile, null );
128 String expectedVersions = "<expected><versions><version>2.0.2</version>" +
129 "<version>2.0.4-SNAPSHOT</version></versions></expected>";
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 );
137 private void populateReleasedSnapshotsTest()
138 throws ArchivaDatabaseException
140 List<String> versions = new ArrayList<String>();
141 versions.add( "2.3-SNAPSHOT" );
143 populateDb( "org.apache.maven.plugins", "maven-plugin-plugin", versions );
146 private void populateHigherSnapshotExistsTest()
149 List<String> versions = new ArrayList<String>();
150 versions.add( "2.0.3-SNAPSHOT" );
152 populateDb( "org.apache.maven.plugins", "maven-source-plugin", versions );