Search in sources :

Example 6 with Cloner

use of com.rits.cloning.Cloner in project gocd by gocd.

the class BuildAssignmentServiceIntegrationTest method shouldCancelBuildsForDeletedStagesWhenPipelineConfigChanges.

@Test
public void shouldCancelBuildsForDeletedStagesWhenPipelineConfigChanges() throws Exception {
    buildAssignmentService.initialize();
    fixture.createPipelineWithFirstStageScheduled();
    buildAssignmentService.onTimer();
    PipelineConfig pipelineConfig = new Cloner().deepClone(configHelper.getCachedGoConfig().currentConfig().getPipelineConfigByName(new CaseInsensitiveString(fixture.pipelineName)));
    String xml = new MagicalGoConfigXmlWriter(configCache, registry).toXmlPartial(pipelineConfig);
    String md5 = CachedDigestUtils.md5Hex(xml);
    StageConfig devStage = pipelineConfig.findBy(new CaseInsensitiveString(fixture.devStage));
    pipelineConfig.remove(devStage);
    pipelineConfigService.updatePipelineConfig(loserUser, pipelineConfig, md5, new HttpLocalizedOperationResult());
    Pipeline pipeline = pipelineDao.mostRecentPipeline(fixture.pipelineName);
    JobInstance job = pipeline.getFirstStage().getJobInstances().first();
    assertThat(job.getState(), is(JobState.Completed));
    assertThat(job.getResult(), is(JobResult.Cancelled));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Cloner(com.rits.cloning.Cloner)

Example 7 with Cloner

use of com.rits.cloning.Cloner in project gocd by gocd.

the class MergeCruiseConfigTest method shouldCollectPipelineNameConflictErrorsInTheChildren_InMergedConfig_WhenCloned.

@Test
public void shouldCollectPipelineNameConflictErrorsInTheChildren_InMergedConfig_WhenCloned() {
    //we need this case because cloning has proven to be problematic with complex object graph in merged config
    BasicCruiseConfig mainCruiseConfig = GoConfigMother.configWithPipelines("pipeline-1");
    PartialConfig partialConfig = PartialConfigMother.withPipelineInGroup("pipeline-1", "g2");
    partialConfig.setOrigin(new RepoConfigOrigin());
    CruiseConfig config = new BasicCruiseConfig(mainCruiseConfig, partialConfig);
    Cloner CLONER = new Cloner();
    CruiseConfig cloned = CLONER.deepClone(config);
    List<ConfigErrors> allErrors = cloned.validateAfterPreprocess();
    assertThat(allErrors.size(), is(2));
    assertThat(allErrors.get(0).on("name"), is("You have defined multiple pipelines named 'pipeline-1'. Pipeline names must be unique. Source(s): [http://some.git at 1234fed, cruise-config.xml]"));
    assertThat(allErrors.get(1).on("name"), is("You have defined multiple pipelines named 'pipeline-1'. Pipeline names must be unique. Source(s): [http://some.git at 1234fed, cruise-config.xml]"));
}
Also used : Cloner(com.rits.cloning.Cloner) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors) Test(org.junit.Test)

Example 8 with Cloner

use of com.rits.cloning.Cloner in project gocd by gocd.

the class GoConfigParallelGraphWalkerTest method shouldAddErrorsToRawCruiseConfigWhenTemplateHasErrors.

