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"));
}
use of com.rits.cloning.Cloner in project gocd by gocd.
the class ArtifactPropertiesGeneratorTest method shouldBeAbleToCreateACopyOfItself.
@Test
public void shouldBeAbleToCreateACopyOfItself() throws Exception {
ArtifactPropertiesGenerator existingGenerator = new ArtifactPropertiesGenerator("prop1", "props.xml", "//some_xpath");
existingGenerator.setId(2);
existingGenerator.setJobId(10);
existingGenerator.addError("abc", "def");
assertThat(existingGenerator, equalTo(new ArtifactPropertiesGenerator(existingGenerator)));
assertThat(existingGenerator, equalTo(new Cloner().deepClone(existingGenerator)));
}
use of com.rits.cloning.Cloner in project gocd by gocd.
the class ArtifactPlanTest method shouldBeAbleToCreateACopyOfItself.
@Test
public void shouldBeAbleToCreateACopyOfItself() throws Exception {
ArtifactPlan existingPlan = new ArtifactPlan("src1", "dest1");
existingPlan.setId(2);
existingPlan.setBuildId(10);
existingPlan.addError("abc", "def");
assertThat(existingPlan, equalTo(new ArtifactPlan(existingPlan)));
assertThat(existingPlan, equalTo(new Cloner().deepClone(existingPlan)));
}
use of com.rits.cloning.Cloner in project gocd by gocd.
the class EnvironmentConfigTestBase method shouldNotUpdateAnythingForNullAttributes.
@Test
public void shouldNotUpdateAnythingForNullAttributes() {
EnvironmentConfig beforeUpdate = new Cloner().deepClone(environmentConfig);
environmentConfig.setConfigAttributes(null);
assertThat(environmentConfig, is(beforeUpdate));
}
Aggregations