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