]> source.dussan.org Git - archiva.git/commitdiff
Making application context dirty after each test class run
authorMartin Stockhammer <martin_s@apache.org>
Wed, 27 Jan 2021 21:17:34 +0000 (22:17 +0100)
committerMartin Stockhammer <martin_s@apache.org>
Wed, 27 Jan 2021 21:17:34 +0000 (22:17 +0100)
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-test-utils/src/main/java/org/apache/archiva/test/utils/ArchivaSpringJUnit4ClassRunner.java
archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java
archiva-modules/metadata/metadata-store-provider/oak-jcr/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/stats/JcrRepositoryStatisticsGatheringTest.java

index 0ff779ffee6a7a587c2db10669bcce407082a99d..e0197f19c12d55657309d9643a5e0b94308969bf 100644 (file)
@@ -33,6 +33,7 @@ import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.context.ApplicationContext;
+import org.springframework.test.annotation.DirtiesContext;
 import org.springframework.test.context.ContextConfiguration;
 
 import javax.inject.Inject;
@@ -55,15 +56,12 @@ public abstract class AbstractArtifactConsumerTest
     @Inject
     ArchivaConfiguration archivaConfiguration;
 
-    ArchivaRepositoryRegistry repositoryRegistry;
-
-
     @Before
     public void setUp()
         throws Exception
     {
         FileType fileType =
-            (FileType) archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
+            archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
         assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
         fileType.addPattern( "**/*.xml" );
         archivaConfiguration.getConfiguration().getArchivaRuntimeConfiguration().addChecksumType("MD5");
@@ -71,14 +69,6 @@ public abstract class AbstractArtifactConsumerTest
         archivaConfiguration.getConfiguration().getArchivaRuntimeConfiguration().addChecksumType("SHA256");
 
         repoLocation = Paths.get( "target/test-" + getName() + "/test-repo" );
-
-        repositoryRegistry = applicationContext.getBean( "repositoryRegistry", ArchivaRepositoryRegistry.class );
-        assertNotNull( repositoryRegistry );
-    }
-
-    @After
-    public void destroy() {
-        repositoryRegistry.destroy();
     }
 
 
index 2f906a5865c396f79444115d3430acdb5024f937..f1791b7d0156ae4927db534f3e11188b9850b837 100644 (file)
@@ -42,6 +42,7 @@ import org.junit.Before;
 import org.junit.runner.RunWith;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.ApplicationContext;
+import org.springframework.test.annotation.DirtiesContext;
 import org.springframework.test.context.ContextConfiguration;
 
 import javax.inject.Inject;
@@ -109,8 +110,6 @@ public abstract class AbstractRepositoryPurgeTest
 
     protected MetadataRepository metadataRepository;
 
-    protected ArchivaRepositoryRegistry repositoryRegistry;
-
     @Inject
     protected ApplicationContext applicationContext;
 
@@ -130,8 +129,6 @@ public abstract class AbstractRepositoryPurgeTest
         repositorySession = sessionControl.createMock( RepositorySession.class );
         metadataRepository = mock( MetadataRepository.class );
         sessionFactory = sessionFactoryControl.createMock( RepositorySessionFactory.class );
-        repositoryRegistry = applicationContext.getBean( "repositoryRegistry", ArchivaRepositoryRegistry.class );
-        assertNotNull( repositoryRegistry );
         EasyMock.expect( repositorySession.getRepository() ).andStubReturn( metadataRepository );
         EasyMock.expect( sessionFactory.createSession( ) ).andStubReturn( repositorySession );
 
@@ -143,8 +140,6 @@ public abstract class AbstractRepositoryPurgeTest
     {
         config = null;
         repo = null;
-        repositoryRegistry.destroy();
-
     }
 
 
index 81a915898eba543666124014c30b5112f557a5bd..8e48cd1b3036d5c0a498ac5dc09081bad66fb2d0 100644 (file)
@@ -18,6 +18,8 @@ package org.apache.archiva.test.utils;
 
 import org.junit.runners.model.FrameworkMethod;
 import org.junit.runners.model.InitializationError;
+import org.junit.runners.model.Statement;
+import org.springframework.test.context.TestContextManager;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
 import java.io.IOException;
@@ -57,4 +59,18 @@ public class ArchivaSpringJUnit4ClassRunner
     }
 
 
+    @Override
+    protected Statement withAfterClasses( final Statement statement )
+    {
+        final TestContextManager cm = getTestContextManager( );
+        return new Statement( )
+        {
+            @Override
+            public void evaluate( ) throws Throwable
+            {
+                statement.evaluate();
+                cm.getTestContext( ).markApplicationContextDirty( null );
+            }
+        };
+    }
 }
index 65b6b3e1d2816bc5704adb2a36623c7b92623c75..b29f7da345e918e76013a99d8c6082b47c275cf6 100644 (file)
@@ -31,6 +31,7 @@ import org.junit.runner.RunWith;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
 import java.text.SimpleDateFormat;
 import java.time.ZoneId;
@@ -41,7 +42,7 @@ import java.util.stream.Stream;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-@RunWith( ArchivaSpringJUnit4ClassRunner.class )
+@RunWith( SpringJUnit4ClassRunner.class )
 @ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml"} )
 public abstract class AbstractMetadataRepositoryTest
     extends TestCase
index c10103a16001fd1b9a440672b394c768a69a7cae..35166df414482828946f284f57fdef2c51cf4bc4 100644 (file)
@@ -43,6 +43,7 @@ import org.junit.runner.RunWith;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
 import javax.jcr.ImportUUIDBehavior;
 import javax.jcr.Node;
@@ -62,7 +63,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.zip.GZIPInputStream;
 
-@RunWith( ArchivaSpringJUnit4ClassRunner.class )
+@RunWith( SpringJUnit4ClassRunner.class )
 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
 public class JcrRepositoryStatisticsGatheringTest
     extends TestCase