Search in sources :

Example 1 with FullConfigUpdateCommand

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

the class CachedGoConfigTest method shouldWriteFullConfigWithLock.

@Test
public void shouldWriteFullConfigWithLock() {
    FullConfigUpdateCommand fullConfigUpdateCommand = mock(FullConfigUpdateCommand.class);
    when(dataSource.writeFullConfigWithLock(any(FullConfigUpdateCommand.class), any(GoConfigHolder.class))).thenReturn(new GoFileConfigDataSource.GoConfigSaveResult(null, null));
    cachedGoConfig.forceReload();
    cachedGoConfig.writeFullConfigWithLock(fullConfigUpdateCommand);
    verify(dataSource).writeFullConfigWithLock(fullConfigUpdateCommand, cachedGoConfig.loadConfigHolder());
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) Test(org.junit.jupiter.api.Test)

Example 2 with FullConfigUpdateCommand

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

the class GoConfigServiceTest method shouldUpdateXmlUsingNewFlowIfEnabled.

@Test
public void shouldUpdateXmlUsingNewFlowIfEnabled() throws Exception {
    String groupName = "group_name";
    String md5 = "md5";
    cruiseConfig = new BasicCruiseConfig();
    ArgumentCaptor<FullConfigUpdateCommand> commandArgumentCaptor = ArgumentCaptor.forClass(FullConfigUpdateCommand.class);
    expectLoad(cruiseConfig);
    new GoConfigMother().addPipelineWithGroup(cruiseConfig, groupName, "pipeline_name", "stage_name", "job_name");
    expectLoadForEditing(cruiseConfig);
    when(goConfigDao.md5OfConfigFile()).thenReturn(md5);
    when(goConfigDao.updateFullConfig(commandArgumentCaptor.capture())).thenReturn(null);
    GoConfigService.XmlPartialSaver partialSaver = goConfigService.groupSaver(groupName);
    String renamedGroupName = "renamed_group_name";
    GoConfigValidity validity = partialSaver.saveXml(groupXml(renamedGroupName), md5);
    assertThat(validity.isValid(), Matchers.is(true));
    CruiseConfig updatedConfig = commandArgumentCaptor.getValue().configForEdit();
    PipelineConfigs group = updatedConfig.findGroup(renamedGroupName);
    PipelineConfig pipeline = group.findBy(new CaseInsensitiveString("new_name"));
    assertThat(pipeline.name(), is(new CaseInsensitiveString("new_name")));
    assertThat(pipeline.getLabelTemplate(), is("${COUNT}-#{foo}"));
    assertThat(pipeline.materialConfigs().first(), is(instanceOf(SvnMaterialConfig.class)));
    assertThat(pipeline.materialConfigs().first().getUriForDisplay(), is("file:///tmp/foo"));
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.jupiter.api.Test)

Example 3 with FullConfigUpdateCommand

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

the class GoConfigServiceTest method shouldReturnValidOnUpdateXml.

@Test
public void shouldReturnValidOnUpdateXml() throws Exception {
    String groupName = "group_name";
    String md5 = "md5";
    cruiseConfig = new BasicCruiseConfig();
    expectLoad(cruiseConfig);
    new GoConfigMother().addPipelineWithGroup(cruiseConfig, groupName, "pipeline_name", "stage_name", "job_name");
    expectLoadForEditing(cruiseConfig);
    when(goConfigDao.md5OfConfigFile()).thenReturn(md5);
    GoConfigService.XmlPartialSaver partialSaver = goConfigService.groupSaver(groupName);
    String renamedGroupName = "renamed_group_name";
    GoConfigValidity validity = partialSaver.saveXml(groupXml(renamedGroupName), md5);
    assertThat(validity.isValid(), Matchers.is(true));
    ArgumentCaptor<FullConfigUpdateCommand> commandArgCaptor = ArgumentCaptor.forClass(FullConfigUpdateCommand.class);
    verify(goConfigDao).updateFullConfig(commandArgCaptor.capture());
    FullConfigUpdateCommand command = commandArgCaptor.getValue();
    CruiseConfig updatedConfig = command.configForEdit();
    PipelineConfigs group = updatedConfig.findGroup(renamedGroupName);
    PipelineConfig pipeline = group.findBy(new CaseInsensitiveString("new_name"));
    assertThat(pipeline.name(), is(new CaseInsensitiveString("new_name")));
    assertThat(pipeline.getLabelTemplate(), is("${COUNT}-#{foo}"));
    assertThat(pipeline.materialConfigs().first(), is(instanceOf(SvnMaterialConfig.class)));
    assertThat(pipeline.materialConfigs().first().getUriForDisplay(), is("file:///tmp/foo"));
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.jupiter.api.Test)

