Search in sources :

Example 11 with FullConfigUpdateCommand

use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.

the class CachedGoConfigIntegrationTest method shouldMarkAPreviousInvalidPartialAsValid_IfMainXMLSatisfiesTheDependency.

@Test
public void shouldMarkAPreviousInvalidPartialAsValid_IfMainXMLSatisfiesTheDependency() throws GitAPIException, IOException {
    String gitShaBeforeSave = configRepository.getCurrentRevCommit().getName();
    PipelineConfig upstream = PipelineConfigMother.createPipelineConfig("upstream", "S", "J");
    PartialConfig partialConfig = PartialConfigMother.pipelineWithDependencyMaterial("downstream", upstream, new RepoConfigOrigin(configRepo, "r2"));
    partialConfigService.onSuccessPartialConfig(configRepo, partialConfig);
    assertThat(cachedGoPartials.lastKnownPartials().contains(partialConfig)).isTrue();
    assertThat(cachedGoPartials.lastValidPartials().isEmpty()).isTrue();
    CruiseConfig originalConfig = cachedGoConfig.loadForEditing();
    CruiseConfig editedConfig = GoConfigMother.deepClone(originalConfig);
    editedConfig.addPipeline("default", upstream);
    ConfigSaveState state = cachedGoConfig.writeFullConfigWithLock(new FullConfigUpdateCommand(editedConfig, goConfigService.configFileMd5()));
    String gitShaAfterSave = configRepository.getCurrentRevCommit().getName();
    String configXmlFromConfigFolder = FileUtils.readFileToString(new File(goConfigDao.fileLocation()), UTF_8);
    assertThat(state).isEqualTo(ConfigSaveState.UPDATED);
    assertThat(cachedGoConfig.loadForEditing()).isEqualTo(editedConfig);
    assertThat(gitShaAfterSave).isNotEqualTo(gitShaBeforeSave);
    assertThat(cachedGoConfig.loadForEditing().getMd5()).isEqualTo(configRepository.getCurrentRevision().getMd5());
    assertThat(cachedGoConfig.currentConfig().getMd5()).isEqualTo(configRepository.getCurrentRevision().getMd5());
    assertThat(configXmlFromConfigFolder).isEqualTo(configRepository.getCurrentRevision().getContent());
    RepoConfigOrigin origin = (RepoConfigOrigin) cachedGoPartials.lastValidPartials().get(0).getOrigin();
    assertThat(origin.getRevision()).isEqualTo("r2");
    assertThat(cachedGoPartials.lastKnownPartials().contains(partialConfig)).isTrue();
    assertThat(cachedGoPartials.lastValidPartials().contains(partialConfig)).isTrue();
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 12 with FullConfigUpdateCommand

use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.

the class FullConfigSaveFlowTestBase method shouldEncryptPluginPropertiesOfFetchTask.

@Test
public void shouldEncryptPluginPropertiesOfFetchTask() throws Exception {
    CruiseConfig cruiseConfig = loader.deserializeConfig(xml);
    Configuration childFetchConfigBeforeEncryption = ((FetchPluggableArtifactTask) cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("child")).get(0).getJobs().get(0).tasks().get(0)).getConfiguration();
    assertThat(childFetchConfigBeforeEncryption.getProperty("FetchProperty").getValue(), is("SECRET"));
    assertThat(childFetchConfigBeforeEncryption.getProperty("FetchProperty").getEncryptedValue(), is(nullValue()));
    assertThat(childFetchConfigBeforeEncryption.getProperty("FetchProperty").getConfigValue(), is("SECRET"));
    GoConfigHolder configHolder = getImplementer().execute(new FullConfigUpdateCommand(cruiseConfig, goConfigService.configFileMd5()), new ArrayList<>(), "Upgrade");
    Configuration childFetchConfigAfterEncryption = ((FetchPluggableArtifactTask) configHolder.configForEdit.pipelineConfigByName(new CaseInsensitiveString("child")).get(0).getJobs().get(0).tasks().get(0)).getConfiguration();
    assertThat(childFetchConfigAfterEncryption.getProperty("FetchProperty").getValue(), is("SECRET"));
    assertThat(childFetchConfigAfterEncryption.getProperty("FetchProperty").getEncryptedValue(), startsWith("AES:"));
    assertThat(childFetchConfigAfterEncryption.getProperty("FetchProperty").getConfigValue(), is(nullValue()));
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) Test(org.junit.jupiter.api.Test)

Example 13 with FullConfigUpdateCommand

use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.

the class CachedGoConfigIntegrationTest method shouldUpdateConfigWhenPartialsAreNotConfigured.

