mirror of https://github.com/apache/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
This commit is contained in:
parent
9991433b42
commit
42edbc5ca5
|
@ -20,12 +20,16 @@ package org.apache.archiva.consumers.core;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
|
||||||
import org.apache.archiva.common.utils.BaseFile;
|
import org.apache.archiva.common.utils.BaseFile;
|
||||||
import org.apache.archiva.configuration.ArchivaConfiguration;
|
import org.apache.archiva.configuration.ArchivaConfiguration;
|
||||||
import org.apache.archiva.configuration.FileType;
|
import org.apache.archiva.configuration.FileType;
|
||||||
import org.apache.archiva.configuration.FileTypes;
|
import org.apache.archiva.configuration.FileTypes;
|
||||||
import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
|
import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
|
||||||
import org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate;
|
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.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
@ -37,7 +41,7 @@ import javax.inject.Inject;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
@RunWith( SpringJUnit4ClassRunner.class )
|
@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
|
public abstract class AbstractArtifactConsumerTest
|
||||||
extends TestCase
|
extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -51,6 +55,10 @@ public abstract class AbstractArtifactConsumerTest
|
||||||
@Inject
|
@Inject
|
||||||
ArchivaConfiguration archivaConfiguration;
|
ArchivaConfiguration archivaConfiguration;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected PlexusSisuBridge plexusSisuBridge;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp()
|
public void setUp()
|
||||||
throws Exception
|
throws Exception
|
||||||
|
@ -65,6 +73,18 @@ public abstract class AbstractArtifactConsumerTest
|
||||||
repoLocation = new File( "target/test-" + getName() + "/test-repo" );
|
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
|
@Test
|
||||||
public void testConsumption()
|
public void testConsumption()
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,12 +21,18 @@ package org.apache.archiva.consumers.core.repository;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import org.apache.archiva.admin.model.beans.ManagedRepository;
|
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.MetadataRepository;
|
||||||
import org.apache.archiva.metadata.repository.RepositorySession;
|
import org.apache.archiva.metadata.repository.RepositorySession;
|
||||||
|
import org.apache.archiva.repository.ManagedRepositoryContent;
|
||||||
import org.apache.archiva.repository.events.RepositoryListener;
|
import org.apache.archiva.repository.events.RepositoryListener;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
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.easymock.MockControl;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -93,6 +99,11 @@ public abstract class AbstractRepositoryPurgeTest
|
||||||
@Inject
|
@Inject
|
||||||
protected ApplicationContext applicationContext;
|
protected ApplicationContext applicationContext;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected PlexusSisuBridge plexusSisuBridge;
|
||||||
|
|
||||||
|
ArchivaConfiguration previousArchivaConfiguration;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp()
|
public void setUp()
|
||||||
throws Exception
|
throws Exception
|
||||||
|
@ -106,15 +117,24 @@ public abstract class AbstractRepositoryPurgeTest
|
||||||
repositorySession = mock( RepositorySession.class );
|
repositorySession = mock( RepositorySession.class );
|
||||||
metadataRepository = mock( MetadataRepository.class );
|
metadataRepository = mock( MetadataRepository.class );
|
||||||
when( repositorySession.getRepository() ).thenReturn( metadataRepository );
|
when( repositorySession.getRepository() ).thenReturn( metadataRepository );
|
||||||
|
|
||||||
|
previousArchivaConfiguration = ( (DefaultManagedRepositoryAdmin) applicationContext.getBean(
|
||||||
|
ManagedRepositoryAdmin.class ) ).getArchivaConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown()
|
public void tearDown()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
NexusIndexer nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class );
|
||||||
|
for ( IndexingContext indexingContext : nexusIndexer.getIndexingContexts().values() )
|
||||||
|
{
|
||||||
|
nexusIndexer.removeIndexingContext( indexingContext, false );
|
||||||
|
}
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
config = null;
|
config = null;
|
||||||
repo = null;
|
repo = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ManagedRepository getRepoConfiguration( String repoId, String repoName )
|
public ManagedRepository getRepoConfiguration( String repoId, String repoName )
|
||||||
|
|
|
@ -91,13 +91,7 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
|
||||||
public void testReleasedSnapshotsExistsInSameRepo()
|
public void testReleasedSnapshotsExistsInSameRepo()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
/**
|
applicationContext.getBean( ManagedRepositoryAdmin.class ).deleteManagedRepository( TEST_REPO_ID, null, true );
|
||||||
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(
|
applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository(
|
||||||
getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ), false, null );
|
getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ), false, null );
|
||||||
|
|
||||||
|
@ -154,9 +148,6 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
|
||||||
public void testNonArtifactFile()
|
public void testNonArtifactFile()
|
||||||
throws Exception
|
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, false );
|
||||||
applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository(
|
applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository(
|
||||||
|
@ -187,12 +178,7 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
|
||||||
public void testReleasedSnapshotsExistsInDifferentRepo()
|
public void testReleasedSnapshotsExistsInDifferentRepo()
|
||||||
throws Exception
|
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 ).deleteManagedRepository( TEST_REPO_ID, null, false );
|
||||||
applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository(
|
applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository(
|
||||||
getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ), false, null );
|
getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ), false, null );
|
||||||
|
@ -241,11 +227,7 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
|
||||||
public void testHigherSnapshotExistsInSameRepo()
|
public void testHigherSnapshotExistsInSameRepo()
|
||||||
throws Exception
|
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, false );
|
||||||
applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository(
|
applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository(
|
||||||
getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ), false, null );
|
getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ), false, null );
|
||||||
|
|
|
@ -48,6 +48,14 @@ public class DaysOldRepositoryPurgeTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
super.tearDown();
|
||||||
|
repoPurge = null;
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testByLastModified()
|
public void testByLastModified()
|
||||||
throws Exception
|
throws Exception
|
||||||
|
@ -223,11 +231,5 @@ public class DaysOldRepositoryPurgeTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
super.tearDown();
|
|
||||||
repoPurge = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.beans.ManagedRepository;
|
||||||
import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
|
import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
|
||||||
import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
|
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.common.utils.BaseFile;
|
||||||
import org.apache.archiva.configuration.ArchivaConfiguration;
|
import org.apache.archiva.configuration.ArchivaConfiguration;
|
||||||
import org.apache.archiva.configuration.FileType;
|
import org.apache.archiva.configuration.FileType;
|
||||||
import org.apache.archiva.configuration.FileTypes;
|
import org.apache.archiva.configuration.FileTypes;
|
||||||
import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
|
import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
|
||||||
import org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate;
|
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.custommonkey.xmlunit.XMLAssert;
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
@ -54,6 +55,13 @@ public class RepositoryPurgeConsumerTest
|
||||||
factory.setRepository( metadataRepository );
|
factory.setRepository( metadataRepository );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConsumption()
|
public void testConsumption()
|
||||||
throws Exception
|
throws Exception
|
||||||
|
@ -181,16 +189,7 @@ public class RepositoryPurgeConsumerTest
|
||||||
applicationContext.getBean( "archivaConfiguration#" + configHint, ArchivaConfiguration.class );
|
applicationContext.getBean( "archivaConfiguration#" + configHint, ArchivaConfiguration.class );
|
||||||
( (DefaultManagedRepositoryAdmin) applicationContext.getBean(
|
( (DefaultManagedRepositoryAdmin) applicationContext.getBean(
|
||||||
ManagedRepositoryAdmin.class ) ).setArchivaConfiguration( archivaConfiguration );
|
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 );
|
ManagedRepositoryAdmin managedRepositoryAdmin = applicationContext.getBean( ManagedRepositoryAdmin.class );
|
||||||
if ( managedRepositoryAdmin.getManagedRepository( repoConfiguration.getId() ) != null )
|
if ( managedRepositoryAdmin.getManagedRepository( repoConfiguration.getId() ) != null )
|
||||||
{
|
{
|
||||||
|
@ -207,14 +206,7 @@ public class RepositoryPurgeConsumerTest
|
||||||
|
|
||||||
( (DefaultManagedRepositoryAdmin) applicationContext.getBean(
|
( (DefaultManagedRepositoryAdmin) applicationContext.getBean(
|
||||||
ManagedRepositoryAdmin.class ) ).setArchivaConfiguration( archivaConfiguration );
|
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 );
|
ManagedRepositoryAdmin managedRepositoryAdmin = applicationContext.getBean( ManagedRepositoryAdmin.class );
|
||||||
if ( managedRepositoryAdmin.getManagedRepository( repoConfiguration.getId() ) != null )
|
if ( managedRepositoryAdmin.getManagedRepository( repoConfiguration.getId() ) != null )
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.apache.archiva.consumers.core.repository;
|
||||||
|
|
||||||
import org.apache.archiva.admin.model.beans.ManagedRepository;
|
import org.apache.archiva.admin.model.beans.ManagedRepository;
|
||||||
import org.apache.archiva.repository.events.RepositoryListener;
|
import org.apache.archiva.repository.events.RepositoryListener;
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -45,6 +46,13 @@ public class RetentionCountRepositoryPurgeTest
|
||||||
repositorySession, listeners );
|
repositorySession, listeners );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if the artifact to be processed was a jar.
|
* Test if the artifact to be processed was a jar.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -111,7 +111,7 @@ public class DefaultManagedRepositoryAdmin
|
||||||
NexusIndexer indexer;
|
NexusIndexer indexer;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
private void initialize()
|
public void initialize()
|
||||||
throws RepositoryAdminException
|
throws RepositoryAdminException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -131,7 +131,7 @@ public class DefaultManagedRepositoryAdmin
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreDestroy
|
@PreDestroy
|
||||||
private void shutdown()
|
public void shutdown()
|
||||||
throws RepositoryAdminException
|
throws RepositoryAdminException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -371,7 +371,9 @@ public class DefaultManagedRepositoryAdmin
|
||||||
IndexingContext context = nexusIndexer.getIndexingContexts().get( repository.getId() );
|
IndexingContext context = nexusIndexer.getIndexingContexts().get( repository.getId() );
|
||||||
if ( context != null )
|
if ( context != null )
|
||||||
{
|
{
|
||||||
nexusIndexer.removeIndexingContext( context, deleteContent );
|
// delete content only if directory exists
|
||||||
|
nexusIndexer.removeIndexingContext( context,
|
||||||
|
deleteContent && context.getIndexDirectoryFile().exists() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch ( PlexusSisuBridgeException e )
|
catch ( PlexusSisuBridgeException e )
|
||||||
|
@ -586,6 +588,11 @@ public class DefaultManagedRepositoryAdmin
|
||||||
indexDirectory = new File( managedRepository, ".indexer" );
|
indexDirectory = new File( managedRepository, ".indexer" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !indexDirectory.exists() )
|
||||||
|
{
|
||||||
|
indexDirectory.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
context =
|
context =
|
||||||
indexer.addIndexingContext( repository.getId(), repository.getId(), managedRepository, indexDirectory,
|
indexer.addIndexingContext( repository.getId(), repository.getId(), managedRepository, indexDirectory,
|
||||||
managedRepository.toURI().toURL().toExternalForm(),
|
managedRepository.toURI().toURL().toExternalForm(),
|
||||||
|
|
Loading…
Reference in New Issue