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());
}
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"));
}
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"));
}
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");
}
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));
}
Aggregations