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 GoConfigFileHelper method saveFullConfig.
public void saveFullConfig(String configFileContent, boolean shouldMigrate) throws Exception {
if (shouldMigrate) {
configFileContent = ConfigMigrator.migrate(configFileContent);
}
ConfigElementImplementationRegistry registry = new ConfigElementImplementationRegistry(new NoPluginsInstalled());
new ConfigElementImplementationRegistrar(registry).initialize();
MagicalGoConfigXmlLoader magicalGoConfigXmlLoader = new MagicalGoConfigXmlLoader(new ConfigCache(), registry);
CruiseConfig configToBeWritten = magicalGoConfigXmlLoader.deserializeConfig(configFileContent);
cachedGoConfig.writeFullConfigWithLock(new FullConfigUpdateCommand(configToBeWritten, cachedGoConfig.loadForEditing().getMd5()));
}
use of com.thoughtworks.go.config.update.FullConfigUpdateCommand in project gocd by gocd.
the class CachedGoConfigIntegrationTest method shouldLoadConfigForReadAndEditWhenNewXMLIsWritten.
@Test
public void shouldLoadConfigForReadAndEditWhenNewXMLIsWritten() throws Exception {
String pipelineName = "mingle";
CruiseConfig configToBeWritten = magicalGoConfigXmlLoader.deserializeConfig(configXmlWithPipeline(pipelineName));
cachedGoConfig.writeFullConfigWithLock(new FullConfigUpdateCommand(configToBeWritten, cachedGoConfig.currentConfig().getMd5()));
PipelineConfig reloadedPipelineConfig = cachedGoConfig.currentConfig().pipelineConfigByName(new CaseInsensitiveString(pipelineName));
HgMaterialConfig hgMaterialConfig = (HgMaterialConfig) byFolder(reloadedPipelineConfig.materialConfigs(), "folder");
assertThat(hgMaterialConfig.getUrl()).isEqualTo("http://hg-server/repo-name");
reloadedPipelineConfig = cachedGoConfig.loadForEditing().pipelineConfigByName(new CaseInsensitiveString(pipelineName));
hgMaterialConfig = (HgMaterialConfig) byFolder(reloadedPipelineConfig.materialConfigs(), "folder");
assertThat(hgMaterialConfig.getUrl()).isEqualTo("http://#{foo}/#{bar}");
GoConfigHolder configHolder = cachedGoConfig.loadConfigHolder();
reloadedPipelineConfig = configHolder.config.pipelineConfigByName(new CaseInsensitiveString(pipelineName));
hgMaterialConfig = (HgMaterialConfig) byFolder(reloadedPipelineConfig.materialConfigs(), "folder");
assertThat(hgMaterialConfig.getUrl()).isEqualTo("http://hg-server/repo-name");
reloadedPipelineConfig = configHolder.configForEdit.pipelineConfigByName(new CaseInsensitiveString(pipelineName));
hgMaterialConfig = (HgMaterialConfig) byFolder(reloadedPipelineConfig.materialConfigs(), "folder");
assertThat(hgMaterialConfig.getUrl()).isEqualTo("http://#{foo}/#{bar}");
}
Aggregations