Search in sources :

Example 36 with Configuration

use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.

the class RemoteRepositoryHandlerTest method removeWithoutSave.

@Test
void removeWithoutSave() throws RepositoryException {
    final String id = "test-repo-09";
    RemoteRepositoryHandler repoHandler = createHandler();
    Configuration aCfg = new Configuration();
    RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration();
    configuration.setId(id);
    configuration.setName("n-" + id);
    repoHandler.put(configuration, aCfg);
    assertTrue(aCfg.getRemoteRepositories().stream().anyMatch(g -> g != null && id.equals(g.getId())));
    repoHandler.remove(id, aCfg);
    assertNull(repoHandler.get(id));
    assertTrue(aCfg.getRemoteRepositories().stream().noneMatch(g -> g != null && id.equals(g.getId())));
    assertNull(repoHandler.get(id));
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) CheckedResult(org.apache.archiva.repository.validation.CheckedResult) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) ArchivaRepositoryRegistry(org.apache.archiva.repository.base.ArchivaRepositoryRegistry) Inject(javax.inject.Inject) Repository(org.apache.archiva.repository.Repository) RepositoryContentFactory(org.apache.archiva.repository.RepositoryContentFactory) RemoteRepository(org.apache.archiva.repository.RemoteRepository) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ISEMPTY(org.apache.archiva.repository.validation.ErrorKeys.ISEMPTY) IndexManagerFactory(org.apache.archiva.indexer.IndexManagerFactory) Map(java.util.Map) FileUtils(org.apache.archiva.common.utils.FileUtils) Named(javax.inject.Named) ConfigurationHandler(org.apache.archiva.repository.base.ConfigurationHandler) ValidationError(org.apache.archiva.repository.validation.ValidationError) Path(java.nio.file.Path) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryValidator(org.apache.archiva.repository.validation.RepositoryValidator) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository) Iterator(java.util.Iterator) SpringExtension(org.springframework.test.context.junit.jupiter.SpringExtension) Files(java.nio.file.Files) FileLockManager(org.apache.archiva.common.filelock.FileLockManager) RepositoryException(org.apache.archiva.repository.RepositoryException) IOException(java.io.IOException) RepositoryType(org.apache.archiva.repository.RepositoryType) Test(org.junit.jupiter.api.Test) List(java.util.List) Paths(java.nio.file.Paths) ContextConfiguration(org.springframework.test.context.ContextConfiguration) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) Assertions(org.junit.jupiter.api.Assertions) RepositoryState(org.apache.archiva.repository.RepositoryState) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) Test(org.junit.jupiter.api.Test)

Example 37 with Configuration

use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.

the class RemoteRepositoryHandlerTest method newInstancesFromConfig.

@Test
void newInstancesFromConfig() throws RepositoryException {
    final String id = "test-repo-01";
    RemoteRepositoryHandler repoHandler = createHandler();
    Configuration configuration = new Configuration();
    repoHandler.remove("test-repo-01", configuration);
    Map<String, RemoteRepository> instances = repoHandler.newInstancesFromConfig();
    assertFalse(repoHandler.hasRepository(id));
    assertTrue(instances.containsKey(id));
    assertEquals(RepositoryState.REFERENCES_SET, instances.get(id).getLastState());
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) RemoteRepository(org.apache.archiva.repository.RemoteRepository) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository) Test(org.junit.jupiter.api.Test)

Example 38 with Configuration

use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.

the class ArchivaRepositoryRegistryTest method removeManagedRepositoryWithoutSave.

@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());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) StandardCopyOption(java.nio.file.StandardCopyOption) AfterAll(org.junit.jupiter.api.AfterAll) Inject(javax.inject.Inject) ReleaseScheme(org.apache.archiva.repository.ReleaseScheme) Repository(org.apache.archiva.repository.Repository) RemoteRepository(org.apache.archiva.repository.RemoteRepository) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ManagedRepositoryHandler(org.apache.archiva.repository.base.managed.ManagedRepositoryHandler) BeforeAll(org.junit.jupiter.api.BeforeAll) Path(java.nio.file.Path) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) SpringExtension(org.springframework.test.context.junit.jupiter.SpringExtension) Files(java.nio.file.Files) RepositoryException(org.apache.archiva.repository.RepositoryException) RemoteRepositoryHandler(org.apache.archiva.repository.base.remote.RemoteRepositoryHandler) Collection(java.util.Collection) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) IOException(java.io.IOException) RepositoryType(org.apache.archiva.repository.RepositoryType) ManagedRepository(org.apache.archiva.repository.ManagedRepository) BasicRemoteRepository(org.apache.archiva.repository.base.remote.BasicRemoteRepository) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) Paths(java.nio.file.Paths) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Assertions(org.junit.jupiter.api.Assertions) RepositoryGroupHandler(org.apache.archiva.repository.base.group.RepositoryGroupHandler) BasicManagedRepository(org.apache.archiva.repository.base.managed.BasicManagedRepository) ManagedRepository(org.apache.archiva.repository.ManagedRepository) BasicManagedRepository(org.apache.archiva.repository.base.managed.BasicManagedRepository) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Test(org.junit.jupiter.api.Test)

