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 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()
|
||||
{
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in New Issue