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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations