Making application context dirty after each test class run

This commit is contained in:
Martin Stockhammer 2021-01-27 22:17:34 +01:00
parent b32d75a85b
commit 8fa8083ef9
5 changed files with 23 additions and 20 deletions

View File

@ -33,6 +33,7 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import javax.inject.Inject; import javax.inject.Inject;
@ -55,15 +56,12 @@ public abstract class AbstractArtifactConsumerTest
@Inject @Inject
ArchivaConfiguration archivaConfiguration; ArchivaConfiguration archivaConfiguration;
ArchivaRepositoryRegistry repositoryRegistry;
@Before @Before
public void setUp() public void setUp()
throws Exception throws Exception
{ {
FileType fileType = FileType fileType =
(FileType) archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 ); archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
assertEquals( FileTypes.ARTIFACTS, fileType.getId() ); assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
fileType.addPattern( "**/*.xml" ); fileType.addPattern( "**/*.xml" );
archivaConfiguration.getConfiguration().getArchivaRuntimeConfiguration().addChecksumType("MD5"); archivaConfiguration.getConfiguration().getArchivaRuntimeConfiguration().addChecksumType("MD5");
@ -71,14 +69,6 @@ public abstract class AbstractArtifactConsumerTest
archivaConfiguration.getConfiguration().getArchivaRuntimeConfiguration().addChecksumType("SHA256"); archivaConfiguration.getConfiguration().getArchivaRuntimeConfiguration().addChecksumType("SHA256");
repoLocation = Paths.get( "target/test-" + getName() + "/test-repo" ); repoLocation = Paths.get( "target/test-" + getName() + "/test-repo" );
repositoryRegistry = applicationContext.getBean( "repositoryRegistry", ArchivaRepositoryRegistry.class );
assertNotNull( repositoryRegistry );
}
@After
public void destroy() {
repositoryRegistry.destroy();
} }

View File

@ -42,6 +42,7 @@ import org.junit.Before;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import javax.inject.Inject; import javax.inject.Inject;
@ -109,8 +110,6 @@ public abstract class AbstractRepositoryPurgeTest
protected MetadataRepository metadataRepository; protected MetadataRepository metadataRepository;
protected ArchivaRepositoryRegistry repositoryRegistry;
@Inject @Inject
protected ApplicationContext applicationContext; protected ApplicationContext applicationContext;
@ -130,8 +129,6 @@ public abstract class AbstractRepositoryPurgeTest
repositorySession = sessionControl.createMock( RepositorySession.class ); repositorySession = sessionControl.createMock( RepositorySession.class );
metadataRepository = mock( MetadataRepository.class ); metadataRepository = mock( MetadataRepository.class );
sessionFactory = sessionFactoryControl.createMock( RepositorySessionFactory.class ); sessionFactory = sessionFactoryControl.createMock( RepositorySessionFactory.class );
repositoryRegistry = applicationContext.getBean( "repositoryRegistry", ArchivaRepositoryRegistry.class );
assertNotNull( repositoryRegistry );
EasyMock.expect( repositorySession.getRepository() ).andStubReturn( metadataRepository ); EasyMock.expect( repositorySession.getRepository() ).andStubReturn( metadataRepository );
EasyMock.expect( sessionFactory.createSession( ) ).andStubReturn( repositorySession ); EasyMock.expect( sessionFactory.createSession( ) ).andStubReturn( repositorySession );
@ -143,8 +140,6 @@ public abstract class AbstractRepositoryPurgeTest
{ {
config = null; config = null;
repo = null; repo = null;
repositoryRegistry.destroy();
} }

View File

@ -18,6 +18,8 @@ package org.apache.archiva.test.utils;
import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError; 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 org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.IOException; 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 );
}
};
}
} }

View File

@ -31,6 +31,7 @@ import org.junit.runner.RunWith;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.ZoneId; import java.time.ZoneId;
@ -41,7 +42,7 @@ import java.util.stream.Stream;
import static org.assertj.core.api.Assertions.assertThat; 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"} ) @ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml"} )
public abstract class AbstractMetadataRepositoryTest public abstract class AbstractMetadataRepositoryTest
extends TestCase extends TestCase

View File

@ -43,6 +43,7 @@ import org.junit.runner.RunWith;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.jcr.ImportUUIDBehavior; import javax.jcr.ImportUUIDBehavior;
import javax.jcr.Node; import javax.jcr.Node;
@ -62,7 +63,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
@RunWith( ArchivaSpringJUnit4ClassRunner.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 class JcrRepositoryStatisticsGatheringTest public class JcrRepositoryStatisticsGatheringTest
extends TestCase extends TestCase