Search in sources :

Example 21 with FullConfigUpdateCommand

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

the class GoFileConfigDataSourceTest method shouldNotRetryConfigUpdateIfLastKnownPartialsAreEmpty_OnWriteFullConfigWithLock.

@Test
public void shouldNotRetryConfigUpdateIfLastKnownPartialsAreEmpty_OnWriteFullConfigWithLock() throws Exception {
    List<PartialConfig> known = new ArrayList<>();
    BasicCruiseConfig configForEdit = new BasicCruiseConfig();
    MagicalGoConfigXmlLoader.setMd5(configForEdit, "md5");
    FullConfigUpdateCommand updatingCommand = new FullConfigUpdateCommand(new BasicCruiseConfig(), "md5");
    GoConfigHolder configHolder = new GoConfigHolder(new BasicCruiseConfig(), configForEdit);
    when(cachedGoPartials.lastKnownPartials()).thenReturn(known);
    when(fullConfigSaveNormalFlow.execute(updatingCommand, known, "loser_boozer")).thenThrow(new GoConfigInvalidException(configForEdit, "error"));
    assertThatThrownBy(() -> dataSource.writeFullConfigWithLock(updatingCommand, configHolder)).isInstanceOf(RuntimeException.class);
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) Test(org.junit.jupiter.api.Test)

Example 22 with FullConfigUpdateCommand

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

the class GoFileConfigDataSourceTest method shouldReloadConfigUsingFullSaveNormalFlowWithLastValidPartialsIfUpdatingWithLastKnownPartialsFails_onLoad.

@Test
public void shouldReloadConfigUsingFullSaveNormalFlowWithLastValidPartialsIfUpdatingWithLastKnownPartialsFails_onLoad() throws Exception {
    CruiseConfig cruiseConfig = new BasicCruiseConfig();
    PartialConfigMother.withPipeline("P1");
    List lastKnownPartials = Arrays.asList(PartialConfigMother.withPipeline("P1"));
    List lastValidPartials = Arrays.asList(PartialConfigMother.withPipeline("P2"), PartialConfigMother.withPipeline("P3"));
    GoConfigHolder goConfigHolder = new GoConfigHolder(cruiseConfig, cruiseConfig);
    ArgumentCaptor<FullConfigUpdateCommand> commandArgumentCaptor = ArgumentCaptor.forClass(FullConfigUpdateCommand.class);
    ArgumentCaptor<List> listArgumentCaptor = ArgumentCaptor.forClass(List.class);
    ArgumentCaptor<String> stringArgumentCaptor = ArgumentCaptor.forClass(String.class);
    when(systemEnvironment.getCruiseConfigFile()).thenReturn("");
    when(goConfigFileReader.fileLocation()).thenReturn(new File(""));
    when(goConfigFileReader.configXml()).thenReturn("config_xml");
    when(xmlLoader.deserializeConfig("config_xml")).thenReturn(cruiseConfig);
    when(cachedGoPartials.lastKnownPartials()).thenReturn(lastKnownPartials);
    when(cachedGoPartials.lastValidPartials()).thenReturn(lastValidPartials);
    when(fullConfigSaveNormalFlow.execute(commandArgumentCaptor.capture(), listArgumentCaptor.capture(), stringArgumentCaptor.capture())).thenThrow(new GoConfigInvalidException(null, Collections.emptyList())).thenReturn(goConfigHolder);
    dataSource.reloadEveryTime();
    GoConfigHolder configHolder = dataSource.load();
    assertThat(configHolder, is(goConfigHolder));
    assertThat(commandArgumentCaptor.getValue().configForEdit(), is(cruiseConfig));
    assertThat(listArgumentCaptor.getValue(), is(lastValidPartials));
    assertThat(stringArgumentCaptor.getValue(), is("Filesystem"));
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) Arrays.asList(java.util.Arrays.asList) File(java.io.File) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) Test(org.junit.jupiter.api.Test)

Example 23 with FullConfigUpdateCommand

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

the class FullConfigSaveNormalFlowTest method setup.

