Search in sources :

Example 11 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 12 with Cloner

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

Example 13 with Cloner

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)));
}
Also used : ArtifactPropertiesGenerator(com.thoughtworks.go.config.ArtifactPropertiesGenerator) Cloner(com.rits.cloning.Cloner) Test(org.junit.Test)

Example 14 with Cloner

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)));
}
Also used : ArtifactPlan(com.thoughtworks.go.config.ArtifactPlan) Cloner(com.rits.cloning.Cloner) Test(org.junit.Test)

Example 15 with Cloner

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));
}
Also used : Cloner(com.rits.cloning.Cloner) Test(org.junit.Test)

Aggregations

Cloner (com.rits.cloning.Cloner)28 Test (org.junit.Test)14 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 Matchers.containsString (org.hamcrest.Matchers.containsString)3 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)2 MergeEnvironmentConfig (com.thoughtworks.go.config.merge.MergeEnvironmentConfig)2 ConfigErrors (com.thoughtworks.go.domain.ConfigErrors)2 IOException (java.io.IOException)2 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)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 ConfigUpdateResponse (com.thoughtworks.go.config.update.ConfigUpdateResponse)1 GoConfigValidity (com.thoughtworks.go.config.validation.GoConfigValidity)1