use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class PipelineHistoryServiceTest method shouldReturn404WhenPipelineInstanceIsNotPresent.
@Test
public void shouldReturn404WhenPipelineInstanceIsNotPresent() throws Exception {
when(pipelineDao.pipelineGraphByNameAndCounter("blahPipeline", 12)).thenReturn(null);
ensureConfigHasPipeline("blahPipeline");
ensureHasPermission(USERNAME, "blahPipeline");
HttpOperationResult result = new HttpOperationResult();
pipelineHistoryService.pipelineDependencyGraph("blahPipeline", 12, USERNAME, result);
assertThat(result.canContinue(), is(false));
assertThat(result.httpCode(), is(404));
assertThat(result.message(), is("Pipeline [blahPipeline] with counter [12] is not found"));
}
use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class PipelineHistoryServiceTest method shouldSetStageRunAndOperatePermissionsInTheDependencyGraphForTheDependentPipelinesOfAPipelineInstance.
@Test
public void shouldSetStageRunAndOperatePermissionsInTheDependencyGraphForTheDependentPipelinesOfAPipelineInstance() throws Exception {
PipelineInstanceModel down1Pim = pim("down1");
down1Pim.getStageHistory().add(new StageInstanceModel("stage", "1", new JobHistory()));
PipelineInstanceModel actualPim = pim("blahPipeline");
actualPim.setId(23);
PipelineDependencyGraphOld returned = new PipelineDependencyGraphOld(actualPim, createPipelineInstanceModels(down1Pim));
when(pipelineDao.pipelineGraphByNameAndCounter("blahPipeline", 12)).thenReturn(returned);
ensureConfigHasPipeline("blahPipeline");
ensureHasPermission(USERNAME, "blahPipeline");
ensureConfigHasPipeline("down1");
ensureHasPermission(USERNAME, "down1");
when(goConfigService.downstreamPipelinesOf("blahPipeline")).thenReturn(Arrays.asList(PipelineConfigMother.pipelineConfig("down1")));
stubConfigServiceToReturnPipeline("blahPipeline", PipelineConfigMother.pipelineConfig("blahPipeline"));
stubConfigServiceToReturnPipeline("down1", PipelineConfigMother.pipelineConfig("down1"));
when(scheduleService.canRun(down1Pim.getPipelineIdentifier(), down1Pim.getStageHistory().first().getName(), CaseInsensitiveString.str(USERNAME.getUsername()), true)).thenReturn(true);
when(securityService.hasOperatePermissionForStage("down1", "stage", CaseInsensitiveString.str(USERNAME.getUsername()))).thenReturn(true);
when(pipelineTimeline.pipelineBefore(23)).thenReturn(-1L);
PipelineDependencyGraphOld actual = pipelineHistoryService.pipelineDependencyGraph("blahPipeline", 12, USERNAME, new HttpOperationResult());
StageInstanceModel firstStageOfDown1 = actual.dependencies().get(0).getStageHistory().get(0);
assertThat(actual.dependencies().size(), is(1));
assertThat(firstStageOfDown1.hasOperatePermission(), is(true));
assertThat(firstStageOfDown1.getCanRun(), is(true));
}
use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class PipelineHistoryServiceTest method shouldSetStageRunAndOperatePermissionsInTheDependencyGraph.
@Test
public void shouldSetStageRunAndOperatePermissionsInTheDependencyGraph() throws Exception {
PipelineInstanceModel pim = pim("blahPipeline");
pim.setId(23);
pim.getStageHistory().add(new StageInstanceModel("stage", "1", new JobHistory()));
PipelineDependencyGraphOld expected = new PipelineDependencyGraphOld(pim, createPipelineInstanceModels());
when(pipelineDao.pipelineGraphByNameAndCounter("blahPipeline", 12)).thenReturn(expected);
ensureConfigHasPipeline("blahPipeline");
when(goConfigService.downstreamPipelinesOf("blahPipeline")).thenReturn(new ArrayList<>());
stubConfigServiceToReturnPipeline("blahPipeline", PipelineConfigMother.pipelineConfig("blahPipeline"));
when(scheduleService.canRun(pim.getPipelineIdentifier(), "stage", CaseInsensitiveString.str(USERNAME.getUsername()), true)).thenReturn(true);
when(securityService.hasOperatePermissionForStage("blahPipeline", "stage", CaseInsensitiveString.str(USERNAME.getUsername()))).thenReturn(true);
when(pipelineTimeline.pipelineBefore(23)).thenReturn(-1L);
ensureHasPermission(USERNAME, "blahPipeline");
PipelineDependencyGraphOld actual = pipelineHistoryService.pipelineDependencyGraph("blahPipeline", 12, USERNAME, new HttpOperationResult());
assertThat(actual.pipeline().getStageHistory().size(), is(1));
assertThat(actual.pipeline().getStageHistory().get(0).getCanRun(), is(true));
assertThat(actual.pipeline().getStageHistory().get(0).hasOperatePermission(), is(true));
}
use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class PipelineHistoryServiceTest method shouldReturnDependencyGraphOnlyIfUserHasPermissions.
@Test
public void shouldReturnDependencyGraphOnlyIfUserHasPermissions() throws Exception {
PipelineInstanceModel instanceModel = pim("blahPipeline");
instanceModel.setId(12);
PipelineDependencyGraphOld expected = new PipelineDependencyGraphOld(instanceModel, createPipelineInstanceModels());
when(pipelineDao.pipelineGraphByNameAndCounter("blahPipeline", 12)).thenReturn(expected);
ensureConfigHasPipeline("blahPipeline");
when(goConfigService.downstreamPipelinesOf("blahPipeline")).thenReturn(new ArrayList<>());
stubConfigServiceToReturnPipeline("blahPipeline", PipelineConfigMother.pipelineConfig("blahPipeline"));
when(pipelineTimeline.pipelineBefore(12)).thenReturn(1L);
when(pipelineDao.loadHistory(1)).thenReturn(new PipelineInstanceModel("blahPipeline", 21, "prev-label", BuildCause.createWithEmptyModifications(), new StageInstanceModels()));
Username foo = new Username(new CaseInsensitiveString("foo"));
ensureHasPermission(USERNAME, "blahPipeline");
assertThat(pipelineHistoryService.pipelineDependencyGraph("blahPipeline", 12, foo, new HttpOperationResult()), is(nullValue()));
assertThat(pipelineHistoryService.pipelineDependencyGraph("blahPipeline", 12, USERNAME, new HttpOperationResult()), is(expected));
}
use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class PipelineHistoryServiceTest method shouldAddOtherDependentPipelinePresentInConfig.
@Test
public void shouldAddOtherDependentPipelinePresentInConfig() throws Exception {
ensureConfigHasPipeline("blahPipeline");
ensureConfigHasPipeline("down1");
ensureConfigHasPipeline("noPermission");
PipelineConfig other = GoConfigMother.createPipelineConfigWithMaterialConfig("other");
other.add(new StageConfig(new CaseInsensitiveString("badChildhood"), new JobConfigs()));
when(pipelineUnlockService.canUnlock(eq("blahPipeline"), eq(USERNAME), any(HttpOperationResult.class))).thenReturn(true);
when(goConfigService.isLockable("blahPipeline")).thenReturn(true);
when(goConfigService.downstreamPipelinesOf("blahPipeline")).thenReturn(Arrays.asList(other));
stubConfigServiceToReturnPipeline("blahPipeline", PipelineConfigMother.pipelineConfig("blahPipeline", new StageConfig(new CaseInsensitiveString("first"), new JobConfigs())));
ensureHasPermission(USERNAME, "blahPipeline");
SvnMaterialConfig svnMaterialConfig = MaterialConfigsMother.svnMaterialConfig();
svnMaterialConfig.setName(null);
stubConfigServiceToReturnMaterialAndPipeline("down1", new MaterialConfigs(svnMaterialConfig), PipelineConfigMother.pipelineConfig("down1", new StageConfig(new CaseInsensitiveString("first"), new JobConfigs())));
ensureHasPermission(USERNAME, "down1");
stubConfigServiceToReturnMaterialAndPipeline("other", new MaterialConfigs(), other);
when(pipelineTimeline.pipelineBefore(23)).thenReturn(-1L);
PipelineInstanceModel actualPim = pim("down1");
PipelineInstanceModel noPermission = pim("noPermission");
PipelineInstanceModel returned = pim("blahPipeline");
returned.setId(23);
PipelineDependencyGraphOld graph = new PipelineDependencyGraphOld(returned, createPipelineInstanceModels(actualPim, noPermission));
when(pipelineDao.pipelineGraphByNameAndCounter("blahPipeline", 12)).thenReturn(graph);
PipelineDependencyGraphOld actual = pipelineHistoryService.pipelineDependencyGraph("blahPipeline", 12, USERNAME, new HttpOperationResult());
assertThat(actual.pipeline().isLockable(), is(true));
assertThat(actual.pipeline().canUnlock(), is(true));
assertThat(actual.dependencies().size(), is(2));
assertThat(actual.dependencies().get(0), is(actualPim));
assertHasMaterial(actualPim, MaterialsMother.svnMaterial().config());
PipelineInstanceModel otherInstance = actual.dependencies().get(1);
assertThat(otherInstance.getName(), is("other"));
assertThat(otherInstance.getMaterials().size(), is(0));
}
Aggregations