use of com.thoughtworks.go.config.update.UpdateConfigFromUI in project gocd by gocd.
the class PackageRepositoryServiceTest method shouldCheckIfUserCanAccessAdminPagesWhileUpdatingPackageRepository.
@Test
public void shouldCheckIfUserCanAccessAdminPagesWhileUpdatingPackageRepository() throws Exception {
Username username = new Username(new CaseInsensitiveString("user"));
when(securityService.canViewAdminPage(username)).thenReturn(false);
UpdateConfigFromUI updateCommand = service.getPackageRepositoryUpdateCommand(new PackageRepository(), username);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
updateCommand.checkPermission(GoConfigMother.configWithPipelines("sample"), result);
assertThat(result.isSuccessful(), is(false));
assertThat(result.httpCode(), is(401));
verify(securityService).canViewAdminPage(username);
}
use of com.thoughtworks.go.config.update.UpdateConfigFromUI in project gocd by gocd.
the class GoConfigServiceIntegrationTest method shouldRespondWithNewConfigWhenSavedSuccessfully.
@Test
public void shouldRespondWithNewConfigWhenSavedSuccessfully() {
configHelper.addPipeline("pipeline", "stage");
String md5 = goConfigService.getConfigForEditing().getMd5();
UpdateConfigFromUI pipelineAndStageRename = new PipelineStageRenamingCommand();
ConfigUpdateResponse response = goConfigService.updateConfigFromUI(pipelineAndStageRename, md5, Username.ANONYMOUS, new HttpLocalizedOperationResult());
PipelineConfig pipeline = goConfigService.getConfigForEditing().pipelineConfigByName(new CaseInsensitiveString("new-pipeline"));
StageConfig stage = pipeline.getStage(new CaseInsensitiveString("new-stage"));
assertThat(pipeline, not(nullValue()));
assertThat(stage, not(nullValue()));
assertThat(((PipelineConfig) response.getNode()).name(), is(new CaseInsensitiveString("new-pipeline")));
assertThat(((StageConfig) response.getSubject()).name(), is(new CaseInsensitiveString("new-stage")));
assertThat(response.configAfterUpdate().hasStageConfigNamed(new CaseInsensitiveString("new-pipeline"), new CaseInsensitiveString("new-stage"), false), is(true));
}
use of com.thoughtworks.go.config.update.UpdateConfigFromUI in project gocd by gocd.
the class GoConfigServiceIntegrationTest method shouldRespondWithModifiedConfigWhenSaveFailsBecauseOfValidationErrors.
@Test
public void shouldRespondWithModifiedConfigWhenSaveFailsBecauseOfValidationErrors() {
configHelper.addPipeline("pipeline", "stage");
String md5 = goConfigService.getConfigForEditing().getMd5();
UpdateConfigFromUI pipelineAndStageRename = new PipelineStageRenamingCommand() {
{
newPipelineName = "pipeline!@foo - bar";
}
};
ConfigUpdateResponse response = goConfigService.updateConfigFromUI(pipelineAndStageRename, md5, Username.ANONYMOUS, new HttpLocalizedOperationResult());
assertThat(goConfigService.getConfigForEditing().hasPipelineNamed(new CaseInsensitiveString("pipeline!@foo - bar")), is(false));
assertThat(goConfigService.getConfigForEditing().hasPipelineNamed(new CaseInsensitiveString("pipeline")), is(true));
assertThat(((PipelineConfig) response.getNode()).name(), is(new CaseInsensitiveString("pipeline!@foo - bar")));
assertThat(((StageConfig) response.getSubject()).name(), is(new CaseInsensitiveString("new-stage")));
assertThat(response.configAfterUpdate().hasStageConfigNamed(new CaseInsensitiveString("pipeline!@foo - bar"), new CaseInsensitiveString("new-stage"), false), is(false));
}
use of com.thoughtworks.go.config.update.UpdateConfigFromUI in project gocd by gocd.
the class PackageRepositoryServiceTest method shouldSavePackageRepositoryAndReturnSuccess.
@Test
public void shouldSavePackageRepositoryAndReturnSuccess() throws Exception {
service = spy(service);
PackageRepository packageRepository = new PackageRepository();
packageRepository.setId("repoid");
Username username = new Username(new CaseInsensitiveString("user"));
UpdateConfigFromUI updateConfigFromUI = mock(UpdateConfigFromUI.class);
doNothing().when(service).performPluginValidationsFor(packageRepository);
doReturn(updateConfigFromUI).when(service).getPackageRepositoryUpdateCommand(packageRepository, username);
when(goConfigService.updateConfigFromUI(eq(updateConfigFromUI), eq("md5"), eq(username), any(LocalizedOperationResult.class))).then(new Answer<ConfigUpdateResponse>() {
@Override
public ConfigUpdateResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
return new ConfigUpdateResponse(null, null, null, mock(ConfigAwareUpdate.class), ConfigSaveState.UPDATED);
}
});
when(localizer.localize("SAVED_CONFIGURATION_SUCCESSFULLY")).thenReturn("SAVED_CONFIGURATION_SUCCESSFULLY");
ConfigUpdateAjaxResponse response = service.savePackageRepositoryToConfig(packageRepository, "md5", username);
assertThat(response.isSuccessful(), is(true));
assertThat(response.getMessage(), is("SAVED_CONFIGURATION_SUCCESSFULLY"));
assertThat(response.getSubjectIdentifier(), is("repoid"));
assertThat(response.getStatusCode(), is(HttpStatus.SC_OK));
verify(service).performPluginValidationsFor(packageRepository);
verify(service).getPackageRepositoryUpdateCommand(packageRepository, username);
}
use of com.thoughtworks.go.config.update.UpdateConfigFromUI in project gocd by gocd.
the class PackageRepositoryServiceTest method shouldValidateUpdateCommandForPackageRepository.
@Test
public void shouldValidateUpdateCommandForPackageRepository() throws Exception {
Username username = new Username(new CaseInsensitiveString("user"));
Validatable packageRepository = new PackageRepository();
((PackageRepository) packageRepository).setId("id");
Validatable cruiseConfig = GoConfigMother.configWithPipelines("sample");
((CruiseConfig) cruiseConfig).getPackageRepositories().add((PackageRepository) packageRepository);
UpdateConfigFromUI updateCommand = service.getPackageRepositoryUpdateCommand((PackageRepository) packageRepository, username);
assertThat(updateCommand.node((CruiseConfig) cruiseConfig), is(cruiseConfig));
assertThat(updateCommand.updatedNode((CruiseConfig) cruiseConfig), is(cruiseConfig));
assertThat(updateCommand.subject(cruiseConfig), is(packageRepository));
assertThat(updateCommand.updatedSubject(cruiseConfig), is(packageRepository));
}
Aggregations