@BeforeEach
public void setup() throws Exception {
    configForEdit = new BasicCruiseConfig();
    updateConfigCommand = new FullConfigUpdateCommand(configForEdit, "md5");
    loader = mock(MagicalGoConfigXmlLoader.class);
    writer = mock(MagicalGoConfigXmlWriter.class);
    document = mock(Document.class);
    fileWriter = mock(GoConfigFileWriter.class);
    timeProvider = mock(TimeProvider.class);
    configRepository = mock(ConfigRepository.class);
    cachedGoPartials = mock(CachedGoPartials.class);
    configElementImplementationRegistry = mock(ConfigElementImplementationRegistry.class);
    partials = new ArrayList<>();
    flow = new FullConfigSaveNormalFlow(loader, writer, configElementImplementationRegistry, timeProvider, configRepository, cachedGoPartials, fileWriter);
    when(writer.documentFrom(configForEdit)).thenReturn(document);
    when(loader.preprocessAndValidate(configForEdit)).thenReturn(new BasicCruiseConfig());
    when(writer.toString(document)).thenReturn("cruise_config");
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) TimeProvider(com.thoughtworks.go.util.TimeProvider) ConfigElementImplementationRegistry(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry) ConfigRepository(com.thoughtworks.go.service.ConfigRepository) Document(org.jdom2.Document) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 24 with FullConfigUpdateCommand

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

the class GoConfigServiceTest method shouldIgnoreXmlEntitiesAndReplaceThemWithEmptyString_DuringPipelineGroupPartialSave.

@Test
public void shouldIgnoreXmlEntitiesAndReplaceThemWithEmptyString_DuringPipelineGroupPartialSave() throws Exception {
    ArgumentCaptor<FullConfigUpdateCommand> commandArgumentCaptor = ArgumentCaptor.forClass(FullConfigUpdateCommand.class);
    File targetFile = TempFiles.createUniqueFile("somefile");
    FileUtils.writeStringToFile(targetFile, "CONTENTS_OF_FILE", StandardCharsets.UTF_8);
    cruiseConfig = new BasicCruiseConfig();
    expectLoad(cruiseConfig);
    new GoConfigMother().addPipelineWithGroup(cruiseConfig, "group_name", "pipeline1", "stage_name", "job_name");
    expectLoadForEditing(cruiseConfig);
    when(goConfigDao.md5OfConfigFile()).thenReturn("md5");
    when(goConfigDao.updateFullConfig(commandArgumentCaptor.capture())).thenReturn(null);
    GoConfigService.XmlPartialSaver partialSaver = goConfigService.groupSaver("group_name");
    GoConfigValidity validity = partialSaver.saveXml(groupXmlWithEntity(targetFile.getAbsolutePath()), "md5");
    PipelineConfigs group = commandArgumentCaptor.getValue().configForEdit().findGroup("group_name");
    PipelineConfig pipeline = group.findBy(new CaseInsensitiveString("pipeline1"));
    assertThat(validity.isValid(), Matchers.is(true));
    String entityValue = pipeline.getParams().getParamNamed("foo").getValue();
    assertThat(entityValue, not(containsString("CONTENTS_OF_FILE")));
    assertThat(entityValue, isEmptyString());
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) File(java.io.File) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.jupiter.api.Test)

Example 25 with FullConfigUpdateCommand

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

the class CachedGoConfigIntegrationTest method shouldUpdateConfigWhenPartialsAreConfigured.

@Test
public void shouldUpdateConfigWhenPartialsAreConfigured() throws GitAPIException, IOException {
    String gitShaBeforeSave = configRepository.getCurrentRevCommit().getName();
    PartialConfig validPartial = PartialConfigMother.withPipeline("remote_pipeline", new RepoConfigOrigin(configRepo, "revision1"));
    partialConfigService.onSuccessPartialConfig(configRepo, validPartial);
    assertThat(cachedGoPartials.lastValidPartials().contains(validPartial)).isTrue();
    assertThat(cachedGoPartials.lastKnownPartials().contains(validPartial)).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().contains(validPartial)).isTrue();
    assertThat(cachedGoPartials.lastKnownPartials().contains(validPartial)).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)

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