Search in sources :

Example 76 with Username

use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.

the class PipelineHistoryServiceTest method shouldPopulateResultAsNotFoundWhenPipelineNotFound_loadMinimalData.

@Test
public void shouldPopulateResultAsNotFoundWhenPipelineNotFound_loadMinimalData() {
    String pipelineName = "unknown-pipeline";
    CruiseConfig cruiseConfig = mock(BasicCruiseConfig.class);
    when(cruiseConfig.hasPipelineNamed(new CaseInsensitiveString(pipelineName))).thenReturn(false);
    when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
    HttpOperationResult result = new HttpOperationResult();
    PipelineInstanceModels pipelineInstanceModels = pipelineHistoryService.loadMinimalData(pipelineName, Pagination.pageFor(0, 0, 10), new Username(new CaseInsensitiveString("looser")), result);
    assertThat(pipelineInstanceModels, is(nullValue()));
    assertThat(result.httpCode(), is(404));
    assertThat(result.detailedMessage(), is("Not Found { Pipeline " + pipelineName + " not found }\n"));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) PipelineInstanceModels.createPipelineInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels.createPipelineInstanceModels) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 77 with Username

use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.

the class PipelineHistoryServiceTest method shouldUnderstandLatestPipelineModel.

@Test
public void shouldUnderstandLatestPipelineModel() {
    Username username = new Username(new CaseInsensitiveString("loser"));
    String pipelineName = "junk";
    String groupName = "some-pipeline-group";
    PipelineInstanceModel pipeline = PipelineInstanceModel.createPipeline(pipelineName, -1, "1.0", BuildCause.createManualForced(), new StageInstanceModels());
    when(pipelineDao.loadHistory(pipelineName, 1, 0)).thenReturn(createPipelineInstanceModels(pipeline));
    when(schedulingCheckerService.canManuallyTrigger(pipelineName, username)).thenReturn(false);
    when(securityService.hasViewPermissionForPipeline(username, pipelineName)).thenReturn(true);
    when(securityService.hasOperatePermissionForPipeline(username.getUsername(), pipelineName)).thenReturn(true);
    when(goConfigService.isLockable(pipelineName)).thenReturn(true);
    when(goConfigService.findGroupNameByPipeline(new CaseInsensitiveString(pipelineName))).thenReturn(groupName);
    when(goConfigService.isUserAdminOfGroup(username.getUsername(), groupName)).thenReturn(true);
    when(pipelineLockService.isLocked(pipelineName)).thenReturn(true);
    stubConfigServiceToReturnPipeline(pipelineName, PipelineConfigMother.createPipelineConfig(pipelineName, "dev", "foo", "bar"));
    PipelineModel loadedPipeline = pipelineHistoryService.latestPipelineModel(username, pipelineName);
    assertThat(loadedPipeline.canForce(), is(false));
    assertThat(loadedPipeline.canOperate(), is(true));
    assertThat(loadedPipeline.getLatestPipelineInstance().isLockable(), is(true));
    assertThat(loadedPipeline.getLatestPipelineInstance().isCurrentlyLocked(), is(true));
    assertThat(loadedPipeline.getLatestPipelineInstance(), is(pipeline));
    assertThat(loadedPipeline.canAdminister(), is(true));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 78 with Username

use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.

the class PipelineHistoryServiceTest method allActivePipelines_shouldOnlyKeepSelectedPipelines_andRemove_EmptyGroups.

@Test
public void allActivePipelines_shouldOnlyKeepSelectedPipelines_andRemove_EmptyGroups() {
    Username foo = new Username(new CaseInsensitiveString("foo"));
    CruiseConfig cruiseConfig = ConfigMigrator.loadWithMigration(ConfigFileFixture.CONFIG).config;
    when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
    PipelineInstanceModels activePipelineInstances = createPipelineInstanceModels(activePipeline("pipeline1", 1, 1.0), activePipeline("pipeline2", 1, 1.0), activePipeline("pipeline4", 1, 1.0), activePipeline("non-operatable-pipeline", 1, 1.0));
    for (String pipeline : new String[] { "pipeline1", "pipeline2", "pipeline3", "pipeline4", "non-operatable-pipeline" }) {
        stubPermisssionsForActivePipeline(foo, cruiseConfig, pipeline, true, true);
        when(pipelineDao.loadHistory(pipeline, 1, 0)).thenReturn(createPipelineInstanceModels());
    }
    when(pipelineDao.loadActivePipelines()).thenReturn(activePipelineInstances);
    when(goConfigService.hasPipelineNamed(new CaseInsensitiveString(any(String.class)))).thenReturn(true);
    List<PipelineGroupModel> groups = pipelineHistoryService.allActivePipelineInstances(foo, new PipelineSelections(Arrays.asList("non-operatable-pipeline")));
    assertThat(groups.size(), is(1));
    assertThat(groups.get(0).getName(), is("defaultGroup"));
    assertThat(groups.get(0).containsPipeline("pipeline1"), is(true));
    assertThat(groups.get(0).containsPipeline("pipeline2"), is(true));
    assertThat(groups.get(0).containsPipeline("pipeline3"), is(true));
    assertThat(groups.get(0).containsPipeline("pipeline4"), is(true));
}
Also used : PipelineInstanceModels.createPipelineInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels.createPipelineInstanceModels) PipelineSelections(com.thoughtworks.go.server.domain.user.PipelineSelections) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 79 with Username

