*/
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;
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
{
@Inject
ArchivaConfiguration archivaConfiguration;
+ @Inject
+ protected PlexusSisuBridge plexusSisuBridge;
+
+
@Before
public void setUp()
throws Exception
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()
{
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;
@Inject
protected ApplicationContext applicationContext;
+ @Inject
+ protected PlexusSisuBridge plexusSisuBridge;
+
+ ArchivaConfiguration previousArchivaConfiguration;
+
@Before
public void setUp()
throws Exception
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 )
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 );
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(
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 );
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 );
}
}
+ @After
+ public void tearDown()
+ throws Exception
+ {
+ super.tearDown();
+ repoPurge = null;
+ }
+
@Test
public void testByLastModified()
throws Exception
}
}
- @After
- public void tearDown()
- throws Exception
- {
- super.tearDown();
- repoPurge = null;
- }
+
}
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;
factory.setRepository( metadataRepository );
}
+ @After
+ public void tearDown()
+ throws Exception
+ {
+ super.tearDown();
+ }
+
@Test
public void testConsumption()
throws Exception
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 )
{
( (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 )
{
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;
repositorySession, listeners );
}
+ @After
+ public void tearDown()
+ throws Exception
+ {
+ super.tearDown();
+ }
+
/**
* Test if the artifact to be processed was a jar.
*/
NexusIndexer indexer;
@PostConstruct
- private void initialize()
+ public void initialize()
throws RepositoryAdminException
{
try
}
@PreDestroy
- private void shutdown()
+ public void shutdown()
throws RepositoryAdminException
{
try
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 )
indexDirectory = new File( managedRepository, ".indexer" );
}
+ if ( !indexDirectory.exists() )
+ {
+ indexDirectory.mkdirs();
+ }
+
context =
indexer.addIndexingContext( repository.getId(), repository.getId(), managedRepository, indexDirectory,
managedRepository.toURI().toURL().toExternalForm(),