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.archiva.repository.events.RepositoryListener;
23 import org.apache.commons.io.FileUtils;
24 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
25 import org.apache.maven.archiva.model.ArchivaArtifact;
26 import org.apache.maven.archiva.repository.ManagedRepositoryContent;
27 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
28 import org.easymock.MockControl;
31 import java.io.IOException;
35 public abstract class AbstractRepositoryPurgeTest
36 extends PlexusInSpringTestCase
38 public static final String TEST_REPO_ID = "test-repo";
40 public static final String TEST_REPO_NAME = "Test Repository";
42 public static final int TEST_RETENTION_COUNT = 2;
44 public static final int TEST_DAYS_OLDER = 30;
46 public static final String PATH_TO_BY_DAYS_OLD_ARTIFACT = "org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar";
48 public static final String PATH_TO_BY_DAYS_OLD_METADATA_DRIVEN_ARTIFACT = "org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT/plexus-utils-1.4.3-20070113.163208-4.jar";
50 public static final String PATH_TO_BY_RETENTION_COUNT_ARTIFACT = "org/jruby/plugins/jruby-rake-plugin/1.0RC1-SNAPSHOT/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar";
52 public static final String PATH_TO_BY_RETENTION_COUNT_POM = "org/codehaus/castor/castor-anttasks/1.1.2-SNAPSHOT/castor-anttasks-1.1.2-20070506.163513-2.pom";
54 public static final String PATH_TO_TEST_ORDER_OF_DELETION = "org/apache/maven/plugins/maven-assembly-plugin/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.jar";
56 protected static final String RELEASES_TEST_REPO_ID = "releases-test-repo-one";
58 protected static final String RELEASES_TEST_REPO_NAME = "Releases Test Repo One";
60 private ManagedRepositoryConfiguration config;
62 private ManagedRepositoryContent repo;
64 protected RepositoryPurge repoPurge;
66 protected MockControl listenerControl;
68 protected RepositoryListener listener;
71 protected void setUp()
76 listenerControl = MockControl.createControl( RepositoryListener.class );
78 listener = (RepositoryListener) listenerControl.getMock();
82 protected void tearDown()
90 public ManagedRepositoryConfiguration getRepoConfiguration( String repoId, String repoName )
92 config = new ManagedRepositoryConfiguration();
93 config.setId( repoId );
94 config.setName( repoName );
95 config.setDaysOlder( TEST_DAYS_OLDER );
96 config.setLocation( getTestFile( "target/test-" + getName() + "/" + repoId ).getAbsolutePath() );
97 config.setReleases( true );
98 config.setSnapshots( true );
99 config.setDeleteReleasedSnapshots( true );
100 config.setRetentionCount( TEST_RETENTION_COUNT );
105 public ManagedRepositoryContent getRepository()
110 repo = (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, "default" );
111 repo.setRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ) );
117 protected void assertDeleted( String path )
119 assertFalse( "File should have been deleted: " + path, new File( path ).exists() );
122 protected void assertExists( String path )
124 assertTrue( "File should exist: " + path, new File( path ).exists() );
127 protected File getTestRepoRoot()
129 return getTestFile( "target/test-" + getName() + "/" + TEST_REPO_ID );
132 protected String prepareTestRepos()
135 File testDir = getTestRepoRoot();
136 FileUtils.deleteDirectory( testDir );
137 FileUtils.copyDirectory( getTestFile( "target/test-classes/" + TEST_REPO_ID ), testDir );
139 File releasesTestDir = getTestFile( "target/test-" + getName() + "/" + RELEASES_TEST_REPO_ID );
140 FileUtils.deleteDirectory( releasesTestDir );
141 FileUtils.copyDirectory( getTestFile( "target/test-classes/" + RELEASES_TEST_REPO_ID ), releasesTestDir );
143 return testDir.getAbsolutePath();
146 protected ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String type )
148 return new ArchivaArtifact( groupId, artifactId, version, null, type, TEST_REPO_ID );