Search in sources :

Example 41 with DependencyMaterialConfig

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

Example 42 with DependencyMaterialConfig

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

Example 43 with DependencyMaterialConfig

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())));
}
Also used : DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) ExpectedException(org.junit.rules.ExpectedException) Test(org.junit.Test)

Example 44 with DependencyMaterialConfig

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

Example 45 with DependencyMaterialConfig

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));
}
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