diff options
author | Martin Stockhammer <martin_s@apache.org> | 2019-10-04 00:29:59 +0200 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2019-10-04 00:29:59 +0200 |
commit | ff28da65a6b9562b7a1848a244fd103ea8ff951d (patch) | |
tree | d6a6e95c99082d14935ade2e8a0697d9f5d6f2df | |
parent | 6766beb8ac281e96166ce51e1b75a4b05cee7c51 (diff) | |
download | archiva-ff28da65a6b9562b7a1848a244fd103ea8ff951d.tar.gz archiva-ff28da65a6b9562b7a1848a244fd103ea8ff951d.zip |
Implementing event manager test
-rw-r--r-- | archiva-modules/archiva-base/archiva-common/src/test/java/org/apache/archiva/event/EventManagerTest.java | 98 | ||||
-rw-r--r-- | archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/internal/DefaultIndexMerger.java (renamed from archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java) | 0 | ||||
-rw-r--r-- | archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/internal/DefaultMergedRemoteIndexesScheduler.java (renamed from archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/DefaultMergedRemoteIndexesScheduler.java) | 0 | ||||
-rw-r--r-- | archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/internal/MergedRemoteIndexesTask.java (renamed from archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/MergedRemoteIndexesTask.java) | 0 | ||||
-rw-r--r-- | archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/internal/MergedRemoteIndexesTaskRequest.java (renamed from archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/MergedRemoteIndexesTaskRequest.java) | 0 | ||||
-rw-r--r-- | archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/internal/MergedRemoteIndexesTaskResult.java (renamed from archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/MergedRemoteIndexesTaskResult.java) | 0 | ||||
-rw-r--r-- | archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/internal/TemporaryGroupIndexCleaner.java (renamed from archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/TemporaryGroupIndexCleaner.java) | 0 | ||||
-rw-r--r-- | archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/internal/ArtifactClassifierMapping.java (renamed from archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ArtifactClassifierMapping.java) | 2 | ||||
-rw-r--r-- | archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/internal/ArtifactUtil.java (renamed from archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ArtifactUtil.java) | 2 | ||||
-rw-r--r-- | archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/internal/AbstractManagedRepository.java (renamed from archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractManagedRepository.java) | 0 | ||||
-rw-r--r-- | archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/internal/AbstractRemoteRepository.java (renamed from archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRemoteRepository.java) | 0 | ||||
-rw-r--r-- | archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/internal/AbstractRepository.java (renamed from archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepository.java) | 0 | ||||
-rw-r--r-- | archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/internal/AbstractRepositoryGroup.java (renamed from archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepositoryGroup.java) | 0 | ||||
-rw-r--r-- | archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/internal/ArchivaRepositoryRegistry.java (renamed from archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/ArchivaRepositoryRegistry.java) | 0 | ||||
-rw-r--r-- | archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/internal/BasicManagedRepository.java (renamed from archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/BasicManagedRepository.java) | 0 | ||||
-rw-r--r-- | archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/internal/BasicRemoteRepository.java (renamed from archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/BasicRemoteRepository.java) | 0 | ||||
-rw-r--r-- | archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/internal/PasswordCredentials.java (renamed from archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/PasswordCredentials.java) | 0 | ||||
-rw-r--r-- | archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/internal/MetadataTools.java (renamed from archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/MetadataTools.java) | 3 | ||||
-rw-r--r-- | archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/internal/RepositoryMetadataException.java (renamed from archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/RepositoryMetadataException.java) | 2 | ||||
-rw-r--r-- | archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/internal/RepositoryMetadataMerge.java (renamed from archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/RepositoryMetadataMerge.java) | 2 | ||||
-rw-r--r-- | archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/internal/RepositoryMetadataWriter.java (renamed from archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/RepositoryMetadataWriter.java) | 2 | ||||
-rw-r--r-- | archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/RepositoryRegistryTest.java | 511 |
22 files changed, 102 insertions, 520 deletions
diff --git a/archiva-modules/archiva-base/archiva-common/src/test/java/org/apache/archiva/event/EventManagerTest.java b/archiva-modules/archiva-base/archiva-common/src/test/java/org/apache/archiva/event/EventManagerTest.java index e486c53fd..f894cb574 100644 --- a/archiva-modules/archiva-base/archiva-common/src/test/java/org/apache/archiva/event/EventManagerTest.java +++ b/archiva-modules/archiva-base/archiva-common/src/test/java/org/apache/archiva/event/EventManagerTest.java @@ -19,9 +19,12 @@ package org.apache.archiva.event; * under the License. */ -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; /** * @author Martin Stockhammer <martin_s@apache.org> @@ -29,18 +32,109 @@ import static org.junit.Assert.*; public class EventManagerTest { + private class TestHandler implements EventHandler<Event> { + + private List<Event> eventList = new ArrayList<>( ); + @Override + public void handle( Event event ) + { + eventList.add( event ); + } + + public List<Event> getEventList() { + return eventList; + } + } + + private EventType<Event> testType = new EventType<>( "TEST" ); + private EventType<Event> testTestType = new EventType<>( testType,"TEST.TEST" ); + private EventType<Event> otherType = new EventType( "OTHER" ); + @Test public void registerEventHandler( ) { + EventManager eventManager = new EventManager( this ); + TestHandler handler1 = new TestHandler( ); + TestHandler handler2 = new TestHandler( ); + TestHandler handler3 = new TestHandler( ); + TestHandler handler4 = new TestHandler( ); + + eventManager.registerEventHandler( Event.ANY, handler1 ); + eventManager.registerEventHandler( testType, handler2 ); + eventManager.registerEventHandler( testTestType, handler3 ); + eventManager.registerEventHandler( otherType, handler4 ); + + Event event1 = new Event( testType, this ); + eventManager.fireEvent( event1 ); + assertEquals( 1, handler1.eventList.size( ) ); + assertEquals( 1, handler2.eventList.size( ) ); + assertEquals( 0, handler3.eventList.size( ) ); + assertEquals( 0, handler4.eventList.size( ) ); + + Event event2 = new Event( testTestType, event1 ); + eventManager.fireEvent( event2 ); + assertEquals( 2, handler1.eventList.size( ) ); + assertEquals( 2, handler2.eventList.size( ) ); + assertEquals( 1, handler3.eventList.size( ) ); + assertEquals( 0, handler4.eventList.size( ) ); + + Event event3 = new Event( otherType, event1 ); + eventManager.fireEvent( event3 ); + assertEquals( 3, handler1.eventList.size( ) ); + assertEquals( 2, handler2.eventList.size( ) ); + assertEquals( 1, handler3.eventList.size( ) ); + assertEquals( 1, handler4.eventList.size( ) ); + + + } @Test public void unregisterEventHandler( ) { + EventManager eventManager = new EventManager( this ); + TestHandler handler1 = new TestHandler( ); + TestHandler handler2 = new TestHandler( ); + TestHandler handler3 = new TestHandler( ); + TestHandler handler4 = new TestHandler( ); + + eventManager.registerEventHandler( Event.ANY, handler1 ); + eventManager.registerEventHandler( testType, handler2 ); + eventManager.registerEventHandler( testTestType, handler3 ); + eventManager.registerEventHandler( otherType, handler4 ); + + eventManager.unregisterEventHandler( Event.ANY, handler1 ); + Event event1 = new Event( testType, this ); + eventManager.fireEvent( event1 ); + assertEquals( 0, handler1.eventList.size( ) ); + assertEquals( 1, handler2.eventList.size( ) ); + assertEquals( 0, handler3.eventList.size( ) ); + assertEquals( 0, handler4.eventList.size( ) ); + + eventManager.unregisterEventHandler( otherType, handler2 ); + Event event2 = new Event( testType, this ); + eventManager.fireEvent( event2 ); + assertEquals( 0, handler1.eventList.size( ) ); + assertEquals( 2, handler2.eventList.size( ) ); + assertEquals( 0, handler3.eventList.size( ) ); + assertEquals( 0, handler4.eventList.size( ) ); } @Test public void fireEvent( ) { + Object other = new Object( ); + EventManager eventManager = new EventManager( this ); + assertThrows( NullPointerException.class, ( ) -> eventManager.fireEvent( null ) ); + Event event = new Event( EventType.ROOT, other ); + assertEquals( other, event.getSource( ) ); + TestHandler handler = new TestHandler( ); + eventManager.registerEventHandler( EventType.ROOT, handler ); + eventManager.fireEvent( event ); + assertEquals( 1, handler.getEventList( ).size( ) ); + Event newEvent = handler.getEventList( ).get( 0 ); + assertNotEquals( event, newEvent ); + assertEquals( this, newEvent.getSource( ) ); + } }
\ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/internal/DefaultIndexMerger.java index 0264c9e35..0264c9e35 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/internal/DefaultIndexMerger.java diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/DefaultMergedRemoteIndexesScheduler.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/internal/DefaultMergedRemoteIndexesScheduler.java index 8e699007b..8e699007b 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/DefaultMergedRemoteIndexesScheduler.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/internal/DefaultMergedRemoteIndexesScheduler.java diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/MergedRemoteIndexesTask.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/internal/MergedRemoteIndexesTask.java index 42896e1f9..42896e1f9 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/MergedRemoteIndexesTask.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/internal/MergedRemoteIndexesTask.java diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/MergedRemoteIndexesTaskRequest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/internal/MergedRemoteIndexesTaskRequest.java index bc0663dbc..bc0663dbc 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/MergedRemoteIndexesTaskRequest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/internal/MergedRemoteIndexesTaskRequest.java diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/MergedRemoteIndexesTaskResult.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/internal/MergedRemoteIndexesTaskResult.java index b7def7000..b7def7000 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/MergedRemoteIndexesTaskResult.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/internal/MergedRemoteIndexesTaskResult.java diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/TemporaryGroupIndexCleaner.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/internal/TemporaryGroupIndexCleaner.java index 583ddd2c8..583ddd2c8 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/TemporaryGroupIndexCleaner.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/indexer/merger/internal/TemporaryGroupIndexCleaner.java diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ArtifactClassifierMapping.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/internal/ArtifactClassifierMapping.java index 0f3fa8271..aa924a519 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ArtifactClassifierMapping.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/internal/ArtifactClassifierMapping.java @@ -1,4 +1,4 @@ -package org.apache.archiva.repository.content; +package org.apache.archiva.repository.internal.content; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ArtifactUtil.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/internal/ArtifactUtil.java index 8bcfa97d6..e55277d34 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ArtifactUtil.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/internal/ArtifactUtil.java @@ -1,4 +1,4 @@ -package org.apache.archiva.repository.content; +package org.apache.archiva.repository.internal.content; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractManagedRepository.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/internal/AbstractManagedRepository.java index 06c328d20..06c328d20 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractManagedRepository.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/internal/AbstractManagedRepository.java diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRemoteRepository.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/internal/AbstractRemoteRepository.java index 5e58f547c..5e58f547c 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRemoteRepository.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/internal/AbstractRemoteRepository.java diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepository.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/internal/AbstractRepository.java index 0cbf261c1..0cbf261c1 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepository.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/internal/AbstractRepository.java diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepositoryGroup.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/internal/AbstractRepositoryGroup.java index 2f78b7bf5..2f78b7bf5 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepositoryGroup.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/internal/AbstractRepositoryGroup.java diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/ArchivaRepositoryRegistry.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/internal/ArchivaRepositoryRegistry.java index 9a34aede2..9a34aede2 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/ArchivaRepositoryRegistry.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/internal/ArchivaRepositoryRegistry.java diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/BasicManagedRepository.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/internal/BasicManagedRepository.java index 33f76a9f9..33f76a9f9 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/BasicManagedRepository.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/internal/BasicManagedRepository.java diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/BasicRemoteRepository.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/internal/BasicRemoteRepository.java index 0675402a0..0675402a0 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/BasicRemoteRepository.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/internal/BasicRemoteRepository.java diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/PasswordCredentials.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/internal/PasswordCredentials.java index 61f60876e..61f60876e 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/PasswordCredentials.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/internal/PasswordCredentials.java diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/MetadataTools.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/internal/MetadataTools.java index b0ec7420e..ca0333687 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/MetadataTools.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/internal/MetadataTools.java @@ -1,4 +1,4 @@ -package org.apache.archiva.repository.metadata; +package org.apache.archiva.repository.internal.metadata; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -46,7 +46,6 @@ import org.apache.archiva.xml.XMLException; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; -import org.apache.commons.lang3.time.DateUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/RepositoryMetadataException.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/internal/RepositoryMetadataException.java index 16cc89ea0..2bfcf744c 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/RepositoryMetadataException.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/internal/RepositoryMetadataException.java @@ -1,4 +1,4 @@ -package org.apache.archiva.repository.metadata; +package org.apache.archiva.repository.internal.metadata; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/RepositoryMetadataMerge.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/internal/RepositoryMetadataMerge.java index c29d64aa2..dc389b13f 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/RepositoryMetadataMerge.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/internal/RepositoryMetadataMerge.java @@ -1,4 +1,4 @@ -package org.apache.archiva.repository.metadata; +package org.apache.archiva.repository.internal.metadata; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/RepositoryMetadataWriter.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/internal/RepositoryMetadataWriter.java index 0b5573676..bbe8a805f 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/RepositoryMetadataWriter.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/internal/RepositoryMetadataWriter.java @@ -1,4 +1,4 @@ -package org.apache.archiva.repository.metadata; +package org.apache.archiva.repository.internal.metadata; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/RepositoryRegistryTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/RepositoryRegistryTest.java deleted file mode 100644 index 53825aa2e..000000000 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/RepositoryRegistryTest.java +++ /dev/null @@ -1,511 +0,0 @@ -package org.apache.archiva.repository; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.configuration.ArchivaConfiguration; -import org.apache.archiva.configuration.Configuration; -import org.apache.archiva.configuration.ManagedRepositoryConfiguration; -import org.apache.archiva.configuration.RemoteRepositoryConfiguration; -import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.test.context.ContextConfiguration; - -import javax.inject.Inject; -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; -import java.util.Collection; - -import static org.junit.Assert.*; - -/** - * Test for RepositoryRegistry - */ -@RunWith(ArchivaSpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" }) -public class RepositoryRegistryTest -{ - - @Inject - RepositoryRegistry repositoryRegistry; - - @Inject - ArchivaConfiguration archivaConfiguration; - - private static final Path userCfg = Paths.get(System.getProperty( "user.home" ), ".m2/archiva.xml"); - - private static Path cfgCopy; - private static Path archivaCfg; - - @BeforeClass - public static void classSetup() throws IOException, URISyntaxException - { - URL archivaCfgUri = Thread.currentThread().getContextClassLoader().getResource( "archiva.xml" ); - if (archivaCfgUri!=null) { - archivaCfg = Paths.get(archivaCfgUri.toURI()); - cfgCopy = Files.createTempFile( "archiva-backup", ".xml" ); - Files.copy( archivaCfg, cfgCopy, StandardCopyOption.REPLACE_EXISTING); - } - } - - @AfterClass - public static void classTearDown() throws IOException - { - if (cfgCopy!=null) { - Files.deleteIfExists( cfgCopy ); - } - } - - @Before - public void setUp( ) throws Exception - { - assertNotNull( repositoryRegistry ); - Files.deleteIfExists( userCfg ); - URL archivaCfgUri = Thread.currentThread().getContextClassLoader().getResource( "archiva.xml" ); - if (archivaCfgUri!=null) { - archivaCfg = Paths.get(archivaCfgUri.toURI()); - if (Files.exists(cfgCopy)) - { - Files.copy( cfgCopy, archivaCfg , StandardCopyOption.REPLACE_EXISTING); - } - } - archivaConfiguration.reload(); - repositoryRegistry.reload(); - } - - @After - public void tearDown( ) throws Exception - { - Files.deleteIfExists( userCfg ); - if (cfgCopy!=null && Files.exists(cfgCopy)) { - Files.copy(cfgCopy, archivaCfg, StandardCopyOption.REPLACE_EXISTING); - } - } - - @Test - public void getRepositories( ) throws Exception - { - Collection<Repository> repos = repositoryRegistry.getRepositories( ); - assertEquals( 5, repos.size( ) ); - assertTrue(repos.stream().anyMatch( rep -> rep.getId().equals("internal") )); - assertTrue( repos.stream( ).anyMatch( rep -> rep.getId( ).equals( "snapshots") ) ); - assertTrue(repos.stream().anyMatch( rep -> rep.getId().equals( "central") )); - } - - @Test - public void getManagedRepositories( ) throws Exception - { - Collection<ManagedRepository> repos = repositoryRegistry.getManagedRepositories(); - assertEquals( 4, repos.size( ) ); - assertTrue(repos.stream().anyMatch( rep -> rep.getId().equals("internal") )); - assertTrue( repos.stream( ).anyMatch( rep -> rep.getId( ).equals( "snapshots") ) ); - } - - @Test - public void getRemoteRepositories( ) throws Exception - { - Collection<RemoteRepository> repos = repositoryRegistry.getRemoteRepositories( ); - assertEquals( 1, repos.size( ) ); - assertTrue(repos.stream().anyMatch( rep -> rep.getId().equals( "central") )); - } - - @Test - public void getRepository( ) throws Exception - { - Repository repo = repositoryRegistry.getRepository( "internal" ); - assertNotNull(repo); - assertEquals("internal", repo.getId()); - assertEquals("Archiva Managed Internal Repository", repo.getName()); - assertEquals("This is internal repository.", repo.getDescription()); - assertEquals( "default", repo.getLayout( ) ); - assertEquals("0 0 * * * ?", repo.getSchedulingDefinition()); - assertTrue(repo instanceof ManagedRepository); - assertTrue( repo.hasIndex( ) ); - assertTrue(repo.isScanned()); - assertEquals(RepositoryType.MAVEN, repo.getType()); - } - - @Test - public void getManagedRepository( ) throws Exception - { - ManagedRepository repo = repositoryRegistry.getManagedRepository( "internal" ); - assertNotNull(repo); - assertEquals("internal", repo.getId()); - assertEquals("Archiva Managed Internal Repository", repo.getName()); - assertEquals("This is internal repository.", repo.getDescription()); - assertEquals( "default", repo.getLayout( ) ); - assertEquals("0 0 * * * ?", repo.getSchedulingDefinition()); - assertTrue( repo.hasIndex( ) ); - assertTrue(repo.isScanned()); - assertEquals(RepositoryType.MAVEN, repo.getType()); - assertTrue(repo.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE)); - assertFalse( repo.getActiveReleaseSchemes( ).contains( ReleaseScheme.SNAPSHOT ) ); - assertNotNull(repo.getContent()); - - assertNull(repositoryRegistry.getManagedRepository( "xyu" )); - - } - - @Test - public void getRemoteRepository( ) throws Exception - { - RemoteRepository repo = repositoryRegistry.getRemoteRepository( "central" ); - assertNotNull(repo); - assertEquals("central", repo.getId()); - assertEquals("Central Repository", repo.getName()); - assertEquals("", repo.getDescription()); - assertEquals( "default", repo.getLayout( ) ); - assertEquals("0 0 08 ? * SUN", repo.getSchedulingDefinition()); - assertTrue( repo.hasIndex( ) ); - assertTrue(repo.isScanned()); - assertEquals(RepositoryType.MAVEN, repo.getType()); - - assertEquals(35, repo.getTimeout().getSeconds()); - } - - @Test - public void putManagedRepository( ) throws Exception - { - BasicManagedRepository managedRepository = BasicManagedRepository.newFilesystemInstance("test001", "Test repo", archivaConfiguration.getRepositoryBaseDir().resolve("test001")); - managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" ); - repositoryRegistry.putRepository(managedRepository); - - assertNotNull(managedRepository.getContent()); - assertEquals(6, repositoryRegistry.getRepositories().size()); - - managedRepository = BasicManagedRepository.newFilesystemInstance("central", "Test repo", archivaConfiguration.getRepositoryBaseDir().resolve("central")); - managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" ); - ManagedRepository updatedRepo = null; - try { - repositoryRegistry.putRepository( managedRepository ); - throw new RuntimeException("Repository exception should be thrown, if there exists a remote repository already with that id"); - } catch (RepositoryException e) { - // OK - } - managedRepository = BasicManagedRepository.newFilesystemInstance("internal", "Test repo", archivaConfiguration.getRepositoryBaseDir().resolve("internal")); - managedRepository.setDescription( managedRepository.getPrimaryLocale(), "This is just a test" ); - updatedRepo = repositoryRegistry.putRepository( managedRepository ); - - assertTrue(updatedRepo==managedRepository); - assertNotNull(managedRepository.getContent()); - assertEquals(6, repositoryRegistry.getRepositories().size()); - ManagedRepository managedRepository1 = repositoryRegistry.getManagedRepository( "internal" ); - assertEquals("Test repo", managedRepository1.getName()); - assertTrue(managedRepository1==managedRepository); - - } - - @Test - public void putManagedRepositoryFromConfig( ) throws Exception - { - ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration(); - cfg.setId("test002"); - cfg.setName("This is test 002"); - ManagedRepository repo = repositoryRegistry.putRepository( cfg ); - assertNotNull(repo); - assertEquals("test002", repo.getId()); - assertEquals("This is test 002", repo.getName()); - assertNotNull(repo.getContent()); - archivaConfiguration.reload(); - Collection<ManagedRepository> repos = repositoryRegistry.getManagedRepositories(); - assertEquals(5, repos.size()); - - ManagedRepository internalRepo = repositoryRegistry.getManagedRepository( "internal" ); - cfg = new ManagedRepositoryConfiguration(); - cfg.setId("internal"); - cfg.setName("This is internal test 002"); - repo = repositoryRegistry.putRepository( cfg ); - assertTrue(internalRepo==repo); - assertEquals("This is internal test 002",repo.getName()); - assertEquals(5, repositoryRegistry.getManagedRepositories().size()); - - repositoryRegistry.reload(); - assertEquals(5, repositoryRegistry.getManagedRepositories().size()); - - } - - @Test - public void putManagedRepositoryFromConfigWithoutSave( ) throws Exception - { - Configuration configuration = archivaConfiguration.getConfiguration(); - ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration(); - cfg.setId("test002"); - cfg.setName("This is test 002"); - ManagedRepository repo = repositoryRegistry.putRepository( cfg, configuration ); - assertNotNull(repo); - assertEquals("test002", repo.getId()); - assertEquals("This is test 002", repo.getName()); - assertNotNull(repo.getContent()); - archivaConfiguration.reload(); - assertEquals(3, archivaConfiguration.getConfiguration().getManagedRepositories().size()); - Collection<ManagedRepository> repos = repositoryRegistry.getManagedRepositories(); - assertEquals(5, repos.size()); - - ManagedRepository internalRepo = repositoryRegistry.getManagedRepository( "internal" ); - cfg = new ManagedRepositoryConfiguration(); - cfg.setId("internal"); - cfg.setName("This is internal test 002"); - repo = repositoryRegistry.putRepository( cfg, configuration ); - assertTrue(internalRepo==repo); - assertEquals("This is internal test 002",repo.getName()); - assertEquals(5, repositoryRegistry.getManagedRepositories().size()); - - repositoryRegistry.reload(); - assertEquals(4, repositoryRegistry.getManagedRepositories().size()); - } - - @Test - public void putRemoteRepository( ) throws Exception - { - BasicRemoteRepository remoteRepository = BasicRemoteRepository.newFilesystemInstance( "test001", "Test repo", archivaConfiguration.getRemoteRepositoryBaseDir() ); - remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" ); - RemoteRepository newRepo = repositoryRegistry.putRepository(remoteRepository); - - assertTrue(remoteRepository==newRepo); - assertNotNull(remoteRepository.getContent()); - assertEquals(6, repositoryRegistry.getRepositories().size()); - - remoteRepository = BasicRemoteRepository.newFilesystemInstance( "internal", "Test repo", archivaConfiguration.getRemoteRepositoryBaseDir() ); - remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" ); - RemoteRepository updatedRepo = null; - try - { - updatedRepo = repositoryRegistry.putRepository( remoteRepository ); - throw new RuntimeException("Should throw repository exception, if repository exists already and is not the same type."); - } catch (RepositoryException e) { - // OK - } - - remoteRepository = BasicRemoteRepository.newFilesystemInstance( "central", "Test repo", archivaConfiguration.getRemoteRepositoryBaseDir() ); - remoteRepository.setDescription( remoteRepository.getPrimaryLocale(), "This is just a test" ); - updatedRepo = repositoryRegistry.putRepository( remoteRepository ); - - assertTrue(updatedRepo==remoteRepository); - assertNotNull(remoteRepository.getContent()); - assertEquals(6, repositoryRegistry.getRepositories().size()); - RemoteRepository remoteRepository1 = repositoryRegistry.getRemoteRepository( "central" ); - assertEquals("Test repo", remoteRepository1.getName()); - assertTrue(remoteRepository1==remoteRepository); - } - - @Test - public void putRemoteRepositoryFromConfig( ) throws Exception - { - RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration(); - cfg.setId("test002"); - cfg.setName("This is test 002"); - RemoteRepository repo = repositoryRegistry.putRepository( cfg ); - assertNotNull(repo); - assertEquals("test002", repo.getId()); - assertEquals("This is test 002", repo.getName()); - assertNotNull(repo.getContent()); - archivaConfiguration.reload(); - Collection<RemoteRepository> repos = repositoryRegistry.getRemoteRepositories(); - assertEquals(2, repos.size()); - - RemoteRepository internalRepo = repositoryRegistry.getRemoteRepository( "central" ); - cfg = new RemoteRepositoryConfiguration(); - cfg.setId("central"); - cfg.setName("This is central test 002"); - repo = repositoryRegistry.putRepository( cfg ); - assertTrue(internalRepo==repo); - assertEquals("This is central test 002",repo.getName()); - assertEquals(2, repositoryRegistry.getRemoteRepositories().size()); - - repositoryRegistry.reload(); - assertEquals(2, repositoryRegistry.getRemoteRepositories().size()); - } - - @Test - public void putRemoteRepositoryFromConfigWithoutSave( ) throws Exception - { - Configuration configuration = archivaConfiguration.getConfiguration(); - RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration(); - cfg.setId("test002"); - cfg.setName("This is test 002"); - RemoteRepository repo = repositoryRegistry.putRepository( cfg, configuration ); - assertNotNull(repo); - assertEquals("test002", repo.getId()); - assertEquals("This is test 002", repo.getName()); - assertNotNull(repo.getContent()); - archivaConfiguration.reload(); - assertEquals(1, archivaConfiguration.getConfiguration().getRemoteRepositories().size()); - Collection<RemoteRepository> repos = repositoryRegistry.getRemoteRepositories(); - assertEquals(2, repos.size()); - - RemoteRepository internalRepo = repositoryRegistry.getRemoteRepository( "central" ); - cfg = new RemoteRepositoryConfiguration(); - cfg.setId("central"); - cfg.setName("This is central test 002"); - repo = repositoryRegistry.putRepository( cfg, configuration ); - assertTrue(internalRepo==repo); - assertEquals("This is central test 002",repo.getName()); - assertEquals(2, repositoryRegistry.getRemoteRepositories().size()); - - repositoryRegistry.reload(); - assertEquals(1, repositoryRegistry.getRemoteRepositories().size()); - } - - @Test - public void removeRepository( ) throws Exception - { - assertEquals(5, repositoryRegistry.getRepositories().size()); - Repository repo = repositoryRegistry.getRepository( "snapshots" ); - repositoryRegistry.removeRepository( repo ); - assertEquals(4, repositoryRegistry.getRepositories().size()); - assertTrue( repositoryRegistry.getRepositories( ).stream( ).noneMatch( rep -> rep.getId( ).equals( "snapshots" ) ) ); - archivaConfiguration.reload(); - repositoryRegistry.reload(); - assertEquals(4, repositoryRegistry.getRepositories().size()); - } - - @Test - public void removeManagedRepository( ) throws Exception - { - - assertEquals(4, repositoryRegistry.getManagedRepositories().size()); - ManagedRepository repo = repositoryRegistry.getManagedRepository( "snapshots" ); - repositoryRegistry.removeRepository( repo ); - assertEquals(3, repositoryRegistry.getManagedRepositories().size()); - assertTrue( repositoryRegistry.getManagedRepositories( ).stream( ).noneMatch( rep -> rep.getId( ).equals( "snapshots" ) ) ); - archivaConfiguration.reload(); - repositoryRegistry.reload(); - assertEquals(3, repositoryRegistry.getManagedRepositories().size()); - } - - @Test - public void removeManagedRepositoryWithoutSave( ) throws Exception - { - Configuration configuration = archivaConfiguration.getConfiguration(); - assertEquals(4, repositoryRegistry.getManagedRepositories().size()); - ManagedRepository repo = repositoryRegistry.getManagedRepository( "snapshots" ); - repositoryRegistry.removeRepository( repo, configuration ); - assertEquals(3, repositoryRegistry.getManagedRepositories().size()); - assertTrue( repositoryRegistry.getManagedRepositories( ).stream( ).noneMatch( rep -> rep.getId( ).equals( "snapshots" ) ) ); - archivaConfiguration.reload(); - repositoryRegistry.reload(); - assertEquals(4, repositoryRegistry.getManagedRepositories().size()); - } - - - @Test - public void removeRemoteRepository( ) throws Exception - { - assertEquals(1, repositoryRegistry.getRemoteRepositories().size()); - RemoteRepository repo = repositoryRegistry.getRemoteRepository( "central" ); - repositoryRegistry.removeRepository( repo ); - assertEquals(0, repositoryRegistry.getRemoteRepositories().size()); - assertTrue( repositoryRegistry.getRemoteRepositories( ).stream( ).noneMatch( rep -> rep.getId( ).equals( "central" ) ) ); - archivaConfiguration.reload(); - repositoryRegistry.reload(); - assertEquals(0, repositoryRegistry.getRemoteRepositories().size()); - } - - @Test - public void removeRemoteRepositoryWithoutSave( ) throws Exception - { - Configuration configuration = archivaConfiguration.getConfiguration(); - assertEquals(1, repositoryRegistry.getRemoteRepositories().size()); - RemoteRepository repo = repositoryRegistry.getRemoteRepository( "central" ); - repositoryRegistry.removeRepository( repo, configuration ); - assertEquals(0, repositoryRegistry.getRemoteRepositories().size()); - assertTrue( repositoryRegistry.getRemoteRepositories( ).stream( ).noneMatch( rep -> rep.getId( ).equals( "central" ) ) ); - archivaConfiguration.reload(); - repositoryRegistry.reload(); - assertEquals(1, repositoryRegistry.getRemoteRepositories().size()); - } - - - @Test - public void cloneManagedRepo( ) throws Exception - { - ManagedRepository managedRepository = repositoryRegistry.getManagedRepository( "internal" ); - - try - { - repositoryRegistry.clone(managedRepository, "snapshots"); - throw new RuntimeException("RepositoryRegistry exception should be thrown if id exists already."); - } - catch ( RepositoryException e ) - { - // OK - } - - try - { - repositoryRegistry.clone(managedRepository, "central"); - throw new RuntimeException("RepositoryRegistry exception should be thrown if id exists already."); - } - catch ( RepositoryException e ) - { - // OK - } - - ManagedRepository clone = repositoryRegistry.clone( managedRepository, "newinternal" ); - assertNotNull(clone); - assertNull(clone.getContent()); - assertEquals("Archiva Managed Internal Repository", clone.getName()); - assertFalse(managedRepository==clone); - - } - - @Test - public void cloneRemoteRepo( ) throws Exception - { - RemoteRepository remoteRepository = repositoryRegistry.getRemoteRepository( "central" ); - - try - { - repositoryRegistry.clone(remoteRepository, "snapshots"); - throw new RuntimeException("RepositoryRegistry exception should be thrown if id exists already."); - } - catch ( RepositoryException e ) - { - // OK - } - - try - { - repositoryRegistry.clone(remoteRepository, "central"); - throw new RuntimeException("RepositoryRegistry exception should be thrown if id exists already."); - } - catch ( RepositoryException e ) - { - // OK - } - - RemoteRepository clone = repositoryRegistry.clone( remoteRepository, "newCentral" ); - assertNotNull(clone); - assertNull(clone.getContent()); - assertEquals("Central Repository", clone.getName()); - assertFalse(remoteRepository==clone); - - } - -}
\ No newline at end of file |