use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class StageServiceTest method shouldFindStageSummaryModelForGivenStageIdentifier.
@Test
public void shouldFindStageSummaryModelForGivenStageIdentifier() throws Exception {
SecurityService securityService = alwaysAllow();
TransactionSynchronizationManager transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
StageService service = new StageService(stageDao, null, null, null, securityService, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
Stage stageRun1 = StageMother.completedStageInstanceWithTwoPlans("stage_name");
stageRun1.setIdentifier(new StageIdentifier("pipeline_name/10/stage_name/1"));
stageRun1.setCounter(1);
Stage stageRun2 = StageMother.completedStageInstanceWithTwoPlans("stage_name");
stageRun2.setIdentifier(new StageIdentifier("pipeline_name/10/stage_name/2"));
stageRun2.setCounter(2);
Stages stages = new Stages(stageRun1, stageRun2);
StageIdentifier stageId = new StageIdentifier("pipeline_name/10/stage_name/2");
when(stageDao.getAllRunsOfStageForPipelineInstance(stageId.getPipelineName(), stageId.getPipelineCounter(), stageId.getStageName())).thenReturn(stages);
StageSummaryModel stageForView = service.findStageSummaryByIdentifier(stageId, ALWAYS_ALLOW_USER, new HttpLocalizedOperationResult());
assertThat(stageForView.getName(), is(stageRun2.getName()));
assertThat(stageForView.getState(), is(stageRun2.stageState()));
assertThat(stageForView.getStageCounter(), is(String.valueOf(stageRun2.getCounter())));
assertThat(stageForView.getTotalRuns(), is(2));
}
use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class StageServiceTest method findStageSummaryByIdentifierShouldRespondWith404WhenNoStagesFound.
@Test
public void findStageSummaryByIdentifierShouldRespondWith404WhenNoStagesFound() throws Exception {
SecurityService securityService = mock(SecurityService.class);
when(securityService.hasViewPermissionForPipeline(ALWAYS_ALLOW_USER, "pipeline_does_not_exist")).thenReturn(true);
TransactionSynchronizationManager transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
StageService service = new StageService(stageDao, null, null, null, securityService, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
StageIdentifier stageId = new StageIdentifier("pipeline_does_not_exist/10/stage_name/1");
when(stageDao.getAllRunsOfStageForPipelineInstance(stageId.getPipelineName(), stageId.getPipelineCounter(), stageId.getStageName())).thenReturn(new Stages());
StageSummaryModel model = service.findStageSummaryByIdentifier(stageId, ALWAYS_ALLOW_USER, result);
assertThat(result.httpCode(), is(404));
assertThat(model, is(nullValue()));
}
use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class UserServiceTest method shouldFailWithErrorWhenDeletingAnEnabledUserFails.
@Test
public void shouldFailWithErrorWhenDeletingAnEnabledUserFails() {
String username = "username";
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
when(userDao.deleteUser(username)).thenThrow(new UserEnabledException());
userService.deleteUser(username, result);
assertThat(result.isSuccessful(), is(false));
assertThat(result.hasMessage(), is(true));
}
use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class ServerConfigServiceTest method shouldSetMessageAsMergedWhenMergingServerConfigChanges.
@Test
public void shouldSetMessageAsMergedWhenMergingServerConfigChanges() {
GoConfigService goConfigService = mock(GoConfigService.class);
UserService userService = mock(UserService.class);
ServerConfigService serverConfigService = new ServerConfigService(goConfigService, userService);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
MailHost mailHost = new MailHost(new GoCipher());
when(goConfigService.updateServerConfig(mailHost, null, null, true, "md5", null, null, null, null, "http://site", "https://site", "location")).thenReturn(ConfigSaveState.MERGED);
serverConfigService.updateServerConfig(mailHost, null, null, null, null, null, null, true, "http://site", "https://site", "location", result, "md5");
assertThat(result.localizable(), Is.is(LocalizedMessage.composite(LocalizedMessage.string("SAVED_CONFIGURATION_SUCCESSFULLY"), LocalizedMessage.string("CONFIG_MERGED"))));
}
use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class PackageRepositoryService method savePackageRepositoryToConfig.
public ConfigUpdateAjaxResponse savePackageRepositoryToConfig(PackageRepository packageRepository, final String md5, Username username) {
performPluginValidationsFor(packageRepository);
UpdateConfigFromUI updateCommand = getPackageRepositoryUpdateCommand(packageRepository, username);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
ConfigUpdateResponse configUpdateResponse = goConfigService.updateConfigFromUI(updateCommand, md5, username, result);
if (result.isSuccessful()) {
ConfigUpdateAjaxResponse response = ConfigUpdateAjaxResponse.success(packageRepository.getId(), result.httpCode(), configUpdateResponse.wasMerged() ? localizer.localize("CONFIG_MERGED") : localizer.localize("SAVED_CONFIGURATION_SUCCESSFULLY"));
return response;
} else {
List<String> globalErrors = globalErrors(configUpdateResponse.getCruiseConfig().getAllErrorsExceptFor(configUpdateResponse.getSubject()));
HashMap<String, List<String>> fieldErrors = fieldErrors(configUpdateResponse.getSubject(), "package_repository");
String message = result.message(localizer);
ConfigUpdateAjaxResponse response = ConfigUpdateAjaxResponse.failure(packageRepository.getId(), result.httpCode(), message, fieldErrors, globalErrors);
return response;
}
}
Aggregations