use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.
the class PipelineConfigServiceIntegrationTest method shouldNotDeletePipelineConfigWhenItHasDownstreamDependencies.
@Test
public void shouldNotDeletePipelineConfigWhenItHasDownstreamDependencies() throws Exception {
PipelineConfig dependency = GoConfigMother.createPipelineConfigWithMaterialConfig(new DependencyMaterialConfig(pipelineConfig.name(), pipelineConfig.first().name()));
goConfigService.addPipeline(dependency, groupName);
int pipelineCountBefore = goConfigService.getAllPipelineConfigs().size();
assertTrue(goConfigService.hasPipelineNamed(pipelineConfig.name()));
pipelineConfigService.deletePipelineConfig(user, pipelineConfig, result);
assertFalse(result.isSuccessful());
assertThat(result.toString(), result.toString().contains("CANNOT_DELETE_PIPELINE_USED_AS_MATERIALS"), is(true));
assertThat(result.httpCode(), is(422));
int pipelineCountAfter = goConfigService.getAllPipelineConfigs().size();
assertThat(pipelineCountAfter, is(pipelineCountBefore));
assertTrue(goConfigService.hasPipelineNamed(pipelineConfig.name()));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.
the class PipelineConfigServiceIntegrationTest method shouldNotCreatePipelineConfigWhenInvalidGroupNameIsPassed.
@Test
public void shouldNotCreatePipelineConfigWhenInvalidGroupNameIsPassed() throws GitAPIException {
GoConfigHolder goConfigHolderBeforeUpdate = goConfigDao.loadConfigHolder();
PipelineConfig pipelineBeingCreated = GoConfigMother.createPipelineConfigWithMaterialConfig(pipelineConfig.name().toLower(), new DependencyMaterialConfig(pipelineConfig.name(), pipelineConfig.first().name()));
pipelineConfigService.createPipelineConfig(user, pipelineBeingCreated, result, "%$-with-invalid-characters");
assertThat(result.toString(), result.isSuccessful(), is(false));
assertThat(result.httpCode(), is(422));
assertFalse(pipelineBeingCreated.errors().isEmpty());
assertThat(pipelineBeingCreated.errors().on(PipelineConfigs.GROUP), contains("Invalid group name '%$-with-invalid-characters'"));
assertThat(goConfigDao.loadConfigHolder(), is(goConfigHolderBeforeUpdate));
assertThat(configRepository.getCurrentRevCommit().name(), is(headCommitBeforeUpdate));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.
the class PipelineConfigServiceIntegrationTest method shouldShowThePipelineConfigErrorMessageWhenPipelineBeingCreatedFromTemplateHasErrors.
@Test
public void shouldShowThePipelineConfigErrorMessageWhenPipelineBeingCreatedFromTemplateHasErrors() throws GitAPIException {
JobConfigs jobConfigs = new JobConfigs();
jobConfigs.add(new JobConfig(new CaseInsensitiveString("Job")));
StageConfig stage = new StageConfig(new CaseInsensitiveString("Stage-1"), jobConfigs);
final PipelineTemplateConfig templateConfig = new PipelineTemplateConfig(new CaseInsensitiveString("foo"), stage);
goConfigDao.updateConfig(new UpdateConfigCommand() {
@Override
public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
cruiseConfig.addTemplate(templateConfig);
return cruiseConfig;
}
});
PipelineConfig pipeline = GoConfigMother.createPipelineConfigWithMaterialConfig();
pipeline.templatize(templateConfig.name());
DependencyMaterialConfig material = new DependencyMaterialConfig(new CaseInsensitiveString("Invalid-pipeline"), new CaseInsensitiveString("Stage"));
pipeline.addMaterialConfig(material);
pipelineConfigService.createPipelineConfig(user, pipeline, result, groupName);
assertThat(result.toString(), result.isSuccessful(), is(false));
assertThat(result.httpCode(), is(422));
assertThat(material.errors().firstError(), is(String.format("Pipeline with name 'Invalid-pipeline' does not exist, it is defined as a dependency for pipeline 'pipeline' (cruise-config.xml)", pipeline.name())));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.
the class PipelineConfigServiceIntegrationTest method shouldUpdatePipelineConfigWithDependencyMaterialWhenUpstreamPipelineHasTemplateDefinedANDUpstreamPipelineIsCreatedUsingCreatePipelineFlow.
@Test
public void shouldUpdatePipelineConfigWithDependencyMaterialWhenUpstreamPipelineHasTemplateDefinedANDUpstreamPipelineIsCreatedUsingCreatePipelineFlow() throws Exception {
CaseInsensitiveString templateName = new CaseInsensitiveString("template_with_param");
saveTemplateWithParamToConfig(templateName);
MaterialConfigs materialConfigs = new MaterialConfigs();
materialConfigs.add(new DependencyMaterialConfig(pipelineConfig.name(), new CaseInsensitiveString("stage")));
PipelineConfig upstream = new PipelineConfig(new CaseInsensitiveString("upstream"), materialConfigs);
upstream.setTemplateName(templateName);
upstream.addParam(new ParamConfig("SOME_PARAM", "SOME_VALUE"));
pipelineConfigService.createPipelineConfig(user, upstream, result, groupName);
PipelineConfig downstream = GoConfigMother.createPipelineConfigWithMaterialConfig("downstream", new DependencyMaterialConfig(upstream.name(), new CaseInsensitiveString("stage")));
pipelineConfigService.createPipelineConfig(user, downstream, result, groupName);
assertThat(result.toString(), result.isSuccessful(), is(true));
assertTrue(downstream.materialConfigs().first().errors().isEmpty());
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.
the class PipelineConfigServiceIntegrationTest method shouldNotSaveWhenKnownPartialsListIsTheSameAsValidPartialsAndPipelineValidationFailsForConfigChanges.
@Test
public void shouldNotSaveWhenKnownPartialsListIsTheSameAsValidPartialsAndPipelineValidationFailsForConfigChanges() throws Exception {
PipelineConfig remoteDownstreamPipeline = partialConfig.getGroups().first().getPipelines().get(0);
assertThat(goConfigService.getCurrentConfig().getAllPipelineNames().contains(remoteDownstreamPipeline.name()), is(true));
assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1)).isEmpty(), is(true));
assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).isEmpty(), is(true));
DependencyMaterialConfig dependencyMaterialForRemotePipelineInConfigCache = goConfigService.getCurrentConfig().getPipelineConfigByName(remoteDownstreamPipeline.name()).materialConfigs().findDependencyMaterial(pipelineConfig.name());
assertThat(dependencyMaterialForRemotePipelineInConfigCache.getStageName(), is(new CaseInsensitiveString("stage")));
String xml = new MagicalGoConfigXmlWriter(configCache, registry).toXmlPartial(pipelineConfig);
String md5 = CachedDigestUtils.md5Hex(xml);
pipelineConfig.getFirstStageConfig().setName(new CaseInsensitiveString("new_name"));
pipelineConfigService.updatePipelineConfig(user, pipelineConfig, md5, result);
assertThat(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())));
CruiseConfig currentConfig = goConfigService.getCurrentConfig();
assertThat(currentConfig.getAllPipelineNames().contains(remoteDownstreamPipeline.name()), is(true));
assertThat(cachedGoPartials.lastValidPartials().contains(partialConfig), is(true));
assertThat(cachedGoPartials.lastKnownPartials().contains(partialConfig), is(true));
assertThat(cachedGoPartials.lastKnownPartials().equals(cachedGoPartials.lastValidPartials()), is(true));
assertThat(currentConfig.getPipelineConfigByName(remoteDownstreamPipeline.name()).materialConfigs().findDependencyMaterial(pipelineConfig.name()).getStageName(), is(new CaseInsensitiveString("stage")));
assertThat(currentConfig.getPipelineConfigByName(pipelineConfig.name()).getFirstStageConfig().name(), is(new CaseInsensitiveString("stage")));
assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1)).isEmpty(), is(true));
assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).isEmpty(), is(true));
}
Aggregations