1 package org.apache.archiva.consumers.lucene;
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
24 import org.apache.commons.io.FileUtils;
25 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
26 import org.apache.maven.archiva.model.ArchivaArtifact;
27 import org.apache.maven.archiva.repository.ManagedRepositoryContent;
28 import org.apache.maven.archiva.repository.RepositoryContentFactory;
29 import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent;
30 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
31 import org.easymock.MockControl;
32 import org.easymock.classextension.MockClassControl;
33 import org.sonatype.nexus.index.ArtifactContext;
34 import org.sonatype.nexus.index.ArtifactContextProducer;
35 import org.sonatype.nexus.index.IndexerEngine;
36 import org.sonatype.nexus.index.context.IndexingContext;
38 public class LuceneCleanupRemoveIndexedConsumerTest
39 extends PlexusInSpringTestCase
41 private LuceneCleanupRemoveIndexedConsumer consumer;
43 private RepositoryContentFactory repoFactory;
45 private MockControl repoFactoryControl;
47 private ManagedRepositoryConfiguration repositoryConfig;
49 private MockControl indexerEngineControl;
51 private IndexerEngine indexerEngine;
53 private MockControl contextProducerControl;
55 private ArtifactContextProducer artifactContextProducer;
57 private MockControl acControl;
59 private ArtifactContext ac;
66 indexerEngineControl = MockControl.createControl( IndexerEngine.class );
67 indexerEngineControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
68 indexerEngine = (IndexerEngine) indexerEngineControl.getMock();
70 repoFactoryControl = MockClassControl.createControl( RepositoryContentFactory.class );
71 repoFactory = (RepositoryContentFactory) repoFactoryControl.getMock();
73 consumer = new LuceneCleanupRemoveIndexedConsumer( repoFactory, indexerEngine );
75 repositoryConfig = new ManagedRepositoryConfiguration();
76 repositoryConfig.setId( "test-repo" );
77 repositoryConfig.setLocation( getBasedir() + "/target/test-classes/test-repo" );
78 repositoryConfig.setLayout( "default" );
79 repositoryConfig.setName( "Test Repository" );
80 repositoryConfig.setScanned( true );
81 repositoryConfig.setSnapshots( false );
82 repositoryConfig.setReleases( true );
83 repositoryConfig.setIndexDir( getBasedir() + "/target/test-classes/test-repo/.cleanup-index" );
85 contextProducerControl = MockControl.createControl( ArtifactContextProducer.class );
86 contextProducerControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
87 artifactContextProducer = (ArtifactContextProducer) contextProducerControl.getMock();
89 consumer.setArtifactContextProducer( artifactContextProducer );
91 acControl = MockClassControl.createControl( ArtifactContext.class );
92 ac = (ArtifactContext) acControl.getMock();
95 public void tearDown()
98 FileUtils.deleteDirectory( new File( repositoryConfig.getIndexDir() ) );
103 public void testProcessArtifactArtifactDoesNotExist()
106 ArchivaArtifact artifact =
107 new ArchivaArtifact( "org.apache.archiva", "archiva-lucene-consumers", "1.2", null, "jar", "test-repo" );
108 ManagedRepositoryContent repoContent = new ManagedDefaultRepositoryContent();
109 repoContent.setRepository( repositoryConfig );
111 IndexingContext context = null;
114 new File( repositoryConfig.getLocation(),
115 "org/apache/archiva/archiva-lucene-consumers/1.2/archiva-lucene-consumers-1.2.jar" );
117 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( repositoryConfig.getId() ),
119 contextProducerControl.expectAndReturn( artifactContextProducer.getArtifactContext( context, artifactFile ), ac );
120 indexerEngine.remove( context, ac );
121 indexerEngineControl.setDefaultVoidCallable();
123 repoFactoryControl.replay();
124 contextProducerControl.replay();
125 indexerEngineControl.replay();
127 consumer.processArchivaArtifact( artifact );
129 repoFactoryControl.verify();
130 contextProducerControl.verify();
131 indexerEngineControl.verify();
134 public void testProcessArtifactArtifactExists()
137 ArchivaArtifact artifact =
138 new ArchivaArtifact( "org.apache.maven.archiva", "archiva-lucene-cleanup", "1.0", null, "jar", "test-repo" );
139 ManagedRepositoryContent repoContent = new ManagedDefaultRepositoryContent();
140 repoContent.setRepository( repositoryConfig );
142 repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( repositoryConfig.getId() ),
145 repoFactoryControl.replay();
147 consumer.processArchivaArtifact( artifact );
149 repoFactoryControl.verify();