Search in sources :

Example 6 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 7 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 8 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 9 with FullConfigUpdateCommand

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()));
}
Also used : ConfigElementImplementationRegistry(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry) FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) ConfigElementImplementationRegistrar(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistrar) NoPluginsInstalled(com.thoughtworks.go.config.registry.NoPluginsInstalled)

Example 10 with FullConfigUpdateCommand

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}");
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) 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