@Test
public void shouldUpdateConfigWhenPartialsAreNotConfigured() throws GitAPIException, IOException {
    String gitShaBeforeSave = configRepository.getCurrentRevCommit().getName();
    BasicCruiseConfig config = GoConfigMother.configWithPipelines("pipeline1");
    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).isEqualTo(ConfigSaveState.UPDATED);
    assertThat(cachedGoConfig.loadForEditing()).isEqualTo(config);
    assertThat(gitShaAfterSave).isNotEqualTo(gitShaBeforeSave);
    assertThat(cachedGoConfig.loadForEditing().getMd5()).isEqualTo(configRepository.getCurrentRevision().getMd5());
    assertThat(cachedGoConfig.currentConfig().getMd5()).isEqualTo(configRepository.getCurrentRevision().getMd5());
    assertThat(configXmlFromConfigFolder).isEqualTo(configRepository.getCurrentRevision().getContent());
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 14 with FullConfigUpdateCommand

use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.

the class CachedGoConfigIntegrationTest method shouldUpdateConfigWithNoValidPartialsAndInvalidKnownPartials.

@Test
public void shouldUpdateConfigWithNoValidPartialsAndInvalidKnownPartials() throws GitAPIException, IOException {
    String gitShaBeforeSave = configRepository.getCurrentRevCommit().getName();
    PartialConfig invalidPartial = PartialConfigMother.invalidPartial("invalid", new RepoConfigOrigin(configRepo, "revision1"));
    partialConfigService.onSuccessPartialConfig(configRepo, invalidPartial);
    assertThat(cachedGoPartials.lastValidPartials().isEmpty()).isTrue();
    assertThat(cachedGoPartials.lastKnownPartials().contains(invalidPartial)).isTrue();
    CruiseConfig config = GoConfigMother.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).isEqualTo(ConfigSaveState.UPDATED);
    assertThat(cachedGoConfig.loadForEditing()).isEqualTo(config);
    assertThat(gitShaAfterSave).isNotEqualTo(gitShaBeforeSave);
    assertThat(cachedGoConfig.loadForEditing().getMd5()).isEqualTo(configRepository.getCurrentRevision().getMd5());
    assertThat(cachedGoConfig.currentConfig().getMd5()).isEqualTo(configRepository.getCurrentRevision().getMd5());
    assertThat(configXmlFromConfigFolder).isEqualTo(configRepository.getCurrentRevision().getContent());
    assertThat(cachedGoPartials.lastValidPartials().isEmpty()).isTrue();
    assertThat(cachedGoPartials.lastKnownPartials().contains(invalidPartial)).isTrue();
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 15 with FullConfigUpdateCommand

use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.

the class CachedGoConfigIntegrationTest method writeFullConfigWithLockShouldUpdateReloadStrategyToEnsureReloadIsSkippedInAbsenceOfConfigFileChanges.

@Test
public void writeFullConfigWithLockShouldUpdateReloadStrategyToEnsureReloadIsSkippedInAbsenceOfConfigFileChanges() throws GitAPIException, IOException {
    BasicCruiseConfig config = GoConfigMother.configWithPipelines("pipeline1");
    ConfigSaveState state = cachedGoConfig.writeFullConfigWithLock(new FullConfigUpdateCommand(config, goConfigService.configFileMd5()));
    String gitShaAfterSave = configRepository.getCurrentRevCommit().getName();
    assertThat(state).isEqualTo(ConfigSaveState.UPDATED);
    cachedGoConfig.forceReload();
    String gitShaAfterReload = configRepository.getCurrentRevCommit().getName();
    assertThat(gitShaAfterReload).isEqualTo(gitShaAfterSave);
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) Test(org.junit.jupiter.api.Test)

Aggregations

FullConfigUpdateCommand (com.thoughtworks.go.config.update.FullConfigUpdateCommand)28 Test (org.junit.jupiter.api.Test)23 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)11 File (java.io.File)11 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)8 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)4 ConfigElementImplementationRegistry (com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry)3 GoConfigValidity (com.thoughtworks.go.config.validation.GoConfigValidity)3 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)3 Configuration (com.thoughtworks.go.domain.config.Configuration)2 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)2 ConfigRepository (com.thoughtworks.go.service.ConfigRepository)2 TimeProvider (com.thoughtworks.go.util.TimeProvider)2 IOException (java.io.IOException)2 Arrays.asList (java.util.Arrays.asList)2 Document (org.jdom2.Document)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ContextConfiguration (org.springframework.test.context.ContextConfiguration)2 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)1 ConfigElementImplementationRegistrar (com.thoughtworks.go.config.registry.ConfigElementImplementationRegistrar)1