Search in sources :

Example 66 with RepoConfigOrigin

use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.

the class GoConfigServiceTest method shouldNotAllowEditOfConfigRepoPipelines.

@Test
public void shouldNotAllowEditOfConfigRepoPipelines() throws Exception {
    CruiseConfig cruiseConfig = mock(CruiseConfig.class);
    when(goConfigDao.load()).thenReturn(cruiseConfig);
    PipelineConfig pipeline = new PipelineConfig();
    pipeline.setName("pipeline1");
    pipeline.setOrigin(new RepoConfigOrigin());
    when(cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("pipeline1"))).thenReturn(pipeline);
    when(cruiseConfig.getGroups()).thenReturn(new GoConfigMother().cruiseConfigWithOnePipelineGroup().getGroups());
    when(cruiseConfig.isAdministrator("admin_user")).thenReturn(true);
    assertFalse(goConfigService.canEditPipeline("pipeline1", new Username("admin_user")));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.Test)

Example 67 with RepoConfigOrigin

use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.

the class PipelineConfigServiceTest method setUp.

@Before
public void setUp() throws Exception {
    PipelineConfigs configs = createGroup("group", "pipeline", "in_env");
    downstream(configs);
    cruiseConfig = new BasicCruiseConfig(configs);
    cruiseConfig.addEnvironment(environment("foo", "in_env"));
    PipelineConfig remotePipeline = PipelineConfigMother.pipelineConfig("remote");
    remotePipeline.setOrigin(new RepoConfigOrigin(new ConfigRepoConfig(new GitMaterialConfig("url"), "plugin"), "1234"));
    cruiseConfig.addPipeline("group", remotePipeline);
    goConfigService = mock(GoConfigService.class);
    securityService = mock(SecurityService.class);
    pluggableTaskService = mock(PluggableTaskService.class);
    when(goConfigService.getCurrentConfig()).thenReturn(cruiseConfig);
    when(goConfigService.cruiseConfig()).thenReturn(cruiseConfig);
    when(goConfigService.getConfigForEditing()).thenReturn(cruiseConfig);
    when(goConfigService.getMergedConfigForEditing()).thenReturn(cruiseConfig);
    when(goConfigService.getAllPipelineConfigs()).thenReturn(cruiseConfig.getAllPipelineConfigs());
    pipelineConfigService = new PipelineConfigService(goConfigService, securityService, pluggableTaskService, null);
}
Also used : ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) PluggableTaskService(com.thoughtworks.go.server.service.tasks.PluggableTaskService) Before(org.junit.Before)

Example 68 with RepoConfigOrigin

use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.

the class BuildCauseProducerServiceTest method manualTrigger_shouldUpdateJustPipelineConfigNotMaterialsWhenPipelineIsDefinedInConfigRepoAndMDUFlagIsTurnedOff.

@Test
public void manualTrigger_shouldUpdateJustPipelineConfigNotMaterialsWhenPipelineIsDefinedInConfigRepoAndMDUFlagIsTurnedOff() {
    HgMaterial material1 = new HgMaterial("url", null);
    HgMaterialConfig materialConfig1 = new HgMaterialConfig("url", null);
    HgMaterialConfig materialConfig2 = new HgMaterialConfig("url2", null);
    pipelineConfig.addMaterialConfig(materialConfig1);
    pipelineConfig.setOrigin(new RepoConfigOrigin(new ConfigRepoConfig(materialConfig2, "plug"), "revision1"));
    when(materialConfigConverter.toMaterial(materialConfig1)).thenReturn(material1);
    when(materialConfigConverter.toMaterial(materialConfig2)).thenReturn(new MaterialConfigConverter().toMaterial(materialConfig2));
    ScheduleOptions scheduleOptions = new ScheduleOptions(new HashMap<>(), new HashMap<>(), new HashMap<>());
    scheduleOptions.shouldPerformMDUBeforeScheduling(false);
    buildCauseProducerService.manualSchedulePipeline(Username.ANONYMOUS, pipelineConfig.name(), scheduleOptions, new ServerHealthStateOperationResult());
    verify(goConfigService, times(1)).pipelineConfigNamed(pipelineConfig.name());
    MaterialUpdateStatusListener statusListener = extractMaterialListenerInstanceFromRegisterCall();
    statusListener.onMaterialUpdate(new MaterialUpdateSuccessfulMessage(material1, 0));
    verify(mockMaterialUpdateStatusNotifier).registerListenerFor(eq(pipelineConfig), any(MaterialUpdateStatusListener.class));
    verify(goConfigService, times(1)).pipelineConfigNamed(pipelineConfig.name());
}
Also used : ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) Test(org.junit.Test)

Example 69 with RepoConfigOrigin

use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.

