Search in sources :

Example 66 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.

the class GoDashboardServiceTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    configMother = new GoConfigMother();
    config = GoConfigMother.defaultCruiseConfig();
    Toggles.initializeWith(featureToggleService);
    lenient().when(cache.allEntries()).thenReturn(this.pipelines);
    service = new GoDashboardService(cache, dashboardCurrentStateLoader, permissionsAuthority, goConfigService);
    GoConfigMother.addUserAsSuperAdmin(config, "superduper");
    configMother.addRoleAsSuperAdmin(config, "supers");
}
Also used : GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 67 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.

the class GoDashboardServiceTest method shouldRemoveExistingPipelineEntryInCacheWhenPipelineIsRemoved.

@Test
public void shouldRemoveExistingPipelineEntryInCacheWhenPipelineIsRemoved() {
    BasicCruiseConfig config = GoConfigMother.defaultCruiseConfig();
    PipelineConfig pipelineConfig = new GoConfigMother().addPipeline(config, "pipeline1", "stage1", "job1");
    config.findGroupOfPipeline(pipelineConfig).remove(pipelineConfig);
    when(goConfigService.findGroupByPipeline(any())).thenReturn(null);
    // simulate the event
    service.updateCacheForPipeline(pipelineConfig.name());
    verify(cache).remove(pipelineConfig.getName());
    verify(dashboardCurrentStateLoader).clearEntryFor(pipelineConfig.getName());
    verifyNoMoreInteractions(dashboardCurrentStateLoader);
}
Also used : GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.jupiter.api.Test)

Example 68 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.

the class GoConfigServiceTest method shouldNotBeAbleToEditPipelineIfUserDoesNotHaveSufficientPermissions.

@Test
public void shouldNotBeAbleToEditPipelineIfUserDoesNotHaveSufficientPermissions() throws Exception {
    CruiseConfig cruiseConfig = mock(CruiseConfig.class);
    PipelineConfig pipeline = new PipelineConfig();
    pipeline.setName("pipeline1");
    when(goConfigDao.load()).thenReturn(cruiseConfig);
    when(cruiseConfig.isSecurityEnabled()).thenReturn(true);
    when(cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("pipeline1"))).thenReturn(pipeline);
    BasicCruiseConfig basicCruiseConfig = new GoConfigMother().cruiseConfigWithOnePipelineGroup();
    when(cruiseConfig.getGroups()).thenReturn(basicCruiseConfig.getGroups());
    when(cruiseConfig.findGroup("group1")).thenReturn(mock(PipelineConfigs.class));
    when(cruiseConfig.isAdministrator("view_user")).thenReturn(false);
    when(cruiseConfig.server()).thenReturn(new ServerConfig());
    assertFalse(goConfigService.canEditPipeline("pipeline1", new Username("view_user")));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.jupiter.api.Test)

Example 69 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother 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.jupiter.api.Test)

Example 70 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.

the class GoConfigServiceTest method shouldReturnSecretConfigBySecretConfigId.

@Test
public void shouldReturnSecretConfigBySecretConfigId() throws Exception {
    Rules rules = new Rules(new Allow("refer", "pipeline_group", "default"));
    SecretConfig secretConfig = new SecretConfig("secret_config_id", "plugin_id", rules);
    GoConfigMother configMother = new GoConfigMother();
    CruiseConfig config = GoConfigMother.configWithSecretConfig(secretConfig);
    configMother.addPipelineWithGroup(config, "default", "pipeline1", "stage1", "job1");
    expectLoad(config);
    assertThat(goConfigService.getSecretConfigById("secret_config_id"), is(secretConfig));
}
Also used : Rules(com.thoughtworks.go.config.rules.Rules) Allow(com.thoughtworks.go.config.rules.Allow) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.jupiter.api.Test)

Aggregations

GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)102 Test (org.junit.jupiter.api.Test)64 Username (com.thoughtworks.go.server.domain.Username)30 BeforeEach (org.junit.jupiter.api.BeforeEach)19 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)15 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)13 GoConfigValidity (com.thoughtworks.go.config.validation.GoConfigValidity)12 File (java.io.File)9 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)8 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 SCM (com.thoughtworks.go.domain.scm.SCM)4 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)3 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)3 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)3 FullConfigUpdateCommand (com.thoughtworks.go.config.update.FullConfigUpdateCommand)3 Configuration (com.thoughtworks.go.domain.config.Configuration)3 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)3