use of com.thoughtworks.go.config.materials.PackageMaterialConfig in project gocd by gocd.
the class PackageMaterialUpdateWithExistingPackageDefinitionCommandTest method shouldUpdateMaterialWithExistingPackageDefinition.
@Test
public void shouldUpdateMaterialWithExistingPackageDefinition() {
PackageDefinition packageDefinition = cruiseConfig.getPackageRepositories().get(0).getPackages().get(1);
String repoId = packageDefinition.getRepository().getId();
String pkgId = packageDefinition.getId();
HashMap<String, Serializable> params = PackageDefinitionMother.paramsForPackageMaterialAssociation(repoId, pkgId);
PackageMaterialUpdateWithExistingPackageDefinitionCommand command = new PackageMaterialUpdateWithExistingPackageDefinitionCommand(packageDefinitionService, securityService, pipelineName, materialToBeUpdated, admin, params);
command.update(cruiseConfig);
assertThat(pipelineConfig.materialConfigs().first() instanceof PackageMaterialConfig, is(true));
PackageMaterialConfig editedMaterial = (PackageMaterialConfig) pipelineConfig.materialConfigs().first();
assertThat(editedMaterial, is(materialToBeUpdated));
assertThat(editedMaterial.getPackageDefinition(), is(packageDefinition));
verify(packageDefinitionService, never()).performPluginValidationsFor(packageDefinition);
}
use of com.thoughtworks.go.config.materials.PackageMaterialConfig in project gocd by gocd.
the class PackageMaterialUpdateWithNewPackageDefinitionCommandTest method shouldHandleDeletedPackageRepo.
@Test
public void shouldHandleDeletedPackageRepo() {
String repoId = "deleted-repo";
String pkgName = "pkg-2";
HashMap<String, Serializable> params = PackageDefinitionMother.paramsForPackageMaterialCreation(repoId, pkgName);
PackageMaterialUpdateWithNewPackageDefinitionCommand command = new PackageMaterialUpdateWithNewPackageDefinitionCommand(packageDefinitionService, securityService, pipelineName, materialToBeUpdated, admin, params);
command.update(cruiseConfig);
assertThat(pipelineConfig.materialConfigs().first() instanceof PackageMaterialConfig, is(true));
PackageMaterialConfig editedMaterial = (PackageMaterialConfig) pipelineConfig.materialConfigs().first();
assertThat(editedMaterial, is(materialToBeUpdated));
assertThat(editedMaterial.getPackageDefinition(), is(notNullValue()));
assertThat(editedMaterial.getPackageDefinition().getId(), is(nullValue()));
assertThat(editedMaterial.getPackageDefinition().getRepository(), is(nullValue()));
assertThat(editedMaterial.getPackageDefinition().getName(), is(pkgName));
assertThat(editedMaterial.getPackageDefinition().getConfiguration().size(), is(0));
verify(packageDefinitionService, never()).performPluginValidationsFor(editedMaterial.getPackageDefinition());
}
use of com.thoughtworks.go.config.materials.PackageMaterialConfig in project gocd by gocd.
the class PipelineGroups method getPackageUsageInPipelines.
public Map<String, List<Pair<PipelineConfig, PipelineConfigs>>> getPackageUsageInPipelines() {
if (packageToPipelineMap == null) {
synchronized (this) {
if (packageToPipelineMap == null) {
packageToPipelineMap = new HashMap<>();
for (PipelineConfigs pipelineConfigs : this) {
for (PipelineConfig pipelineConfig : pipelineConfigs) {
for (PackageMaterialConfig packageMaterialConfig : pipelineConfig.packageMaterialConfigs()) {
String packageId = packageMaterialConfig.getPackageId();
if (!packageToPipelineMap.containsKey(packageId)) {
packageToPipelineMap.put(packageId, new ArrayList<>());
}
packageToPipelineMap.get(packageId).add(new Pair<>(pipelineConfig, pipelineConfigs));
}
}
}
}
}
}
return packageToPipelineMap;
}
use of com.thoughtworks.go.config.materials.PackageMaterialConfig in project gocd by gocd.
the class MagicalGoConfigXmlWriterTest method shouldAllowPackageTypeMaterialForPipeline.
@Test
public void shouldAllowPackageTypeMaterialForPipeline() throws Exception {
CruiseConfig configToSave = new BasicCruiseConfig();
PackageRepository packageRepository = new PackageRepository();
packageRepository.setId("id");
packageRepository.setName("name");
packageRepository.setPluginConfiguration(new PluginConfiguration("plugin-id", "version"));
packageRepository.setConfiguration(new Configuration(getConfigurationProperty("url", false, "http://go")));
String packageId = "id";
PackageDefinition expectedPackageDefinition = new PackageDefinition(packageId, "name", new Configuration(getConfigurationProperty("name", false, "go-agent")));
expectedPackageDefinition.setRepository(packageRepository);
packageRepository.getPackages().add(expectedPackageDefinition);
configToSave.getPackageRepositories().add(packageRepository);
PackageMaterialConfig packageMaterialConfig = new PackageMaterialConfig(packageId);
packageMaterialConfig.setPackageDefinition(expectedPackageDefinition);
configToSave.addPipeline("default", com.thoughtworks.go.helper.PipelineConfigMother.pipelineConfig("test", new MaterialConfigs(packageMaterialConfig), new JobConfigs(new JobConfig("ls"))));
xmlWriter.write(configToSave, output, false);
GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(output.toString());
PipelineConfig pipelineConfig = goConfigHolder.config.pipelineConfigByName(new CaseInsensitiveString("test"));
assertThat(pipelineConfig.materialConfigs().get(0) instanceof PackageMaterialConfig, is(true));
assertThat(((PackageMaterialConfig) pipelineConfig.materialConfigs().get(0)).getPackageId(), is(packageId));
PackageDefinition packageDefinition = goConfigHolder.config.getPackageRepositories().first().getPackages().first();
assertThat(((PackageMaterialConfig) pipelineConfig.materialConfigs().get(0)).getPackageDefinition(), is(packageDefinition));
}
use of com.thoughtworks.go.config.materials.PackageMaterialConfig in project gocd by gocd.
the class MagicalGoConfigXmlWriterTest method shouldFailValidationIfPackageTypeMaterialForPipelineHasARefToNonExistantPackage.
@Test
public void shouldFailValidationIfPackageTypeMaterialForPipelineHasARefToNonExistantPackage() throws Exception {
CruiseConfig configToSave = new BasicCruiseConfig();
String packageId = "does-not-exist";
PackageMaterialConfig packageMaterialConfig = new PackageMaterialConfig(packageId);
PackageRepository repository = com.thoughtworks.go.domain.packagerepository.PackageRepositoryMother.create("repo-id", "repo-name", "pluginid", "version", new Configuration(com.thoughtworks.go.domain.packagerepository.ConfigurationPropertyMother.create("k1", false, "v1")));
packageMaterialConfig.setPackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinitionMother.create("does-not-exist", "package-name", new Configuration(com.thoughtworks.go.domain.packagerepository.ConfigurationPropertyMother.create("k2", false, "v2")), repository));
configToSave.addPipeline("default", com.thoughtworks.go.helper.PipelineConfigMother.pipelineConfig("test", new MaterialConfigs(packageMaterialConfig), new JobConfigs(new JobConfig("ls"))));
try {
xmlWriter.write(configToSave, output, false);
fail("should not allow this");
} catch (XsdValidationException exception) {
assertThat(exception.getMessage(), is("Key 'packageIdReferredByMaterial' with value 'does-not-exist' not found for identity constraint of element 'cruise'."));
}
}
Aggregations