Search in sources :

Example 1 with Cloner

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

Example 2 with Cloner

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

Example 3 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 4 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 5 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)

Aggregations

Cloner (com.rits.cloning.Cloner)19 Test (org.junit.Test)11 PolyTrendLine (com.eveningoutpost.dexdrip.Models.Forecast.PolyTrendLine)2 TrendLine (com.eveningoutpost.dexdrip.Models.Forecast.TrendLine)2 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)2 ArrayList (java.util.ArrayList)2 Line (lecho.lib.hellocharts.model.Line)2 LineChartData (lecho.lib.hellocharts.model.LineChartData)2 Cache (com.opensymphony.oscache.base.Cache)1 IFastCloner (com.rits.cloning.IFastCloner)1 ArtifactPlan (com.thoughtworks.go.config.ArtifactPlan)1 ArtifactPropertiesGenerator (com.thoughtworks.go.config.ArtifactPropertiesGenerator)1 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)1 ConfigUpdateResponse (com.thoughtworks.go.config.update.ConfigUpdateResponse)1 ConfigErrors (com.thoughtworks.go.domain.ConfigErrors)1 PipelineWithTwoStages (com.thoughtworks.go.fixture.PipelineWithTwoStages)1 GoCache (com.thoughtworks.go.server.cache.GoCache)1 StubGoCache (com.thoughtworks.go.server.service.StubGoCache)1 SqlMapClientTemplate (com.thoughtworks.go.server.transaction.SqlMapClientTemplate)1 TestTransactionSynchronizationManager (com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager)1