use of com.thoughtworks.go.domain.packagerepository.PackageRepositories in project gocd by gocd.
the class UpdatePackageConfigCommandTest method shouldValidateDuplicateIdentity.
@Test
public void shouldValidateDuplicateIdentity() throws Exception {
PackageRepository repository = cruiseConfig.getPackageRepositories().find("repoId");
PackageDefinition pkg = new PackageDefinition("Id", "name", configuration);
pkg.setRepository(repository);
repository.addPackage(pkg);
cruiseConfig.setPackageRepositories(new PackageRepositories(repository));
UpdatePackageConfigCommand command = new UpdatePackageConfigCommand(goConfigService, packageUuid, newPackageDefinition, currentUser, "md5", this.entityHashingService, result, packageDefinitionService);
command.update(cruiseConfig);
assertFalse(command.isValid(cruiseConfig));
assertThat(newPackageDefinition.errors().size(), is(1));
assertThat(newPackageDefinition.errors().firstError(), is("Cannot save package or repo, found duplicate packages. [Repo Name: 'repoName', Package Name: 'name'], [Repo Name: 'repoName', Package Name: 'prettyjson']"));
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepositories in project gocd by gocd.
the class PackageMaterialAddWithNewPackageDefinitionCommandTest method shouldPerformValidationsBeforeDeleteEmptyConfigurationsHappensDuringAddingPackageIntoConfig.
@Test
public void shouldPerformValidationsBeforeDeleteEmptyConfigurationsHappensDuringAddingPackageIntoConfig() throws Exception {
String repoId = "repoId";
HashMap repositoryIdMap = new HashMap();
repositoryIdMap.put("repositoryId", repoId);
Map params = new HashMap();
params.put("package_definition", repositoryIdMap);
CruiseConfig config = mock(BasicCruiseConfig.class);
PackageRepositories packageRepositories = mock(PackageRepositories.class);
when(packageRepositories.find(repoId)).thenReturn(mock(PackageRepository.class));
when(config.getPackageRepositories()).thenReturn(packageRepositories);
PackageMaterialAddWithNewPackageDefinitionCommand command = spy(new PackageMaterialAddWithNewPackageDefinitionCommand(packageDefinitionService, securityService, pipelineName, new PackageMaterialConfig(), admin, params));
command.createNewPackageDefinition(config);
InOrder inOrder = inOrder(command, config);
inOrder.verify(config).savePackageDefinition(any(PackageDefinition.class));
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepositories in project gocd by gocd.
the class GoConfigMigrationIntegrationTest method shouldValidatePackageRepositoriesConfiguration.
@Test
public void shouldValidatePackageRepositoriesConfiguration() throws Exception {
String configString = "<cruise schemaVersion='66'>" + "<repositories>" + "<repository id='go-repo' name='go-repo'>" + " <pluginConfiguration id='plugin-id' version='1.0'/>" + " <configuration>" + " <property><key>url</key><value>http://fake-yum-repo</value></property>" + " <property><key>username</key><value>godev</value></property>" + " <property><key>password</key><value>password</value></property>" + " </configuration>" + " <packages>" + " <package id='go-server' name='go-server'>" + " <configuration>" + " <property><key>name</key><value>go-server-13.2.0-1-i386</value></property>" + " </configuration>" + " </package>" + " </packages>" + "</repository>" + "</repositories>" + "</cruise>";
CruiseConfig cruiseConfig = migrateConfigAndLoadTheNewConfig(configString, 66);
PackageRepositories packageRepositories = cruiseConfig.getPackageRepositories();
assertThat(packageRepositories.size(), is(1));
assertThat(packageRepositories.get(0).getId(), is("go-repo"));
assertThat(packageRepositories.get(0).getName(), is("go-repo"));
assertThat(packageRepositories.get(0).getPluginConfiguration().getId(), is("plugin-id"));
assertThat(packageRepositories.get(0).getPluginConfiguration().getVersion(), is("1.0"));
assertThat(packageRepositories.get(0).getConfiguration(), is(notNullValue()));
assertThat(packageRepositories.get(0).getPackages().size(), is(1));
assertConfiguration(packageRepositories.get(0).getConfiguration(), asList(new List[] { asList("url", Boolean.FALSE, "http://fake-yum-repo"), asList("username", Boolean.FALSE, "godev"), asList("password", Boolean.FALSE, "password") }));
assertThat(packageRepositories.get(0).getPackages().get(0).getId(), is("go-server"));
assertThat(packageRepositories.get(0).getPackages().get(0).getName(), is("go-server"));
assertConfiguration(packageRepositories.get(0).getPackages().get(0).getConfiguration(), asList(new List[] { asList("name", Boolean.FALSE, "go-server-13.2.0-1-i386") }));
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepositories in project gocd by gocd.
the class GoConfigMigrationIntegrationTest method shouldAllowOnlyRepositoryConfiguration.
@Test
public void shouldAllowOnlyRepositoryConfiguration() throws Exception {
String configString = "<cruise schemaVersion='66'>" + "<repositories>" + "<repository id='go-repo' name='go-repo'>" + " <pluginConfiguration id='plugin-id' version='1.0'/>" + " <configuration>" + " <property><key>url</key><value>http://fake-yum-repo</value></property>" + " <property><key>username</key><value>godev</value></property>" + " <property><key>password</key><value>password</value></property>" + " </configuration>" + "</repository>" + "</repositories>" + "</cruise>";
CruiseConfig cruiseConfig = loadConfigFileWithContent(configString);
PackageRepositories packageRepositories = cruiseConfig.getPackageRepositories();
assertThat(packageRepositories.size(), is(1));
assertThat(packageRepositories.get(0).getId(), is("go-repo"));
assertThat(packageRepositories.get(0).getName(), is("go-repo"));
assertThat(packageRepositories.get(0).getPluginConfiguration().getId(), is("plugin-id"));
assertThat(packageRepositories.get(0).getPluginConfiguration().getVersion(), is("1.0"));
assertThat(packageRepositories.get(0).getConfiguration(), is(notNullValue()));
assertThat(packageRepositories.get(0).getPackages().size(), is(0));
assertConfiguration(packageRepositories.get(0).getConfiguration(), asList(new List[] { asList("url", Boolean.FALSE, "http://fake-yum-repo"), asList("username", Boolean.FALSE, "godev"), asList("password", Boolean.FALSE, "password") }));
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepositories in project gocd by gocd.
the class UpdatePackageConfigCommand method update.
@Override
public void update(CruiseConfig modifiedConfig) {
PackageRepositories packageRepositories = modifiedConfig.getPackageRepositories();
PackageRepository repository = packageRepositories.findPackageRepositoryHaving(oldPackageId);
int index = packageRepositories.indexOf(repository);
newPackage.setRepository(repository);
repository.removePackage(oldPackageId);
repository.addPackage(this.newPackage);
packageRepositories.replace(index, repository);
modifiedConfig.setPackageRepositories(packageRepositories);
updatePackageConfigurationOnAssociatedPipelines(modifiedConfig);
}
Aggregations