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