mirror of
https://github.com/apache/archiva.git
synced 2025-03-06 16:39:13 +00:00
Implementing event manager test
This commit is contained in:
parent
6766beb8ac
commit
ff28da65a6
@ -19,9 +19,12 @@
|
||||
* 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 @@
|
||||
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( ) );
|
||||
|
||||
}
|
||||
}
|
@ -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
|
@ -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
|
@ -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.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;
|
@ -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
|
@ -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
|
@ -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
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user