the class CachedGoPartialsTest method setUp.

@Before
public void setUp() throws Exception {
    serverHealthService = new ServerHealthService();
    partials = new CachedGoPartials(serverHealthService);
    configRepo1 = new ConfigRepoConfig(new GitMaterialConfig("url1"), "plugin");
    part1 = PartialConfigMother.withPipeline("p1", new RepoConfigOrigin(configRepo1, "1"));
    configRepo2 = new ConfigRepoConfig(new GitMaterialConfig("url2"), "plugin");
    part2 = PartialConfigMother.withPipeline("p2", new RepoConfigOrigin(configRepo2, "1"));
    partials.addOrUpdate(configRepo1.getMaterialConfig().getFingerprint(), part1);
    partials.addOrUpdate(configRepo2.getMaterialConfig().getFingerprint(), part2);
    fingerprintForRepo1 = ((RepoConfigOrigin) part1.getOrigin()).getMaterial().getFingerprint();
    fingerprintForRepo2 = ((RepoConfigOrigin) part2.getOrigin()).getMaterial().getFingerprint();
}
Also used : ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) Before(org.junit.Before)

Example 70 with RepoConfigOrigin

use of com.thoughtworks.go.config.remote.RepoConfigOrigin in project gocd by gocd.

the class GoFileConfigDataSourceTest method shouldFallbackToLastKnownValidPartialsForValidationWhenConfigSaveWithLastKnownPartialsWithMainConfigFails.

@Test
public void shouldFallbackToLastKnownValidPartialsForValidationWhenConfigSaveWithLastKnownPartialsWithMainConfigFails() {
    String pipelineOneFromConfigRepo = "pipeline_one_from_config_repo";
    String invalidPartial = "invalidPartial";
    final String pipelineInMain = "pipeline_in_main";
    PartialConfig validPartialConfig = PartialConfigMother.withPipeline(pipelineOneFromConfigRepo, new RepoConfigOrigin(repoConfig, "1"));
    PartialConfig invalidPartialConfig = PartialConfigMother.invalidPartial(invalidPartial, new RepoConfigOrigin(repoConfig, "2"));
    cachedGoPartials.addOrUpdate(repoConfig.getMaterialConfig().getFingerprint(), validPartialConfig);
    cachedGoPartials.markAllKnownAsValid();
    cachedGoPartials.addOrUpdate(repoConfig.getMaterialConfig().getFingerprint(), invalidPartialConfig);
    GoFileConfigDataSource.GoConfigSaveResult result = dataSource.writeWithLock(new UpdateConfigCommand() {

        @Override
        public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
            cruiseConfig.addPipeline("default", PipelineConfigMother.createPipelineConfig(pipelineInMain, "stage", "job"));
            return cruiseConfig;
        }
    }, new GoConfigHolder(configHelper.currentConfig(), configHelper.currentConfig()));
    assertThat(result.getConfigHolder().config.getAllPipelineNames().contains(new CaseInsensitiveString(invalidPartial)), is(false));
    assertThat(result.getConfigHolder().config.getAllPipelineNames().contains(new CaseInsensitiveString(pipelineOneFromConfigRepo)), is(true));
    assertThat(result.getConfigHolder().config.getAllPipelineNames().contains(new CaseInsensitiveString(pipelineInMain)), is(true));
    assertThat(cachedGoPartials.lastValidPartials().size(), is(1));
    PartialConfig partialConfig = cachedGoPartials.lastValidPartials().get(0);
    assertThat(partialConfig.getGroups(), is(validPartialConfig.getGroups()));
    assertThat(partialConfig.getEnvironments(), is(validPartialConfig.getEnvironments()));
    assertThat(partialConfig.getOrigin(), is(validPartialConfig.getOrigin()));
}
Also used : PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) StringContains.containsString(org.hamcrest.core.StringContains.containsString) ConfigFileHasChangedException(com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) ExpectedException(org.junit.rules.ExpectedException) ConfigMergeException(com.thoughtworks.go.config.exceptions.ConfigMergeException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)97 Test (org.junit.Test)74 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)34 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)29 FileConfigOrigin (com.thoughtworks.go.config.remote.FileConfigOrigin)23 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)15 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)13 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)11 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)11 ServerHealthStateOperationResult (com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult)11 StringContains.containsString (org.hamcrest.core.StringContains.containsString)11 File (java.io.File)9 IOException (java.io.IOException)8 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)8 ExpectedException (org.junit.rules.ExpectedException)8 Cloner (com.rits.cloning.Cloner)7 FullConfigUpdateCommand (com.thoughtworks.go.config.update.FullConfigUpdateCommand)7 Modification (com.thoughtworks.go.domain.materials.Modification)7 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)6 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)6