Example 4 with FullConfigUpdateCommand

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

the class GoFileConfigDataSourceTest method shouldEnsureMergeFlowWithLastKnownPartialsIfConfigHasChangedBetweenUpdates_OnWriteFullConfigWithLock.

@Test
public void shouldEnsureMergeFlowWithLastKnownPartialsIfConfigHasChangedBetweenUpdates_OnWriteFullConfigWithLock() throws Exception {
    com.thoughtworks.go.server.newsecurity.SessionUtilsHelper.loginAs("loser_boozer");
    when(systemEnvironment.get(SystemEnvironment.ENABLE_CONFIG_MERGE_FEATURE)).thenReturn(true);
    BasicCruiseConfig configForEdit = new BasicCruiseConfig();
    MagicalGoConfigXmlLoader.setMd5(configForEdit, "new_md5");
    FullConfigUpdateCommand updatingCommand = new FullConfigUpdateCommand(new BasicCruiseConfig(), "old_md5");
    GoConfigHolder configHolder = new GoConfigHolder(new BasicCruiseConfig(), configForEdit);
    List<PartialConfig> lastKnownPartials = mock(List.class);
    when(cachedGoPartials.lastKnownPartials()).thenReturn(lastKnownPartials);
    when(fullConfigSaveMergeFlow.execute(any(FullConfigUpdateCommand.class), anyList(), any(String.class))).thenReturn(new GoConfigHolder(new BasicCruiseConfig(), new BasicCruiseConfig()));
    dataSource.writeFullConfigWithLock(updatingCommand, configHolder);
    verify(fullConfigSaveMergeFlow).execute(updatingCommand, lastKnownPartials, "loser_boozer");
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) Test(org.junit.jupiter.api.Test)

Example 5 with FullConfigUpdateCommand

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

the class GoFileConfigDataSourceTest method shouldErrorOutOnTryingToMergeConfigsIfConfigMergeFeatureIsDisabled_OnWriteFullConfigWithLock.

@Test
public void shouldErrorOutOnTryingToMergeConfigsIfConfigMergeFeatureIsDisabled_OnWriteFullConfigWithLock() throws Exception {
    BasicCruiseConfig configForEdit = new BasicCruiseConfig();
    MagicalGoConfigXmlLoader.setMd5(configForEdit, "new_md5");
    FullConfigUpdateCommand updatingCommand = new FullConfigUpdateCommand(new BasicCruiseConfig(), "old_md5");
    GoConfigHolder configHolder = new GoConfigHolder(new BasicCruiseConfig(), configForEdit);
    List<PartialConfig> lastKnownPartials = new ArrayList<>();
    when(cachedGoPartials.lastKnownPartials()).thenReturn(lastKnownPartials);
    systemEnvironment.set(SystemEnvironment.ENABLE_CONFIG_MERGE_FEATURE, false);
    assertThatThrownBy(() -> dataSource.writeFullConfigWithLock(updatingCommand, configHolder)).isInstanceOf(RuntimeException.class);
    verify(fullConfigSaveMergeFlow, never()).execute(any(FullConfigUpdateCommand.class), anyList(), any(String.class));
    verify(fullConfigSaveNormalFlow, never()).execute(any(FullConfigUpdateCommand.class), anyList(), any(String.class));
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) 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