use of com.rits.cloning.Cloner in project gocd by gocd.
the class ResourceTest method shouldBeAbleToCreateACopyOfItself.
@Test
public void shouldBeAbleToCreateACopyOfItself() {
Resource existingResource = new Resource("some-name");
existingResource.setId(2);
existingResource.setBuildId(10);
assertThat(existingResource, equalTo(new Resource(existingResource)));
assertThat(existingResource, equalTo(new Cloner().deepClone(existingResource)));
}
use of com.rits.cloning.Cloner in project gocd by gocd.
the class PipelineConfigServiceTest method pipelineCountShouldIncludeConfigRepoPipelinesAsWell.
@Test
public void pipelineCountShouldIncludeConfigRepoPipelinesAsWell() {
CruiseConfig mergedCruiseConfig = new Cloner().deepClone(cruiseConfig);
ReflectionUtil.setField(mergedCruiseConfig, "allPipelineConfigs", null);
mergedCruiseConfig.addPipeline("default", PipelineConfigMother.pipelineConfig(UUID.randomUUID().toString()));
when(goConfigService.cruiseConfig()).thenReturn(mergedCruiseConfig);
when(goConfigService.getConfigForEditing()).thenReturn(cruiseConfig);
when(goConfigService.getAllPipelineConfigs()).thenReturn(mergedCruiseConfig.getAllPipelineConfigs());
assertThat(pipelineConfigService.totalPipelinesCount(), is(mergedCruiseConfig.allPipelines().size()));
}
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]"));
}
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.");
}
use of com.rits.cloning.Cloner in project gocd by gocd.
the class PipelineConfigValidationTest method shouldDetectCyclicDependencies.
@Test
public void shouldDetectCyclicDependencies() {
String pipelineName = "p1";
BasicCruiseConfig cruiseConfig = GoConfigMother.configWithPipelines(pipelineName, "p2", "p3");
PipelineConfig p2 = cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString("p2"));
p2.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString(pipelineName), new CaseInsensitiveString("stage")));
PipelineConfig p3 = cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString("p3"));
p3.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("p2"), new CaseInsensitiveString("stage")));
PipelineConfig p1 = cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString(pipelineName));
// Do not remove cloning else it changes the underlying cache object defeating the purpose of the test.
p1 = new Cloner().deepClone(p1);
p1.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("p3"), new CaseInsensitiveString("stage")));
p1.validateTree(PipelineConfigSaveValidationContext.forChain(true, cruiseConfig.getGroups().first().getGroup(), cruiseConfig, p1));
assertThat(p1.materialConfigs().errors().isEmpty(), is(false));
assertThat(p1.materialConfigs().errors().on("base"), is("Circular dependency: p1 <- p2 <- p3 <- p1"));
}
Aggregations