]> source.dussan.org Git - archiva.git/commitdiff
fix tests in archiva-core-consumers
authorOlivier Lamy <olamy@apache.org>
Thu, 3 Nov 2011 14:29:43 +0000 (14:29 +0000)
committerOlivier Lamy <olamy@apache.org>
Thu, 3 Nov 2011 14:29:43 +0000 (14:29 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1197139 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/AbstractArtifactConsumerTest.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java

index 00b916f11c36ce587e3d4f84d3f97cc5c0334631..90582b761be220b8bae5db2dfb8a3eea1507b62c 100644 (file)
@@ -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()
     {
index 0831b49b183db10bb55c8e7407a8e4cc5fcbdf65..1c55ffdf19db1a8d23dd45feda499636ec0746bf 100644 (file)
@@ -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 )
index 78b66596bf043bf2d57949ee56a0d9790e832d56..514c381cbdbd6b65c5dacb058fa94f7670901160 100644 (file)
@@ -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 );
index 0f846983daa9742a168f899ecafbea1f3dda073b..1e248c3195b7c024c64f6312f73f1a6bbea23edd 100644 (file)
@@ -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;
-    }
+
 }
index 01fe6a594005161c21ea97dc52152d6e5d63aae4..81c2353dbc54bdfc0d89a882fda69155dbf926d7 100644 (file)
@@ -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 )
         {
index fa3805792b6ac403c3f73c2d20b64e4b929476d1..b2cdce460c3ed37a2157ff53693ff390a85706be 100644 (file)
@@ -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.
      */
index 9bb5cfd2d575a184d0f0ce0b667bd5ab96d4d1ff..2ae481a947bdb7a6287435f297d85e76c04b1b71 100644 (file)
@@ -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(),