Search in sources :

Example 91 with MaterialConfigs

use of com.thoughtworks.go.config.materials.MaterialConfigs in project gocd by gocd.

the class PipelineConfigValidationTest method shouldValidateTree.

@Test
public void shouldValidateTree() {
    PipelineConfig pipeline = new PipelineConfig();
    pipeline.setName("pipeline");
    pipeline.addEnvironmentVariable("", "");
    pipeline.addParam(new ParamConfig("", ""));
    pipeline.setMaterialConfigs(new MaterialConfigs(MaterialConfigsMother.gitMaterialConfig(), MaterialConfigsMother.svnMaterialConfig()));
    StageConfig stage1 = getStageConfig("stage1", "s1j1");
    StageConfig stage2 = getStageConfig("stage2", "s2j1");
    pipeline.getStages().add(stage1);
    pipeline.getStages().add(stage2);
    BasicCruiseConfig cruiseConfig = new BasicCruiseConfig(new BasicPipelineConfigs("group", new Authorization(), pipeline));
    boolean isValid = pipeline.validateTree(PipelineConfigSaveValidationContext.forChain(true, cruiseConfig.getGroups().first().getGroup(), cruiseConfig, pipeline));
    assertThat(isValid, is(false));
    assertThat(pipeline.getVariables().get(0).errors().firstError(), is("Environment Variable cannot have an empty name for pipeline 'pipeline'."));
    assertThat(pipeline.getParams().get(0).errors().firstError(), is("Parameter cannot have an empty name for pipeline 'pipeline'."));
    assertThat(pipeline.materialConfigs().errors().isEmpty(), is(true));
    assertThat(pipeline.materialConfigs().get(0).errors().isEmpty(), is(true));
    assertThat(pipeline.materialConfigs().get(1).errors().isEmpty(), is(true));
    assertThat(pipeline.errors().getAll().isEmpty(), is(true));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) Test(org.junit.Test)

Example 92 with MaterialConfigs

use of com.thoughtworks.go.config.materials.MaterialConfigs in project gocd by gocd.

the class PipelineConfigValidationTest method shouldValidateAPipelineHasAtleastOneStage.

@Test
public void shouldValidateAPipelineHasAtleastOneStage() {
    PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("p"), new MaterialConfigs());
    pipelineConfig.validateTree(PipelineConfigSaveValidationContext.forChain(true, "group", new BasicCruiseConfig(new BasicPipelineConfigs("group", new Authorization())), pipelineConfig));
    assertThat(pipelineConfig.errors().on("pipeline"), is("Pipeline 'p' does not have any stages configured. A pipeline must have at least one stage."));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) Test(org.junit.Test)

Example 93 with MaterialConfigs

use of com.thoughtworks.go.config.materials.MaterialConfigs in project gocd by gocd.

the class PipelineConfigValidationTest method shouldFailValidationIfAStageIsDeletedWhileItsStillReferredToByADownstreamPipeline.

@Test
public void shouldFailValidationIfAStageIsDeletedWhileItsStillReferredToByADownstreamPipeline() {
    BasicCruiseConfig cruiseConfig = GoConfigMother.configWithPipelines("p1", "p2");
    PipelineConfig p1 = cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString("p1"));
    PipelineConfig p2 = cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString("p2"));
    p2.addMaterialConfig(new DependencyMaterialConfig(p1.name(), p1.first().name()));
    String group = cruiseConfig.getGroups().first().getGroup();
    StageConfig stageConfig = new StageConfig(new CaseInsensitiveString("s1"), new JobConfigs(new JobConfig(new CaseInsensitiveString("j1"))));
    PipelineConfig pipelineConfig = new PipelineConfig(p1.name(), new MaterialConfigs(), stageConfig);
    cruiseConfig.update(group, pipelineConfig.name().toString(), pipelineConfig);
    PipelineConfigSaveValidationContext validationContext = PipelineConfigSaveValidationContext.forChain(false, group, cruiseConfig, pipelineConfig);
    pipelineConfig.validateTree(validationContext);
    assertThat(pipelineConfig.errors().on("base"), is("Stage with name 'stage' does not exist on pipeline 'p1', it is being referred to from pipeline 'p2' (cruise-config.xml)"));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Test(org.junit.Test)

Example 94 with MaterialConfigs

use of com.thoughtworks.go.config.materials.MaterialConfigs in project gocd by gocd.

the class PipelineConfigValidationTest method validate_shouldEnsureThatTemplateFollowsTheNameType.

@Test
public void validate_shouldEnsureThatTemplateFollowsTheNameType() {
    PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("name"), new MaterialConfigs());
    pipelineConfig.setTemplateName(new CaseInsensitiveString(".Name"));
    config.addPipeline("group", pipelineConfig);
    pipelineConfig.validateTemplate(new PipelineTemplateConfig());
    assertThat(pipelineConfig.errors().isEmpty(), is(false));
    assertThat(pipelineConfig.errors().on(PipelineConfig.TEMPLATE_NAME), is("Invalid template name '.Name'. This must be alphanumeric and can contain underscores and periods (however, it cannot start with a period). The maximum allowed length is 255 characters."));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) Test(org.junit.Test)

Example 95 with MaterialConfigs

use of com.thoughtworks.go.config.materials.MaterialConfigs in project gocd by gocd.

the class PipelineConfigValidationTest method shouldAddValidationErrorsFromStagesOntoPipelineIfPipelineIsAssociatedToATemplate.

@Test
public void shouldAddValidationErrorsFromStagesOntoPipelineIfPipelineIsAssociatedToATemplate() {
    BasicCruiseConfig cruiseConfig = GoConfigMother.configWithPipelines("p1", "p2", "p3");
    PipelineConfig p1 = cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString("p1"));
    PipelineConfig p2 = cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString("p2"));
    PipelineConfig p3 = cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString("p3"));
    p2.addMaterialConfig(new DependencyMaterialConfig(p1.name(), p1.first().name()));
    p3.addMaterialConfig(new DependencyMaterialConfig(p2.name(), p2.first().name()));
    p3.first().getJobs().first().addTask(new FetchTask(new CaseInsensitiveString("p1/p2"), p1.first().name(), p1.first().getJobs().first().name(), "src", "dest"));
    StageConfig stageConfig = new StageConfig(new CaseInsensitiveString("stage"), new JobConfigs(new JobConfig(new CaseInsensitiveString("new-job"))));
    PipelineConfig pipelineConfig = new PipelineConfig(p1.name(), new MaterialConfigs(), stageConfig);
    String group = cruiseConfig.getGroups().first().getGroup();
    cruiseConfig.update(group, pipelineConfig.name().toString(), pipelineConfig);
    PipelineConfigSaveValidationContext validationContext = PipelineConfigSaveValidationContext.forChain(false, group, cruiseConfig, pipelineConfig);
    pipelineConfig.validateTree(validationContext);
    assertThat(pipelineConfig.errors().on("base"), is("\"p3 :: stage :: job\" tries to fetch artifact from job \"p1 :: stage :: job\" which does not exist."));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Test(org.junit.Test)

Aggregations

MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)218 Test (org.junit.Test)158 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)35 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)33 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)32 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)32 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)27 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)25 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)25 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)25 TimeProvider (com.thoughtworks.go.util.TimeProvider)25 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)21 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)19 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)19 ValueStreamMapPresentationModel (com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel)16 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)15 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)14 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)14 Material (com.thoughtworks.go.domain.materials.Material)14 Materials (com.thoughtworks.go.config.materials.Materials)12