diff options
author | Maria Odea B. Ching <oching@apache.org> | 2009-02-20 06:52:41 +0000 |
---|---|---|
committer | Maria Odea B. Ching <oching@apache.org> | 2009-02-20 06:52:41 +0000 |
commit | 48e96d554fa626f031aa0cc88dfb0b15270eeb08 (patch) | |
tree | b62f495623b3a9a1b485b70f067acf0043c4e160 /archiva-modules | |
parent | 57ebe9526abc785386ea8292306cd54a7ebdb7ab (diff) | |
download | archiva-48e96d554fa626f031aa0cc88dfb0b15270eeb08.tar.gz archiva-48e96d554fa626f031aa0cc88dfb0b15270eeb08.zip |
[MRM-1079]
o updated and activated tests for index cleanup consumer
o cleaned up index cleanup consumer
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@746169 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules')
3 files changed, 77 insertions, 67 deletions
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumer.java index dcc8d1f84..04d569b48 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumer.java @@ -41,7 +41,6 @@ import org.sonatype.nexus.index.NexusIndexer; import org.sonatype.nexus.index.context.IndexingContext; import org.sonatype.nexus.index.context.UnsupportedExistingLuceneIndexException; import org.sonatype.nexus.index.creator.AbstractIndexCreator; -import org.sonatype.nexus.index.creator.IndexerEngine; import java.io.File; import java.io.IOException; @@ -64,22 +63,17 @@ public class LuceneCleanupRemoveIndexedConsumer private ArtifactContextProducer artifactContextProducer; - private IndexerEngine indexerEngine; - private IndexingContext context; - public LuceneCleanupRemoveIndexedConsumer( RepositoryContentFactory repoFactory, NexusIndexer indexer, - IndexerEngine indexerEngine ) + public LuceneCleanupRemoveIndexedConsumer( RepositoryContentFactory repoFactory, NexusIndexer indexer ) { this.repoFactory = repoFactory; this.indexer = indexer; - this.indexerEngine = indexerEngine; this.artifactContextProducer = new DefaultArtifactContextProducer(); } public void beginScan() { - // TODO Auto-generated method stub } @@ -136,7 +130,6 @@ public class LuceneCleanupRemoveIndexedConsumer context.setSearchable( repository.isScanned() ); File artifactFile = new File( repoContent.getRepoRoot(), repoContent.toPath( artifact ) ); - System.out.println( "artifactFile :: " + artifactFile.getAbsolutePath() ); if ( !artifactFile.exists() ) { @@ -147,7 +140,7 @@ public class LuceneCleanupRemoveIndexedConsumer { //indexerEngine.remove( context, artifactContext ); - // hack for deleting documents - indexer engine's isn't working for me + // hack for deleting documents - indexer engine's remove(...) isn't working for me removeDocuments( artifactContext ); } } @@ -167,7 +160,7 @@ public class LuceneCleanupRemoveIndexedConsumer throw new ConsumerException( "Can't run index cleanup consumer: " + e.getMessage() ); } } - + private void removeDocuments( ArtifactContext ac ) throws IOException { @@ -209,4 +202,9 @@ public class LuceneCleanupRemoveIndexedConsumer { this.repoFactory = repoFactory; } + + public void setArtifactContextProducer( ArtifactContextProducer artifactContextProducer ) + { + this.artifactContextProducer = artifactContextProducer; + } } diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml index 6ed1feefc..ddfc400fc 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml @@ -12,6 +12,5 @@ <bean id="indexCleanupConsumer" class="org.apache.archiva.consumers.lucene.LuceneCleanupRemoveIndexedConsumer"> <constructor-arg ref="repositoryContentFactory"/> <constructor-arg ref="nexusIndexer#archiva"/> - <constructor-arg ref="indexerEngine"/> </bean> </beans>
\ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumerTest.java index 99c4091a5..570b11759 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumerTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/LuceneCleanupRemoveIndexedConsumerTest.java @@ -32,47 +32,48 @@ import org.easymock.MockControl; import org.easymock.classextension.MockClassControl; import org.sonatype.nexus.index.ArtifactContext; import org.sonatype.nexus.index.ArtifactContextProducer; -import org.sonatype.nexus.index.DefaultArtifactContextProducer; +import org.sonatype.nexus.index.ArtifactInfo; import org.sonatype.nexus.index.NexusIndexer; import org.sonatype.nexus.index.context.DefaultIndexingContext; import org.sonatype.nexus.index.context.IndexingContext; -import org.sonatype.nexus.index.creator.IndexerEngine; public class LuceneCleanupRemoveIndexedConsumerTest extends PlexusInSpringTestCase { private LuceneCleanupRemoveIndexedConsumer consumer; - + private MockControl indexerControl; - + private NexusIndexer indexer; - + private RepositoryContentFactory repoFactory; - + private MockControl repoFactoryControl; - + private ManagedRepositoryConfiguration repositoryConfig; - + + private MockControl contextProducerControl; + private ArtifactContextProducer artifactContextProducer; - - private IndexerEngine indexerEngine; - + + private MockControl acControl; + + private ArtifactContext ac; + public void setUp() - throws Exception + throws Exception { super.setUp(); - + indexerControl = MockControl.createControl( NexusIndexer.class ); indexerControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER ); - indexer = ( NexusIndexer ) indexerControl.getMock(); - + indexer = (NexusIndexer) indexerControl.getMock(); + repoFactoryControl = MockClassControl.createControl( RepositoryContentFactory.class ); - repoFactory = ( RepositoryContentFactory ) repoFactoryControl.getMock(); - - indexerEngine = ( IndexerEngine ) lookup( IndexerEngine.class ); - - consumer = new LuceneCleanupRemoveIndexedConsumer( repoFactory, indexer, indexerEngine ); - + repoFactory = (RepositoryContentFactory) repoFactoryControl.getMock(); + + consumer = new LuceneCleanupRemoveIndexedConsumer( repoFactory, indexer ); + repositoryConfig = new ManagedRepositoryConfiguration(); repositoryConfig.setId( "test-repo" ); repositoryConfig.setLocation( getBasedir() + "/target/test-classes/test-repo" ); @@ -80,28 +81,34 @@ public class LuceneCleanupRemoveIndexedConsumerTest repositoryConfig.setName( "Test Repository" ); repositoryConfig.setScanned( true ); repositoryConfig.setSnapshots( false ); - repositoryConfig.setReleases( true ); + repositoryConfig.setReleases( true ); repositoryConfig.setIndexDir( getBasedir() + "/target/test-classes/test-repo/.cleanup-index" ); - - artifactContextProducer = new DefaultArtifactContextProducer(); + + contextProducerControl = MockControl.createControl( ArtifactContextProducer.class ); + artifactContextProducer = (ArtifactContextProducer) contextProducerControl.getMock(); + + consumer.setArtifactContextProducer( artifactContextProducer ); + + acControl = MockClassControl.createControl( ArtifactContext.class ); + ac = (ArtifactContext) acControl.getMock(); } - - public void tearDown() + + public void tearDown() throws Exception { FileUtils.deleteDirectory( new File( repositoryConfig.getIndexDir() ) ); - + super.tearDown(); } - + public void testProcessArtifactArtifactDoesNotExist() throws Exception { - /*ArchivaArtifact artifact = + ArchivaArtifact artifact = new ArchivaArtifact( "org.apache.archiva", "archiva-lucene-consumers", "1.2", null, "jar", "test-repo" ); ManagedRepositoryContent repoContent = new ManagedDefaultRepositoryContent(); repoContent.setRepository( repositoryConfig ); - + IndexingContext context = new DefaultIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(), new File( repositoryConfig.getLocation() ), @@ -111,51 +118,57 @@ public class LuceneCleanupRemoveIndexedConsumerTest File artifactFile = new File( repositoryConfig.getLocation(), "org/apache/archiva/archiva-lucene-consumers/1.2/archiva-lucene-consumers-1.2.jar" ); - ArtifactContext artifactContext = artifactContextProducer.getArtifactContext( context, artifactFile ); - - repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( repositoryConfig.getId() ), repoContent ); + ArtifactInfo ai = new ArtifactInfo( "test-repo", "org.apache.archiva", "archiva-lucene-consumers", "1.2", null ); + + repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( repositoryConfig.getId() ), + repoContent ); indexerControl.expectAndReturn( indexer.addIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(), - new File( repositoryConfig.getLocation() ), - new File( repositoryConfig.getIndexDir() ), null, null, - NexusIndexer.FULL_INDEX ), context ); - indexer.deleteArtifactFromIndex( artifactContext, context ); - indexerControl.setVoidCallable(); - + new File( repositoryConfig.getLocation() ), + new File( repositoryConfig.getIndexDir() ), null, + null, NexusIndexer.FULL_INDEX ), context ); + contextProducerControl.expectAndReturn( artifactContextProducer.getArtifactContext( context, artifactFile ), ac ); + acControl.expectAndReturn( ac.getArtifactInfo(), ai ); + repoFactoryControl.replay(); indexerControl.replay(); - + contextProducerControl.replay(); + acControl.replay(); + consumer.processArchivaArtifact( artifact ); - + repoFactoryControl.verify(); - indexerControl.verify(); */ - } - + indexerControl.verify(); + contextProducerControl.verify(); + acControl.verify(); + } + public void testProcessArtifactArtifactExists() throws Exception { - /*ArchivaArtifact artifact = + ArchivaArtifact artifact = new ArchivaArtifact( "org.apache.maven.archiva", "archiva-lucene-cleanup", "1.0", null, "jar", "test-repo" ); ManagedRepositoryContent repoContent = new ManagedDefaultRepositoryContent(); repoContent.setRepository( repositoryConfig ); - + IndexingContext context = new DefaultIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(), new File( repositoryConfig.getLocation() ), new File( repositoryConfig.getIndexDir() ), null, null, NexusIndexer.FULL_INDEX, false ); - - repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( repositoryConfig.getId() ), repoContent ); + + repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( repositoryConfig.getId() ), + repoContent ); indexerControl.expectAndReturn( indexer.addIndexingContext( repositoryConfig.getId(), repositoryConfig.getId(), - new File( repositoryConfig.getLocation() ), - new File( repositoryConfig.getIndexDir() ), null, null, - NexusIndexer.FULL_INDEX ), context ); - + new File( repositoryConfig.getLocation() ), + new File( repositoryConfig.getIndexDir() ), null, + null, NexusIndexer.FULL_INDEX ), context ); + repoFactoryControl.replay(); indexerControl.replay(); - + consumer.processArchivaArtifact( artifact ); - + repoFactoryControl.verify(); - indexerControl.verify(); */ - } + indexerControl.verify(); + } } |