Search in sources :

Example 1 with DependencyMaterialConfig

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);
    }
}
Also used : DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)

Example 2 with DependencyMaterialConfig

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]"));
}
Also used : HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Test(org.junit.Test)

Example 3 with DependencyMaterialConfig

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'"));
}
Also used : DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors) Test(org.junit.Test)

Example 4 with DependencyMaterialConfig

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));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Test(org.junit.Test)

Example 5 with DependencyMaterialConfig

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()));
}
Also used : DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Test(org.junit.Test)

Aggregations

DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)135 Test (org.junit.Test)106 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)22 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)22 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)21 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)15 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)14 PipelineConfigDependencyGraph (com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph)11 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)10 Date (java.util.Date)10 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)9 PluggableSCMMaterialConfig (com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig)8 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)8 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)8 Pipeline (com.thoughtworks.go.domain.Pipeline)8 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)8 ScmMaterialConfig (com.thoughtworks.go.config.materials.ScmMaterialConfig)7 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)7 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)7 ModificationsMother.changedDependencyMaterialRevision (com.thoughtworks.go.helper.ModificationsMother.changedDependencyMaterialRevision)7