Search in sources :

Example 91 with HttpOperationResult

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

Example 92 with HttpOperationResult

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

Example 93 with HttpOperationResult

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

Example 94 with HttpOperationResult

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

Example 95 with HttpOperationResult

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));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) Test(org.junit.Test)

Aggregations

HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)146 Test (org.junit.jupiter.api.Test)64 Test (org.junit.Test)53 Username (com.thoughtworks.go.server.domain.Username)34 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)23 TriStateSelection (com.thoughtworks.go.presentation.TriStateSelection)12 Pagination (com.thoughtworks.go.server.util.Pagination)7 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)6 StageStatusCache (com.thoughtworks.go.domain.activity.StageStatusCache)6 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)6 StageStatusTopic (com.thoughtworks.go.server.messaging.StageStatusTopic)6 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)5 AgentInstance (com.thoughtworks.go.domain.AgentInstance)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)4 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)4 NullStage (com.thoughtworks.go.domain.NullStage)4 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)4 PipelineStatusModel (com.thoughtworks.go.presentation.PipelineStatusModel)4 Stage (com.thoughtworks.go.domain.Stage)3