use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.
the class FetchTask method validatePathFromAncestor.
private void validatePathFromAncestor(PipelineConfig currentPipeline, ValidationContext validationContext) {
List<CaseInsensitiveString> parentPipelineNames = pipelineName.pathIncludingAncestor();
PipelineConfig pipeline = currentPipeline;
CaseInsensitiveString dependencyStage = null;
for (CaseInsensitiveString parentPipelineName : parentPipelineNames) {
if (validationContext.getPipelineConfigByName(parentPipelineName) == null) {
addError(FetchTask.PIPELINE_NAME, String.format("Pipeline named '%s' which is declared ancestor of '%s' through path '%s' does not exist.", parentPipelineName, currentPipeline.name(), pipelineName.getPath()));
return;
}
DependencyMaterialConfig matchingDependencyMaterial = findMatchingDependencyMaterial(pipeline, parentPipelineName);
if (matchingDependencyMaterial != null) {
dependencyStage = matchingDependencyMaterial.getStageName();
pipeline = validationContext.getPipelineConfigByName(matchingDependencyMaterial.getPipelineName());
} else {
addError(FetchTask.PIPELINE_NAME, String.format("Pipeline named '%s' exists, but is not an ancestor of '%s' as declared in '%s'.", parentPipelineName, currentPipeline.name(), pipelineName.getPath()));
return;
}
}
boolean foundStageAtOrBeforeDependency = dependencyStage.equals(stage);
if (!foundStageAtOrBeforeDependency) {
for (StageConfig stageConfig : pipeline.allStagesBefore(dependencyStage)) {
foundStageAtOrBeforeDependency = stage.equals(stageConfig.name());
if (foundStageAtOrBeforeDependency) {
break;
}
}
}
if (!foundStageAtOrBeforeDependency) {
addStageMayNotCompleteBeforeDownstreamError(currentPipeline, validationContext);
}
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.
the class DependencyMaterialConfigTest method setConfigAttributes_shouldPopulateFromConfigAttributes.
@Test
public void setConfigAttributes_shouldPopulateFromConfigAttributes() {
DependencyMaterialConfig dependencyMaterialConfig = new DependencyMaterialConfig(new CaseInsensitiveString(""), new CaseInsensitiveString(""));
assertThat(dependencyMaterialConfig.getPipelineStageName(), is(nullValue()));
HashMap<String, String> configMap = new HashMap<>();
configMap.put(AbstractMaterialConfig.MATERIAL_NAME, "name1");
configMap.put(DependencyMaterialConfig.PIPELINE_STAGE_NAME, "pipeline-1 [stage-1]");
dependencyMaterialConfig.setConfigAttributes(configMap);
assertThat(dependencyMaterialConfig.getMaterialName(), is(new CaseInsensitiveString("name1")));
assertThat(dependencyMaterialConfig.getPipelineName(), is(new CaseInsensitiveString("pipeline-1")));
assertThat(dependencyMaterialConfig.getStageName(), is(new CaseInsensitiveString("stage-1")));
assertThat(dependencyMaterialConfig.getPipelineStageName(), is("pipeline-1 [stage-1]"));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.
the class DependencyMaterialConfigTest method shouldNOTBeValidIfThePipelineExistsButTheStageDoesNot.
@Test
public void shouldNOTBeValidIfThePipelineExistsButTheStageDoesNot() throws Exception {
DependencyMaterialConfig dependencyMaterialConfig = new DependencyMaterialConfig(new CaseInsensitiveString("pipeline2"), new CaseInsensitiveString("stage-not-existing does not exist!"));
dependencyMaterialConfig.validate(ConfigSaveValidationContext.forChain(config, pipelineConfig));
ConfigErrors configErrors = dependencyMaterialConfig.errors();
assertThat(configErrors.isEmpty(), is(false));
assertThat(configErrors.on(DependencyMaterialConfig.PIPELINE_STAGE_NAME), containsString("Stage with name 'stage-not-existing does not exist!' does not exist on pipeline 'pipeline2'"));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.
the class DependencyMaterialConfigTest method shouldBeAbleToLoadADependencyMaterialFromConfig.
@Test
public void shouldBeAbleToLoadADependencyMaterialFromConfig() throws Exception {
String xml = "<pipeline pipelineName=\"pipeline-name\" stageName=\"stage-name\" />";
DependencyMaterialConfig material = loader.fromXmlPartial(xml, DependencyMaterialConfig.class);
assertThat(material.getPipelineName(), is(new CaseInsensitiveString("pipeline-name")));
assertThat(material.getStageName(), is(new CaseInsensitiveString("stage-name")));
assertThat(writer.toXmlPartial(material), is(xml));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.
the class DependencyMaterialConfigTest method shouldNotBombValidationWhenMaterialNameIsNotSet.
@Test
public void shouldNotBombValidationWhenMaterialNameIsNotSet() {
DependencyMaterialConfig dependencyMaterialConfig = new DependencyMaterialConfig(new CaseInsensitiveString("pipeline-foo"), new CaseInsensitiveString("stage-bar"));
dependencyMaterialConfig.validate(ConfigSaveValidationContext.forChain(new BasicCruiseConfig(), pipelineConfig));
assertThat(dependencyMaterialConfig.errors().on(AbstractMaterialConfig.MATERIAL_NAME), is(nullValue()));
}
Aggregations