use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class PipelineHistoryServiceTest method shouldLoadCurrentlyLockedStatusFlagForAllPipelines.
@Test
public void shouldLoadCurrentlyLockedStatusFlagForAllPipelines() {
Username foo = new Username(new CaseInsensitiveString("foo"));
CruiseConfig cruiseConfig = ConfigMigrator.loadWithMigration(ConfigFileFixture.CONFIG).config;
when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
PipelineInstanceModels activePipelineInstances = createPipelineInstanceModels();
PipelineInstanceModel pipeline1 = activePipeline("pipeline1", 9, 2.0, new StageInstanceModel("stage1", "3", StageResult.Failed, new StageIdentifier()), new StageInstanceModel("stage2", "4", JobHistory.withJob("plan1", JobState.Building, JobResult.Unknown, new Date())));
PipelineInstanceModel pipeline2 = activePipeline("pipeline2", 5, 2.5, new StageInstanceModel("plan1", "2", JobHistory.withJob("plan1", JobState.Building, JobResult.Unknown, new Date())));
PipelineInstanceModel pipeline3 = activePipeline("pipeline3", 5, 2.5, new StageInstanceModel("plan1", "2", JobHistory.withJob("plan1", JobState.Building, JobResult.Unknown, new Date())));
activePipelineInstances.add(pipeline1);
activePipelineInstances.add(pipeline2);
activePipelineInstances.add(pipeline3);
when(pipelineDao.loadActivePipelines()).thenReturn(activePipelineInstances);
stubPermisssionsForActivePipeline(foo, cruiseConfig, "pipeline1", true, true);
stubPermisssionsForActivePipeline(foo, cruiseConfig, "pipeline2", true, true);
stubPermisssionsForActivePipeline(foo, cruiseConfig, "pipeline3", true, true);
when(goConfigService.hasPipelineNamed(new CaseInsensitiveString(any(String.class)))).thenReturn(true);
when(goConfigService.isLockable("pipeline1")).thenReturn(true);
when(goConfigService.isLockable("pipeline2")).thenReturn(true);
when(pipelineLockService.isLocked("pipeline1")).thenReturn(true);
List<PipelineGroupModel> groups = pipelineHistoryService.allActivePipelineInstances(foo, PipelineSelections.ALL);
PipelineGroupModel group = groups.get(0);
PipelineModel pipelineModel1 = group.getPipelineModels().get(0);
PipelineInstanceModel firstPipelinePIM = pipelineModel1.getActivePipelineInstances().get(0);
assertThat(firstPipelinePIM.isLockable(), is(true));
assertThat(firstPipelinePIM.isCurrentlyLocked(), is(true));
PipelineModel pipelineModel2 = group.getPipelineModels().get(1);
PipelineInstanceModel secondPipeline = pipelineModel2.getActivePipelineInstances().get(0);
assertThat(secondPipeline.isLockable(), is(true));
assertThat(secondPipeline.isCurrentlyLocked(), is(false));
PipelineModel pipelineModel3 = group.getPipelineModels().get(2);
PipelineInstanceModel thirdPipeline = pipelineModel3.getActivePipelineInstances().get(0);
assertThat(thirdPipeline.isLockable(), is(false));
assertThat(thirdPipeline.isCurrentlyLocked(), is(false));
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class PipelineHistoryServiceTest method shouldNotUpdateCommentWhenUserIsUnauthorized.
@Test
public void shouldNotUpdateCommentWhenUserIsUnauthorized() {
CaseInsensitiveString unauthorizedUser = new CaseInsensitiveString("cannot-access");
String pipelineName = "pipeline_name";
when(securityService.hasOperatePermissionForPipeline(unauthorizedUser, pipelineName)).thenReturn(false);
HttpLocalizedOperationResult result = mock(HttpLocalizedOperationResult.class);
pipelineHistoryService.updateComment(pipelineName, 1, "test comment", new Username(unauthorizedUser), result);
verify(pipelineDao, never()).updateComment(pipelineName, 1, "test comment");
verify(result, times(1)).unauthorized(LocalizedMessage.cannotOperatePipeline(pipelineName), HealthStateType.general(HealthStateScope.forPipeline(pipelineName)));
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class PipelineHistoryServiceTest method allActivePipelines_shouldRemove_EmptyGroups.
@Test
public void allActivePipelines_shouldRemove_EmptyGroups() {
Username bar = new Username(new CaseInsensitiveString("non-existant"));
CruiseConfig cruiseConfig = ConfigMigrator.loadWithMigration(ConfigFileFixture.CONFIG).config;
when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
when(pipelineDao.loadActivePipelines()).thenReturn(createPipelineInstanceModels());
when(goConfigService.hasPipelineNamed(new CaseInsensitiveString(any(String.class)))).thenReturn(true);
List<PipelineGroupModel> groups = pipelineHistoryService.allActivePipelineInstances(bar, new PipelineSelections());
assertThat(groups.isEmpty(), is(true));
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class PipelineHistoryServiceTest method shouldUpdateCommentUsingPipelineDao.
@Test
public void shouldUpdateCommentUsingPipelineDao() {
CaseInsensitiveString authorizedUser = new CaseInsensitiveString("can-access");
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
when(securityService.hasOperatePermissionForPipeline(authorizedUser, "pipeline_name")).thenReturn(true);
pipelineHistoryService.updateComment("pipeline_name", 1, "test comment", new Username(authorizedUser), result);
verify(pipelineDao, times(1)).updateComment("pipeline_name", 1, "test comment");
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class PipelineHistoryServiceTest method getActivePipelineInstance_shouldRemoveEmptyGroups.
@Test
public void getActivePipelineInstance_shouldRemoveEmptyGroups() {
Username foo = new Username(new CaseInsensitiveString("foo"));
CruiseConfig cruiseConfig = ConfigMigrator.loadWithMigration(ConfigFileFixture.CONFIG).config;
when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
when(pipelineDao.loadActivePipelines()).thenReturn(createPipelineInstanceModels());
when(goConfigService.hasPipelineNamed(new CaseInsensitiveString(any(String.class)))).thenReturn(true);
List<PipelineGroupModel> groups = pipelineHistoryService.getActivePipelineInstance(foo, "pipeline1");
assertThat(groups.isEmpty(), is(true));
}
Aggregations