use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.

the class PipelineHistoryServiceTest method shouldFailWhenFeatureIsToggledOff_updateComment.

@Test
public void shouldFailWhenFeatureIsToggledOff_updateComment() {
    when(featureToggleService.isToggleOn(Toggles.PIPELINE_COMMENT_FEATURE_TOGGLE_KEY)).thenReturn(false);
    Toggles.initializeWith(featureToggleService);
    CaseInsensitiveString unauthorizedUser = new CaseInsensitiveString("cannot-access");
    String pipelineName = "pipeline_name";
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    pipelineHistoryService.updateComment(pipelineName, 1, "test comment", new Username(unauthorizedUser), result);
    assertThat(result.httpCode(), is(SC_NOT_IMPLEMENTED));
    assertThat(result.localizable(), is(LocalizedMessage.string("FEATURE_NOT_AVAILABLE", "Pipeline Comment")));
    verify(pipelineDao, never()).updateComment(pipelineName, 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 80 with Username

use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.

the class PipelineHistoryServiceTest method shouldLoadCanOperateAndLockableFlagForAllPipelines.

@Test
public void shouldLoadCanOperateAndLockableFlagForAllPipelines() {
    Username jez = new Username(new CaseInsensitiveString("jez"));
    CruiseConfig cruiseConfig = ConfigMigrator.loadWithMigration(ConfigFileFixture.CONFIG).config;
    PipelineConfig pipelineConfig = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("pipeline1"));
    pipelineConfig.setTrackingTool(new TrackingTool("http://link", "#"));
    pipelineConfig = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("pipeline2"));
    pipelineConfig.setMingleConfig(new MingleConfig("baseUrl", "id"));
    when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
    PipelineInstanceModels activePipelineInstances = createPipelineInstanceModels();
    StageInstanceModel stage1 = new StageInstanceModel("stage1", "2", JobHistory.withJob("plan1", JobState.Building, JobResult.Unknown, new Date()));
    activePipelineInstances.add(activePipeline("pipeline1", 10, 1.0, stage1, new NullStageHistoryItem("stage2", true)));
    activePipelineInstances.add(activePipeline("pipeline2", 5, 2.5, new StageInstanceModel("plan1", "2", JobHistory.withJob("plan1", JobState.Building, JobResult.Unknown, new Date()))));
    activePipelineInstances.add(activePipeline("non-operatable-pipeline", 5, 2.0, new StageInstanceModel("one", "2", JobHistory.withJob("plan1", JobState.Completed, JobResult.Failed, new Date()))));
    when(goConfigService.isLockable("pipeline1")).thenReturn(true);
    when(pipelineDao.loadActivePipelines()).thenReturn(activePipelineInstances);
    stubPermisssionsForActivePipeline(jez, cruiseConfig, "pipeline1", true, true);
    stubPermisssionsForActivePipeline(jez, cruiseConfig, "pipeline2", true, false);
    stubPermisssionsForActivePipeline(jez, cruiseConfig, "non-operatable-pipeline", false, false);
    when(goConfigService.hasPipelineNamed(new CaseInsensitiveString(any(String.class)))).thenReturn(true);
    when(securityService.hasOperatePermissionForStage("pipeline1", "stage1", CaseInsensitiveString.str(jez.getUsername()))).thenReturn(true);
    List<PipelineGroupModel> groups = pipelineHistoryService.allActivePipelineInstances(jez, PipelineSelections.ALL);
    PipelineModel secondPipelineModel = groups.get(0).getPipelineModels().get(1);
    assertPipelineIs(secondPipelineModel, "pipeline2", true, false);
    PipelineInstanceModel secondPim = secondPipelineModel.getLatestPipelineInstance();
    assertThat(secondPim.getTrackingTool(), is(nullValue()));
    assertThat(secondPim.getMingleConfig(), is(new MingleConfig("baseUrl", "id")));
    assertThat(secondPim.isLockable(), is(false));
    PipelineModel firstPipelineModel = groups.get(0).getPipelineModels().get(0);
    assertPipelineIs(firstPipelineModel, "pipeline1", true, true);
    PipelineInstanceModel pim = firstPipelineModel.getLatestPipelineInstance();
    assertThat(pim.isLockable(), is(true));
    assertThat(pim.getTrackingTool(), is(new TrackingTool("http://link", "#")));
    assertThat(pim.getMingleConfig(), is(new MingleConfig()));
    PipelineModel nonOperatablePipelineModel = groups.get(1).getPipelineModels().get(0);
    assertPipelineIs(nonOperatablePipelineModel, "non-operatable-pipeline", false, false);
}
Also used : PipelineInstanceModels.createPipelineInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels.createPipelineInstanceModels) 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