@Test
public void shouldAddErrorsToRawCruiseConfigWhenTemplateHasErrors() {
    CruiseConfig cruiseConfig = GoConfigMother.configWithPipelines("pipeline-1");
    cruiseConfig.getTemplates().add(new PipelineTemplateConfig(new CaseInsensitiveString("invalid template name"), new StageConfig(new CaseInsensitiveString("stage-1"), new JobConfigs(new JobConfig("job-1")))));
    PipelineConfig pipelineWithTemplate = new PipelineConfig(new CaseInsensitiveString("pipeline-with-template"), MaterialConfigsMother.defaultMaterialConfigs());
    pipelineWithTemplate.setTemplateName(new CaseInsensitiveString("invalid template name"));
    cruiseConfig.getGroups().get(0).add(pipelineWithTemplate);
    CruiseConfig rawCruiseConfig = new Cloner().deepClone(cruiseConfig);
    MagicalGoConfigXmlLoader.validate(cruiseConfig);
    cruiseConfig.copyErrorsTo(rawCruiseConfig);
    ConfigErrors templateErrors = rawCruiseConfig.getTemplateByName(new CaseInsensitiveString("invalid template name")).errors();
    assertThat(templateErrors.getAll().size(), is(1));
    assertThat(templateErrors.getAll().get(0), is("Invalid template name 'invalid template 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 : Cloner(com.rits.cloning.Cloner) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors) Test(org.junit.Test)

Example 9 with Cloner

use of com.rits.cloning.Cloner in project gocd by gocd.

the class GoConfigServiceIntegrationTest method shouldReturnTheLatestConfigAsResultWhenThereIsAnMd5Conflict.

@Test
public void shouldReturnTheLatestConfigAsResultWhenThereIsAnMd5Conflict() {
    configHelper.addPipeline("pipeline", "stage");
    String md5 = goConfigService.getConfigForEditing().getMd5();
    goConfigService.updateConfigFromUI(new AddStageToPipelineCommand("secondStage"), md5, Username.ANONYMOUS, new HttpLocalizedOperationResult());
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ConfigUpdateResponse response = goConfigService.updateConfigFromUI(new AddStageToPipelineCommand("thirdStage"), md5, Username.ANONYMOUS, result);
    assertFailedResult(result, "Save failed. Configuration file has been modified by someone else.");
    CruiseConfig expectedConfig = goConfigService.getConfigForEditing();
    CruiseConfig modifiedConfig = new Cloner().deepClone(expectedConfig);
    ReflectionUtil.setField(modifiedConfig, "md5", expectedConfig.getMd5());
    PipelineConfig expected = modifiedConfig.pipelineConfigByName(new CaseInsensitiveString("pipeline"));
    expected.addStageWithoutValidityAssertion(StageConfigMother.custom("thirdStage", "job"));
    PipelineConfig actual = (PipelineConfig) response.getNode();
    assertThat(response.configAfterUpdate(), is(expectedConfig));
    assertThat(response.getCruiseConfig(), is(modifiedConfig));
    assertThat(actual, is(expected));
    assertFailedResult(result, "Save failed. Configuration file has been modified by someone else.");
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Matchers.containsString(org.hamcrest.Matchers.containsString) ConfigUpdateResponse(com.thoughtworks.go.config.update.ConfigUpdateResponse) Cloner(com.rits.cloning.Cloner) Test(org.junit.Test)

Example 10 with Cloner

use of com.rits.cloning.Cloner in project gocd by gocd.

the class PipelineConfigTreeValidator method validateDependencyMaterialsForDownstreams.

private void validateDependencyMaterialsForDownstreams(PipelineConfigSaveValidationContext validationContext, CaseInsensitiveString selected, PipelineConfig downstreamPipeline) {
    Node dependenciesOfSelectedPipeline = validationContext.getDependencyMaterialsFor(selected);
    for (Node.DependencyNode dependencyNode : dependenciesOfSelectedPipeline.getDependencies()) {
        if (dependencyNode.getPipelineName().equals(pipelineConfig.name())) {
            for (MaterialConfig materialConfig : downstreamPipeline.materialConfigs()) {
                if (materialConfig instanceof DependencyMaterialConfig) {
                    DependencyMaterialConfig dependencyMaterialConfig = new Cloner().deepClone((DependencyMaterialConfig) materialConfig);
                    dependencyMaterialConfig.validate(validationContext.withParent(downstreamPipeline));
                    List<String> allErrors = dependencyMaterialConfig.errors().getAll();
                    for (String error : allErrors) {
                        pipelineConfig.errors().add("base", error);
                    }
                }
            }
        }
    }
}
Also used : DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Cloner(com.rits.cloning.Cloner)

Aggregations

Cloner (com.rits.cloning.Cloner)26 Test (org.junit.Test)12 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)7 File (java.io.File)7 StringContains.containsString (org.hamcrest.core.StringContains.containsString)7 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)6 FullConfigUpdateCommand (com.thoughtworks.go.config.update.FullConfigUpdateCommand)5 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)3 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)2 ConfigErrors (com.thoughtworks.go.domain.ConfigErrors)2 IOException (java.io.IOException)2 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 ExpectedException (org.junit.rules.ExpectedException)2 Cache (com.opensymphony.oscache.base.Cache)1 ArtifactPlan (com.thoughtworks.go.config.ArtifactPlan)1 ArtifactPropertiesGenerator (com.thoughtworks.go.config.ArtifactPropertiesGenerator)1 MergeEnvironmentConfig (com.thoughtworks.go.config.merge.MergeEnvironmentConfig)1 ConfigUpdateResponse (com.thoughtworks.go.config.update.ConfigUpdateResponse)1 GoConfigValidity (com.thoughtworks.go.config.validation.GoConfigValidity)1