use of com.thoughtworks.go.config.materials.PackageMaterialConfig in project gocd by gocd.
the class GoConfigMaterialsTest method getPackageMaterialConfigWithAutoUpdateTrue.
private PackageMaterialConfig getPackageMaterialConfigWithAutoUpdateTrue() {
PackageDefinition packageDefinition = new PackageDefinition("packageWithAutoUpdateFalse", "DTDC Package", new Configuration());
packageDefinition.setRepository(PackageRepositoryMother.create("DTDC"));
packageDefinition.setAutoUpdate(true);
return new PackageMaterialConfig(new CaseInsensitiveString("Krish"), "packageWithAutoUpdateTrue", packageDefinition);
}
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'."));
}
}
use of com.thoughtworks.go.config.materials.PackageMaterialConfig in project gocd by gocd.
the class PipelineConfigServiceIntegrationTest method shouldMapErrorsBackToPackageMaterials.
@Test
public void shouldMapErrorsBackToPackageMaterials() throws Exception {
GoConfigHolder goConfigHolder = goConfigDao.loadConfigHolder();
String packageid = "packageid";
saveScmMaterialToConfig(packageid);
PackageMaterialConfig packageMaterialConfig = new PackageMaterialConfig(packageid);
String xml = new MagicalGoConfigXmlWriter(configCache, registry).toXmlPartial(pipelineConfig);
String md5 = CachedDigestUtils.md5Hex(xml);
pipelineConfig.materialConfigs().add(packageMaterialConfig);
pipelineConfigService.updatePipelineConfig(user, pipelineConfig, md5, result);
assertThat(result.toString(), result.isSuccessful(), is(false));
assertThat(result.message(localizer), is(String.format("Validations failed for pipeline '%s'. Error(s): [Validation failed.]. Please correct and resubmit.", pipelineConfig.name())));
assertThat(packageMaterialConfig.errors().on(PackageMaterialConfig.PACKAGE_ID), is("Could not find repository for given package id:[packageid]"));
assertThat(configRepository.getCurrentRevCommit().name(), is(headCommitBeforeUpdate));
assertThat(goConfigDao.loadConfigHolder().configForEdit, is(goConfigHolder.configForEdit));
assertThat(goConfigDao.loadConfigHolder().config, is(goConfigHolder.config));
}
use of com.thoughtworks.go.config.materials.PackageMaterialConfig in project gocd by gocd.
the class PackageMaterialUpdateWithExistingPackageDefinitionCommandTest method shouldHandleDeletedPackageRepo.
@Test
public void shouldHandleDeletedPackageRepo() {
String repoId = "deleted-repo";
String pkgId = "pkg-2";
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(nullValue()));
assertThat(editedMaterial.getPackageId(), is(nullValue()));
verify(packageDefinitionService, never()).performPluginValidationsFor(Matchers.<PackageDefinition>any());
}
Aggregations