Search in sources :

Example 11 with Configuration

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

the class ArchivaConfigurationTest method testGetConfigurationFixEmptyRemoteRepoUsernamePassword.

/**
 * [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
 */
@Test
public void testGetConfigurationFixEmptyRemoteRepoUsernamePassword() throws Exception {
    ArchivaConfiguration archivaConfiguration = lookup(ArchivaConfiguration.class, "test-configuration");
    Configuration configuration = archivaConfiguration.getConfiguration();
    assertConfiguration(configuration, 2, 2, 2);
    assertEquals("check remote repositories", 2, configuration.getRemoteRepositories().size());
    RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get("maven2-repository.dev.java.net");
    assertEquals("remote repository.url", "https://maven2-repository.dev.java.net/nonav/repository", repository.getUrl());
    assertEquals("remote repository.name", "Java.net Repository for Maven 2", repository.getName());
    assertEquals("remote repository.id", "maven2-repository.dev.java.net", repository.getId());
    assertEquals("remote repository.layout", "default", repository.getLayout());
    assertNull("remote repository.username == null", repository.getUsername());
    assertNull("remote repository.password == null", repository.getPassword());
}
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) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) Test(org.junit.Test)

Example 12 with Configuration

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

the class ArchivaConfigurationTest method testCronExpressionsWithComma.

@Test
public void testCronExpressionsWithComma() 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.copyFile(getTestFile("src/test/conf/escape-cron-expressions.xml").toFile(), baseFile.toFile());
    Files.createDirectories(userFile.getParent());
    FileUtils.writeStringToFile(userFile.toFile(), "<configuration/>", Charset.defaultCharset());
    final ArchivaConfiguration archivaConfiguration = lookup(ArchivaConfiguration.class, "test-cron-expressions");
    archivaConfiguration.reload();
    Configuration configuration = archivaConfiguration.getConfiguration();
    ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get(0);
    assertEquals("check cron expression", "0 0,30 * * * ?", repository.getRefreshCronExpression().trim());
    // add a test listener to confirm it doesn't see the escaped format. We don't need to test the number of calls,
    // etc. as it's done in other tests
    archivaConfiguration.addListener(new ConfigurationListener() {

        @Override
        public void configurationEvent(ConfigurationEvent event) {
            assertEquals(ConfigurationEvent.SAVED, event.getType());
        }
    });
    archivaConfiguration.save(configuration);
    configuration = archivaConfiguration.getConfiguration();
    // test for the escape character '\' showing up on repositories.jsp
    repository.setRefreshCronExpression("0 0,20 0 * * ?");
    archivaConfiguration.save(configuration);
    repository = archivaConfiguration.getConfiguration().findManagedRepositoryById("snapshots");
    assertEquals("check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression());
}
Also used : Path(java.nio.file.Path) LegacyArtifactPath(org.apache.archiva.configuration.model.LegacyArtifactPath) 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) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Test(org.junit.Test)

Example 13 with Configuration

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

the class ArchivaConfigurationTest method testStoreConfigurationUser.

@Test
public void testStoreConfigurationUser() 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(userFile.getParent());
    FileUtils.writeStringToFile(userFile.toFile(), "<configuration/>", Charset.forName("UTF-8"));
    ArchivaConfiguration archivaConfiguration = lookup(ArchivaConfiguration.class, "test-save-user");
    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(userFile));
    assertFalse("Check file not created", Files.exists(baseFile));
    // 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 14 with Configuration

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

the class ArchivaConfigurationTest method testGetConfigurationFromRegistryWithASingleNamedConfigurationResource.

@Test
public void testGetConfigurationFromRegistryWithASingleNamedConfigurationResource() throws Exception {
    ArchivaConfiguration archivaConfiguration = lookup(ArchivaConfiguration.class, "test-configuration");
    Configuration configuration = archivaConfiguration.getConfiguration();
    assertConfiguration(configuration, 2, 2, 2);
    assertEquals("check network proxies", 1, configuration.getNetworkProxies().size());
    ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get(0);
    assertEquals("check managed repositories", "${appserver.base}/repositories/internal", repository.getLocation());
    assertEquals("check managed repositories", "Archiva Managed Internal Repository", repository.getName());
    assertEquals("check managed repositories", "internal", repository.getId());
    assertEquals("check managed repositories", "default", repository.getLayout());
    assertTrue("check managed repositories", repository.isScanned());
}
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) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Test(org.junit.Test)

Example 15 with Configuration

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

the class ArchivaConfigurationTest method testStoreConfiguration.

@Test
public void testStoreConfiguration() throws Exception {
    Path file = getTestFile("target/test/test-file.xml");
    Files.deleteIfExists(file);
    assertFalse(Files.exists(file));
    // TODO: remove with commons-configuration 1.4
    // file.getParentFile().mkdirs();
    // FileUtils.writeStringToFile( file, "<configuration/>", null );
    DefaultArchivaConfiguration archivaConfiguration = (DefaultArchivaConfiguration) lookup(ArchivaConfiguration.class, "test-save");
    archivaConfiguration.reload();
    Configuration configuration = new Configuration();
    configuration.setVersion("1");
    configuration.setWebapp(new WebappConfiguration());
    configuration.getWebapp().setUi(new UserInterfaceOptions());
    configuration.getWebapp().getUi().setAppletFindEnabled(false);
    // add a change listener
    ConfigurationListener listener = mock(ConfigurationListener.class);
    archivaConfiguration.addListener(listener);
    listener.configurationEvent(new ConfigurationEvent(ConfigurationEvent.SAVED));
    archivaConfiguration.save(configuration);
    assertTrue("Check file exists", Files.exists(file));
    // check it
    configuration = archivaConfiguration.getConfiguration();
    assertFalse("check value", configuration.getWebapp().getUi().isAppletFindEnabled());
    // read it back
    archivaConfiguration = (DefaultArchivaConfiguration) lookup(ArchivaConfiguration.class, "test-read-saved");
    archivaConfiguration.reload();
    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)

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