@Test public void shouldNotContinueWhenTemplateNoLongerExists() { when(goConfigService.isAuthorizedToEditTemplate("template", currentUser)).thenReturn(true); DeleteTemplateConfigCommand command = new DeleteTemplateConfigCommand( pipelineTemplateConfig, result, goConfigService, currentUser); assertThat(command.canContinue(cruiseConfig), is(false)); }
@Test public void shouldDeleteTemplateFromTheGivenConfig() throws Exception { cruiseConfig.addTemplate(pipelineTemplateConfig); DeleteTemplateConfigCommand command = new DeleteTemplateConfigCommand( pipelineTemplateConfig, result, goConfigService, currentUser); assertThat(cruiseConfig.getTemplates().contains(pipelineTemplateConfig), is(true)); command.update(cruiseConfig); assertThat(cruiseConfig.getTemplates().contains(pipelineTemplateConfig), is(false)); }
@Test public void shouldNotContinueWithConfigSaveIfUserIsUnauthorized() { when(goConfigService.isAuthorizedToEditTemplate("template", currentUser)).thenReturn(false); DeleteTemplateConfigCommand command = new DeleteTemplateConfigCommand( pipelineTemplateConfig, result, goConfigService, currentUser); assertThat(command.canContinue(cruiseConfig), is(false)); assertThat(result.toString(), containsString("UNAUTHORIZED_TO_EDIT")); }
@Test public void shouldContinueWithConfigSaveIfUserIsAuthorized() { cruiseConfig.addTemplate(pipelineTemplateConfig); when(goConfigService.isUserAdmin(currentUser)).thenReturn(true); DeleteTemplateConfigCommand command = new DeleteTemplateConfigCommand( pipelineTemplateConfig, result, goConfigService, currentUser); assertThat(command.canContinue(cruiseConfig), is(true)); }
@Test public void shouldValidateWhetherTemplateIsAssociatedWithPipelines() { new GoConfigMother() .addPipelineWithTemplate( cruiseConfig, "p1", pipelineTemplateConfig.name().toString(), "s1", "j1"); DeleteTemplateConfigCommand command = new DeleteTemplateConfigCommand( pipelineTemplateConfig, result, goConfigService, currentUser); thrown.expectMessage("The template 'template' is being referenced by pipeline(s): [p1]"); assertThat(command.isValid(cruiseConfig), is(false)); }