Search in sources :

Example 81 with Username

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));
}
Also used : PipelineInstanceModels.createPipelineInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels.createPipelineInstanceModels) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 82 with Username

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)));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 83 with Username

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));
}
Also used : PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 84 with Username

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");
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 85 with Username

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));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Aggregations

Username (com.thoughtworks.go.server.domain.Username)391 Test (org.junit.Test)317 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)170 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)81 Before (org.junit.Before)42 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)36 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)33 Pipeline (com.thoughtworks.go.domain.Pipeline)30 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)27 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)21 StringContains.containsString (org.hamcrest.core.StringContains.containsString)20 Modification (com.thoughtworks.go.domain.materials.Modification)17 ArrayList (java.util.ArrayList)16 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)15 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)14 TimeProvider (com.thoughtworks.go.util.TimeProvider)13 UpdateConfigFromUI (com.thoughtworks.go.config.update.UpdateConfigFromUI)12 Date (java.util.Date)12 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)11 ConfigUpdateResponse (com.thoughtworks.go.config.update.ConfigUpdateResponse)10