Example 39 with Configuration

use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.

the class ArchivaConfigurationTest method testStoreConfigurationFallback.

@Test
public void testStoreConfigurationFallback() throws Exception {
    Path baseFile = getTestFile("target/test/test-file.xml");
    Files.deleteIfExists(baseFile);
    assertFalse(Files.exists(baseFile));
    Path userFile = getTestFile("target/test/test-file-user.xml");
    Files.deleteIfExists(userFile);
    assertFalse(Files.exists(userFile));
    Files.createDirectories(baseFile.getParent());
    FileUtils.writeStringToFile(baseFile.toFile(), "<configuration/>", Charset.forName("UTF-8"));
    ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup(ArchivaConfiguration.class, "test-save-user-fallback");
    archivaConfiguration.reload();
    Configuration configuration = new Configuration();
    configuration.setWebapp(new WebappConfiguration());
    configuration.getWebapp().setUi(new UserInterfaceOptions());
    configuration.getWebapp().getUi().setAppletFindEnabled(false);
    archivaConfiguration.save(configuration);
    assertTrue("Check file exists", Files.exists(baseFile));
    assertFalse("Check file not created", Files.exists(userFile));
    // check it
    configuration = archivaConfiguration.getConfiguration();
    assertFalse("check value", configuration.getWebapp().getUi().isAppletFindEnabled());
}
Also used : Path(java.nio.file.Path) LegacyArtifactPath(org.apache.archiva.configuration.model.LegacyArtifactPath) WebappConfiguration(org.apache.archiva.configuration.model.WebappConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) WebappConfiguration(org.apache.archiva.configuration.model.WebappConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) UserInterfaceOptions(org.apache.archiva.configuration.model.UserInterfaceOptions) Test(org.junit.Test)

Example 40 with Configuration

use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.

the class ArchivaConfigurationTest method testLoadConfigurationFromInvalidBothLocationsOnDisk.

@Test
public void testLoadConfigurationFromInvalidBothLocationsOnDisk() throws Exception {
    String propFile = System.getProperty(ArchivaConfiguration.USER_CONFIG_PROPERTY);
    System.setProperty(ArchivaConfiguration.USER_CONFIG_PROPERTY, "/../../..//*intentionally:invalid*/.m2/archiva-user.xml");
    ArchivaConfiguration archivaConfiguration = lookup(ArchivaConfiguration.class, "test-not-allowed-to-write-to-both");
    Configuration config = archivaConfiguration.getConfiguration();
    try {
        archivaConfiguration.save(config);
        fail("Should have thrown a RegistryException because the configuration can't be saved.");
    } catch (RegistryException e) {
    /* expected exception */
    }
    if (propFile != null) {
        System.setProperty(ArchivaConfiguration.USER_CONFIG_PROPERTY, propFile);
    }
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) WebappConfiguration(org.apache.archiva.configuration.model.WebappConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) RegistryException(org.apache.archiva.components.registry.RegistryException) Test(org.junit.Test)

Aggregations

Configuration (org.apache.archiva.configuration.model.Configuration)94 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)56 ContextConfiguration (org.springframework.test.context.ContextConfiguration)45 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)42 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)34 ArchivaConfiguration (org.apache.archiva.configuration.provider.ArchivaConfiguration)34 WebappConfiguration (org.apache.archiva.configuration.model.WebappConfiguration)32 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)29 Path (java.nio.file.Path)27 Test (org.junit.Test)26 NetworkProxyConfiguration (org.apache.archiva.configuration.model.NetworkProxyConfiguration)23 RepositoryScanningConfiguration (org.apache.archiva.configuration.model.RepositoryScanningConfiguration)23 RepositoryException (org.apache.archiva.repository.RepositoryException)22 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)14 ManagedRepository (org.apache.archiva.repository.ManagedRepository)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)12 RemoteRepository (org.apache.archiva.repository.RemoteRepository)12 Test (org.junit.jupiter.api.Test)12 LegacyArtifactPath (org.apache.archiva.configuration.model.LegacyArtifactPath)11