aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2021-07-11 20:18:26 +0200
committerMartin Stockhammer <martin_s@apache.org>2021-07-11 20:18:26 +0200
commit33ab453a5cc4f91345f3c05f972cd521b19922cb (patch)
tree377ae9a4dd266f7810cdb81ee68a6cdba9c30dfc
parent51f6e48839a54873d120d6ccd97f2cf391314005 (diff)
downloadarchiva-33ab453a5cc4f91345f3c05f972cd521b19922cb.tar.gz
archiva-33ab453a5cc4f91345f3c05f972cd521b19922cb.zip
Adding additional tests
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/pom.xml11
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/group/RepositoryGroupHandlerTest.java54
2 files changed, 49 insertions, 16 deletions
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/pom.xml b/archiva-modules/archiva-base/archiva-repository-layer/pom.xml
index 877487935..c68e4bce6 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/pom.xml
+++ b/archiva-modules/archiva-base/archiva-repository-layer/pom.xml
@@ -116,6 +116,17 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-junit-jupiter</artifactId>
+ <version>${mockito.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<scope>test</scope>
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/group/RepositoryGroupHandlerTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/group/RepositoryGroupHandlerTest.java
index 07992dad3..696cdf6a6 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/group/RepositoryGroupHandlerTest.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/group/RepositoryGroupHandlerTest.java
@@ -21,12 +21,18 @@ package org.apache.archiva.repository.base.group;
import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.indexer.merger.MergedRemoteIndexesScheduler;
import org.apache.archiva.repository.Repository;
+import org.apache.archiva.repository.RepositoryException;
+import org.apache.archiva.repository.RepositoryGroup;
import org.apache.archiva.repository.RepositoryRegistry;
+import org.apache.archiva.repository.RepositoryState;
+import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
import org.apache.archiva.repository.base.ConfigurationHandler;
import org.apache.archiva.repository.validation.RepositoryValidator;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@@ -34,26 +40,30 @@ import javax.inject.Inject;
import javax.inject.Named;
import java.util.List;
+import java.util.Map;
import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.verify;
/**
* @author Martin Stockhammer <martin_s@apache.org>
*/
-@ExtendWith( SpringExtension.class)
-@ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-group.xml" })
+@ExtendWith( {MockitoExtension.class, SpringExtension.class} )
+@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-group.xml"} )
class RepositoryGroupHandlerTest
{
@Inject
- @Named("repositoryRegistry")
+ @Named( "repositoryRegistry" )
ArchivaRepositoryRegistry repositoryRegistry;
@Inject
ConfigurationHandler configurationHandler;
- @Inject
- @Named( "mergedRemoteIndexesScheduler#default" )
+ @Mock
+ // @Named( "mergedRemoteIndexesScheduler#default" )
MergedRemoteIndexesScheduler mergedRemoteIndexesScheduler;
@Inject
@@ -63,9 +73,10 @@ class RepositoryGroupHandlerTest
ArchivaConfiguration archivaConfiguration;
- private RepositoryGroupHandler createHandler() {
+ private RepositoryGroupHandler createHandler( )
+ {
RepositoryGroupHandler groupHandler = new RepositoryGroupHandler( repositoryRegistry, configurationHandler, mergedRemoteIndexesScheduler, repositoryValidatorList );
- groupHandler.init();
+ groupHandler.init( );
return groupHandler;
}
@@ -73,32 +84,43 @@ class RepositoryGroupHandlerTest
void initializeFromConfig( )
{
RepositoryGroupHandler groupHandler = createHandler( );
- assertNotNull( groupHandler );
- groupHandler.initializeFromConfig();
+ groupHandler.initializeFromConfig( );
assertEquals( 1, groupHandler.getAll( ).size( ) );
assertNotNull( groupHandler.get( "test-group-01" ).getRepositories( ) );
- assertEquals( "internal", groupHandler.get( "test-group-01" ).getRepositories( ).get( 0 ).getId() );
+ assertEquals( "internal", groupHandler.get( "test-group-01" ).getRepositories( ).get( 0 ).getId( ) );
}
@Test
- void activateRepository( )
+ void activateRepository( ) throws RepositoryException
{
+ RepositoryGroupHandler groupHandler = createHandler( );
+ RepositoryGroup repo = groupHandler.newInstance( RepositoryType.MAVEN, "test-group-02" );
+ groupHandler.activateRepository( repo );
+ verify( mergedRemoteIndexesScheduler ).schedule( eq( repo ), any( ) );
+ assertEquals( RepositoryState.INITIALIZED, repo.getLastState( ) );
}
@Test
void newInstancesFromConfig( )
{
+ RepositoryGroupHandler groupHandler = new RepositoryGroupHandler( repositoryRegistry, configurationHandler, mergedRemoteIndexesScheduler, repositoryValidatorList );
+ Map<String, RepositoryGroup> instances = groupHandler.newInstancesFromConfig( );
+ assertFalse( groupHandler.hasRepository( "test-group-01" ) );
+ assertTrue( instances.containsKey( "test-group-01" ) );
+ assertEquals( RepositoryState.REFERENCES_SET, instances.get( "test-group-01" ).getLastState( ) );
}
@Test
- void newInstance( )
+ void newInstance( ) throws RepositoryException
{
+ RepositoryGroupHandler groupHandler = createHandler( );
+ RepositoryGroup instance = groupHandler.newInstance( RepositoryType.MAVEN, "test-group-03" );
+ assertNotNull( instance );
+ assertEquals( "test-group-03", instance.getId( ) );
+ assertFalse( groupHandler.hasRepository( "test-group-03" ) );
+ assertEquals( RepositoryState.REFERENCES_SET, instance.getLastState( ) );
}
- @Test
- void testNewInstance( )
- {
- }
@Test
void put( )