From: Olivier Lamy Date: Thu, 3 Nov 2011 14:29:43 +0000 (+0000) Subject: fix tests in archiva-core-consumers X-Git-Tag: archiva-1.4-M2~174 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=42edbc5ca57ee217c81effa9a2d89838e112ad66;p=archiva.git fix tests in archiva-core-consumers git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1197139 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/AbstractArtifactConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/AbstractArtifactConsumerTest.java index 00b916f11..90582b761 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/AbstractArtifactConsumerTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/AbstractArtifactConsumerTest.java @@ -20,12 +20,16 @@ package org.apache.archiva.consumers.core; */ import junit.framework.TestCase; +import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.archiva.common.utils.BaseFile; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.FileType; import org.apache.archiva.configuration.FileTypes; import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate; +import org.apache.maven.index.NexusIndexer; +import org.apache.maven.index.context.IndexingContext; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -37,7 +41,7 @@ import javax.inject.Inject; import java.io.File; @RunWith( SpringJUnit4ClassRunner.class ) -@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml","classpath:/spring-context.xml"} ) +@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } ) public abstract class AbstractArtifactConsumerTest extends TestCase { @@ -51,6 +55,10 @@ public abstract class AbstractArtifactConsumerTest @Inject ArchivaConfiguration archivaConfiguration; + @Inject + protected PlexusSisuBridge plexusSisuBridge; + + @Before public void setUp() throws Exception @@ -65,6 +73,18 @@ public abstract class AbstractArtifactConsumerTest repoLocation = new File( "target/test-" + getName() + "/test-repo" ); } + @After + public void tearDown() + throws Exception + { + NexusIndexer nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class ); + for ( IndexingContext indexingContext : nexusIndexer.getIndexingContexts().values() ) + { + nexusIndexer.removeIndexingContext( indexingContext, false ); + } + } + + @Test public void testConsumption() { diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java index 0831b49b1..1c55ffdf1 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java @@ -21,12 +21,18 @@ package org.apache.archiva.consumers.core.repository; import junit.framework.TestCase; import org.apache.archiva.admin.model.beans.ManagedRepository; +import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; +import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin; +import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; +import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.RepositorySession; +import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.events.RepositoryListener; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; -import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.maven.index.NexusIndexer; +import org.apache.maven.index.context.IndexingContext; import org.easymock.MockControl; import org.junit.After; import org.junit.Before; @@ -93,6 +99,11 @@ public abstract class AbstractRepositoryPurgeTest @Inject protected ApplicationContext applicationContext; + @Inject + protected PlexusSisuBridge plexusSisuBridge; + + ArchivaConfiguration previousArchivaConfiguration; + @Before public void setUp() throws Exception @@ -106,15 +117,24 @@ public abstract class AbstractRepositoryPurgeTest repositorySession = mock( RepositorySession.class ); metadataRepository = mock( MetadataRepository.class ); when( repositorySession.getRepository() ).thenReturn( metadataRepository ); + + previousArchivaConfiguration = ( (DefaultManagedRepositoryAdmin) applicationContext.getBean( + ManagedRepositoryAdmin.class ) ).getArchivaConfiguration(); } @After public void tearDown() throws Exception { + NexusIndexer nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class ); + for ( IndexingContext indexingContext : nexusIndexer.getIndexingContexts().values() ) + { + nexusIndexer.removeIndexingContext( indexingContext, false ); + } super.tearDown(); config = null; repo = null; + } public ManagedRepository getRepoConfiguration( String repoId, String repoName ) diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java index 78b66596b..514c381cb 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java @@ -91,13 +91,7 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest public void testReleasedSnapshotsExistsInSameRepo() throws Exception { - /** - Configuration config = archivaConfiguration.getConfiguration(); - config.removeManagedRepository( config.findManagedRepositoryById( TEST_REPO_ID ) ); - config.addManagedRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ) ); - **/ - - applicationContext.getBean( ManagedRepositoryAdmin.class ).deleteManagedRepository( TEST_REPO_ID, null, false ); + applicationContext.getBean( ManagedRepositoryAdmin.class ).deleteManagedRepository( TEST_REPO_ID, null, true ); applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ), false, null ); @@ -154,9 +148,6 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest public void testNonArtifactFile() throws Exception { - /*Configuration config = archivaConfiguration.getConfiguration(); - config.removeManagedRepository( config.findManagedRepositoryById( TEST_REPO_ID ) ); - config.addManagedRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ) );*/ applicationContext.getBean( ManagedRepositoryAdmin.class ).deleteManagedRepository( TEST_REPO_ID, null, false ); applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository( @@ -187,12 +178,7 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest public void testReleasedSnapshotsExistsInDifferentRepo() throws Exception { - /* - Configuration config = archivaConfiguration.getConfiguration(); - config.removeManagedRepository( config.findManagedRepositoryById( TEST_REPO_ID ) ); - config.addManagedRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ) ); - config.addManagedRepository( getRepoConfiguration( RELEASES_TEST_REPO_ID, RELEASES_TEST_REPO_NAME ) ); - */ + applicationContext.getBean( ManagedRepositoryAdmin.class ).deleteManagedRepository( TEST_REPO_ID, null, false ); applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ), false, null ); @@ -241,11 +227,7 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest public void testHigherSnapshotExistsInSameRepo() throws Exception { - /* - Configuration config = archivaConfiguration.getConfiguration(); - config.removeManagedRepository( config.findManagedRepositoryById( TEST_REPO_ID ) ); - config.addManagedRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ) ); - */ + applicationContext.getBean( ManagedRepositoryAdmin.class ).deleteManagedRepository( TEST_REPO_ID, null, false ); applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ), false, null ); diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java index 0f846983d..1e248c319 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java @@ -48,6 +48,14 @@ public class DaysOldRepositoryPurgeTest } } + @After + public void tearDown() + throws Exception + { + super.tearDown(); + repoPurge = null; + } + @Test public void testByLastModified() throws Exception @@ -223,11 +231,5 @@ public class DaysOldRepositoryPurgeTest } } - @After - public void tearDown() - throws Exception - { - super.tearDown(); - repoPurge = null; - } + } diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java index 01fe6a594..81c2353db 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java @@ -22,15 +22,16 @@ package org.apache.archiva.consumers.core.repository; import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin; -import org.apache.archiva.metadata.repository.TestRepositorySessionFactory; -import org.apache.commons.io.FileUtils; import org.apache.archiva.common.utils.BaseFile; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.FileType; import org.apache.archiva.configuration.FileTypes; import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate; +import org.apache.archiva.metadata.repository.TestRepositorySessionFactory; +import org.apache.commons.io.FileUtils; import org.custommonkey.xmlunit.XMLAssert; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.springframework.test.context.ContextConfiguration; @@ -54,6 +55,13 @@ public class RepositoryPurgeConsumerTest factory.setRepository( metadataRepository ); } + @After + public void tearDown() + throws Exception + { + super.tearDown(); + } + @Test public void testConsumption() throws Exception @@ -181,16 +189,7 @@ public class RepositoryPurgeConsumerTest applicationContext.getBean( "archivaConfiguration#" + configHint, ArchivaConfiguration.class ); ( (DefaultManagedRepositoryAdmin) applicationContext.getBean( ManagedRepositoryAdmin.class ) ).setArchivaConfiguration( archivaConfiguration ); - /** - Configuration configuration = archivaConfiguration.getConfiguration(); - ManagedRepositoryConfiguration managedRepositoryConfiguration = - configuration.findManagedRepositoryById( repoConfiguration.getId() ); - if ( managedRepositoryConfiguration != null ) - { - configuration.removeManagedRepository( managedRepositoryConfiguration ); - } - configuration.addManagedRepository( repoConfiguration ); - **/ + ManagedRepositoryAdmin managedRepositoryAdmin = applicationContext.getBean( ManagedRepositoryAdmin.class ); if ( managedRepositoryAdmin.getManagedRepository( repoConfiguration.getId() ) != null ) { @@ -207,14 +206,7 @@ public class RepositoryPurgeConsumerTest ( (DefaultManagedRepositoryAdmin) applicationContext.getBean( ManagedRepositoryAdmin.class ) ).setArchivaConfiguration( archivaConfiguration ); - /** - Configuration configuration = archivaConfiguration.getConfiguration(); - ManagedRepositoryConfiguration managedRepositoryConfiguration = - configuration.findManagedRepositoryById( repoConfiguration.getId() ); - if ( managedRepositoryConfiguration != null ) - { - configuration.removeManagedRepository( managedRepositoryConfiguration ); - }*/ + ManagedRepositoryAdmin managedRepositoryAdmin = applicationContext.getBean( ManagedRepositoryAdmin.class ); if ( managedRepositoryAdmin.getManagedRepository( repoConfiguration.getId() ) != null ) { diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java index fa3805792..b2cdce460 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java @@ -21,6 +21,7 @@ package org.apache.archiva.consumers.core.repository; import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.repository.events.RepositoryListener; +import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -45,6 +46,13 @@ public class RetentionCountRepositoryPurgeTest repositorySession, listeners ); } + @After + public void tearDown() + throws Exception + { + super.tearDown(); + } + /** * Test if the artifact to be processed was a jar. */ diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java index 9bb5cfd2d..2ae481a94 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java @@ -111,7 +111,7 @@ public class DefaultManagedRepositoryAdmin NexusIndexer indexer; @PostConstruct - private void initialize() + public void initialize() throws RepositoryAdminException { try @@ -131,7 +131,7 @@ public class DefaultManagedRepositoryAdmin } @PreDestroy - private void shutdown() + public void shutdown() throws RepositoryAdminException { try @@ -371,7 +371,9 @@ public class DefaultManagedRepositoryAdmin IndexingContext context = nexusIndexer.getIndexingContexts().get( repository.getId() ); if ( context != null ) { - nexusIndexer.removeIndexingContext( context, deleteContent ); + // delete content only if directory exists + nexusIndexer.removeIndexingContext( context, + deleteContent && context.getIndexDirectoryFile().exists() ); } } catch ( PlexusSisuBridgeException e ) @@ -586,6 +588,11 @@ public class DefaultManagedRepositoryAdmin indexDirectory = new File( managedRepository, ".indexer" ); } + if ( !indexDirectory.exists() ) + { + indexDirectory.mkdirs(); + } + context = indexer.addIndexingContext( repository.getId(), repository.getId(), managedRepository, indexDirectory, managedRepository.toURI().toURL().toExternalForm(),