Search in sources :

Example 26 with Cloner

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

the class CachedGoConfigIntegrationTest method shouldMarkAPartialAsValidIfItBecomesValidBecauseOfNewerChangesInMainXml_GitMergeWorkflow.

@Test
public void shouldMarkAPartialAsValidIfItBecomesValidBecauseOfNewerChangesInMainXml_GitMergeWorkflow() {
    final String upstream = UUID.randomUUID().toString();
    String remoteDownstream = "remote-downstream";
    setupExternalConfigRepoWithDependencyMaterialOnPipelineInMainXml(upstream, remoteDownstream);
    PartialConfig partialWithStageRenamed = new Cloner().deepClone(goPartialConfig.lastPartials().get(0));
    PipelineConfig pipelineInRemoteConfigRepo = partialWithStageRenamed.getGroups().get(0).getPipelines().get(0);
    pipelineInRemoteConfigRepo.materialConfigs().getDependencyMaterial().setStageName(new CaseInsensitiveString("new_name"));
    partialWithStageRenamed.setOrigin(new RepoConfigOrigin(configRepo, "r2"));
    goPartialConfig.onSuccessPartialConfig(configRepo, partialWithStageRenamed);
    final String md5 = cachedGoConfig.currentConfig().getMd5();
    // some random unrelated change to force a git merge workflow
    cachedGoConfig.writeWithLock(new NoOverwriteUpdateConfigCommand() {

        @Override
        public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
            cruiseConfig.server().setCommandRepositoryLocation("new_location");
            return cruiseConfig;
        }

        @Override
        public String unmodifiedMd5() {
            return md5;
        }
    });
    ConfigSaveState saveState = cachedGoConfig.writeWithLock(new NoOverwriteUpdateConfigCommand() {

        @Override
        public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
            cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString(upstream)).getFirstStageConfig().setName(new CaseInsensitiveString("new_name"));
            return cruiseConfig;
        }

        @Override
        public String unmodifiedMd5() {
            return md5;
        }
    });
    assertThat(saveState, is(ConfigSaveState.MERGED));
    assertThat(cachedGoPartials.lastValidPartials().get(0).getGroups().first().get(0).materialConfigs().getDependencyMaterial().getStageName(), is(new CaseInsensitiveString("new_name")));
    assertThat(goConfigService.getConfigForEditing().getPipelineConfigByName(new CaseInsensitiveString(upstream)).getFirstStageConfig().name(), is(new CaseInsensitiveString("new_name")));
    assertThat(goConfigService.getCurrentConfig().getPipelineConfigByName(new CaseInsensitiveString(upstream)).getFirstStageConfig().name(), is(new CaseInsensitiveString("new_name")));
}
Also used : PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) StringContains.containsString(org.hamcrest.core.StringContains.containsString) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) Cloner(com.rits.cloning.Cloner)

Example 27 with Cloner

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

the class CachedGoConfigIntegrationTest method shouldErrorOutOnUpdateConfigWithValidPartials_WithMainConfigBreakingPartials.

@Test
public void shouldErrorOutOnUpdateConfigWithValidPartials_WithMainConfigBreakingPartials() throws GitAPIException, IOException {
    setupExternalConfigRepoWithDependencyMaterialOnPipelineInMainXml("upstream", "downstream");
    String gitShaBeforeSave = configRepository.getCurrentRevCommit().getName();
    CruiseConfig originalConfig = cachedGoConfig.loadForEditing();
    CruiseConfig editedConfig = new Cloner().deepClone(originalConfig);
    editedConfig.getGroups().remove(editedConfig.findGroup("default"));
    try {
        cachedGoConfig.writeFullConfigWithLock(new FullConfigUpdateCommand(editedConfig, goConfigService.configFileMd5()));
        fail("Expected the test to fail");
    } catch (Exception e) {
        String gitShaAfterSave = configRepository.getCurrentRevCommit().getName();
        String configXmlFromConfigFolder = FileUtils.readFileToString(new File(goConfigDao.fileLocation()), UTF_8);
        assertThat(cachedGoConfig.loadForEditing(), is(originalConfig));
        assertEquals(gitShaBeforeSave, gitShaAfterSave);
        assertThat(cachedGoConfig.loadForEditing().getMd5(), is(configRepository.getCurrentRevision().getMd5()));
        assertThat(cachedGoConfig.currentConfig().getMd5(), is(configRepository.getCurrentRevision().getMd5()));
        assertThat(configXmlFromConfigFolder, is(configRepository.getCurrentRevision().getContent()));
        RepoConfigOrigin origin = (RepoConfigOrigin) cachedGoPartials.lastValidPartials().get(0).getOrigin();
        assertThat(origin.getRevision(), is("r1"));
    }
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) StringContains.containsString(org.hamcrest.core.StringContains.containsString) File(java.io.File) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) Cloner(com.rits.cloning.Cloner)

Example 28 with Cloner

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

the class CachedGoConfigIntegrationTest method shouldUpdateConfigWithValidPartialsAndInvalidKnownPartials.

@Test
public void shouldUpdateConfigWithValidPartialsAndInvalidKnownPartials() throws GitAPIException, IOException {
    String gitShaBeforeSave = configRepository.getCurrentRevCommit().getName();
    PartialConfig validPartial = PartialConfigMother.withPipeline("remote_pipeline", new RepoConfigOrigin(configRepo, "revision1"));
    PartialConfig invalidPartial = PartialConfigMother.invalidPartial("invalid", new RepoConfigOrigin(configRepo, "revision2"));
    goPartialConfig.onSuccessPartialConfig(configRepo, validPartial);
    goPartialConfig.onSuccessPartialConfig(configRepo, invalidPartial);
    assertTrue(cachedGoPartials.lastValidPartials().contains(validPartial));
    assertTrue(cachedGoPartials.lastKnownPartials().contains(invalidPartial));
    CruiseConfig config = new Cloner().deepClone(cachedGoConfig.loadForEditing());
    config.addEnvironment(UUID.randomUUID().toString());
    ConfigSaveState state = cachedGoConfig.writeFullConfigWithLock(new FullConfigUpdateCommand(config, goConfigService.configFileMd5()));
    String gitShaAfterSave = configRepository.getCurrentRevCommit().getName();
    String configXmlFromConfigFolder = FileUtils.readFileToString(new File(goConfigDao.fileLocation()), UTF_8);
    assertThat(state, is(ConfigSaveState.UPDATED));
    assertThat(cachedGoConfig.loadForEditing(), is(config));
    assertNotEquals(gitShaBeforeSave, gitShaAfterSave);
    assertThat(cachedGoConfig.loadForEditing().getMd5(), is(configRepository.getCurrentRevision().getMd5()));
    assertThat(cachedGoConfig.currentConfig().getMd5(), is(configRepository.getCurrentRevision().getMd5()));
    assertThat(configXmlFromConfigFolder, is(configRepository.getCurrentRevision().getContent()));
    assertTrue(cachedGoPartials.lastValidPartials().contains(validPartial));
    assertTrue(cachedGoPartials.lastKnownPartials().contains(invalidPartial));
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) StringContains.containsString(org.hamcrest.core.StringContains.containsString) File(java.io.File) Cloner(com.rits.cloning.Cloner)

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