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"));
}
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));
}
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));
}
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");
}
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);
}
Aggregations