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 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 findStageSummaryByIdentifierShouldRespondWith401WhenUserDoesNotHavePermissionToViewThePipeline.
@Test
public void findStageSummaryByIdentifierShouldRespondWith401WhenUserDoesNotHavePermissionToViewThePipeline() throws Exception {
SecurityService securityService = mock(SecurityService.class);
when(securityService.hasViewPermissionForPipeline(ALWAYS_ALLOW_USER, "pipeline_name")).thenReturn(false);
TransactionSynchronizationManager transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
StageService service = new StageService(stageDao, null, null, null, securityService, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
StageSummaryModel model = service.findStageSummaryByIdentifier(new StageIdentifier("pipeline_name/10/stage_name/1"), ALWAYS_ALLOW_USER, result);
assertThat(result.httpCode(), is(401));
assertThat(model, is(nullValue()));
}
use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class UserSearchServiceTest method shouldReturnWarningMessageWhenSearchReturnsNoResults.
@Test
public void shouldReturnWarningMessageWhenSearchReturnsNoResults() throws Exception {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
userSearchService.search("foo", result);
assertThat(result.localizable(), is(LocalizedMessage.string("NO_SEARCH_RESULTS_ERROR")));
}
use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class UserSearchServiceTest method shouldNotInvokeSearchWhenUserSearchTextIsTooSmall.
@Test
public void shouldNotInvokeSearchWhenUserSearchTextIsTooSmall() throws Exception {
String smallSearchText = "f";
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
userSearchService.search(smallSearchText, result);
verifyZeroInteractions(authorizationExtension);
assertThat(result.localizable(), is(LocalizedMessage.string("SEARCH_STRING_TOO_SMALL")));
}
Aggregations