Search in sources :

Example 21 with StageIdentifier

use of com.thoughtworks.go.domain.StageIdentifier in project gocd by gocd.

the class PipelineLockServiceTest method shouldAllowStageFromAnotherPipelineIfThePipelineIsNotLockabler.

@Test
public void shouldAllowStageFromAnotherPipelineIfThePipelineIsNotLockabler() throws Exception {
    Pipeline pipeline = PipelineMother.firstStageBuildingAndSecondStageScheduled("mingle", asList("dev", "ft"), asList("test"));
    when(pipelineStateDao.pipelineStateFor("mingle")).thenReturn(new PipelineState(pipeline.getName(), new StageIdentifier(pipeline.getName(), 9999, "1.2.9999", "stage", "1")));
    when(goConfigService.isLockable(pipeline.getName())).thenReturn(false);
    pipelineLockService.lockIfNeeded(pipeline);
    assertThat(pipelineLockService.canScheduleStageInPipeline(pipeline.getIdentifier()), is(true));
}
Also used : PipelineState(com.thoughtworks.go.domain.PipelineState) StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.Test)

Example 22 with StageIdentifier

use of com.thoughtworks.go.domain.StageIdentifier in project gocd by gocd.

the class PipelineLockServiceTest method shouldKnowIfPipelineIsLocked.

@Test
public void shouldKnowIfPipelineIsLocked() throws Exception {
    String pipelineName = "mingle";
    PipelineState pipelineState = new PipelineState(pipelineName, new StageIdentifier(pipelineName, 1, "1", "stage", "1"));
    pipelineState.lock(1);
    when(pipelineStateDao.pipelineStateFor(pipelineName)).thenReturn(pipelineState);
    assertThat(pipelineLockService.isLocked(pipelineName), is(true));
    assertThat(pipelineLockService.isLocked("twist"), is(false));
}
Also used : PipelineState(com.thoughtworks.go.domain.PipelineState) StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) Test(org.junit.Test)

Example 23 with StageIdentifier

use of com.thoughtworks.go.domain.StageIdentifier in project gocd by gocd.

the class PipelineUnlockApiServiceTest method unlockShouldSetResultToNotAcceptableWhenAPipelineInstanceIsCurrentlyRunning.

@Test
public void unlockShouldSetResultToNotAcceptableWhenAPipelineInstanceIsCurrentlyRunning() throws Exception {
    when(securityService.hasOperatePermissionForPipeline(new CaseInsensitiveString("username"), "pipeline-name")).thenReturn(true);
    when(goConfigService.hasPipelineNamed(new CaseInsensitiveString("pipeline-name"))).thenReturn(true);
    when(goConfigService.isLockable("pipeline-name")).thenReturn(true);
    StageIdentifier identifier = new StageIdentifier("pipeline-name", 10, "10", "stage", "1");
    when(pipelineLockService.lockedPipeline("pipeline-name")).thenReturn(identifier);
    when(currentActivityService.isAnyStageActive(identifier.pipelineIdentifier())).thenReturn(true);
    HttpOperationResult result = new HttpOperationResult();
    pipelineUnlockApiService.unlock("pipeline-name", new Username(new CaseInsensitiveString("username")), result);
    assertThat(result.httpCode(), is(409));
    assertThat(result.message(), is("Locked pipeline instance is currently running (one of the stages is in progress)"));
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Username(com.thoughtworks.go.server.domain.Username) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 24 with StageIdentifier

use of com.thoughtworks.go.domain.StageIdentifier in project gocd by gocd.

the class PipelineUnlockApiServiceTest method shouldBeAbleToVerifyUnlockStatusOfAPipelineWithoutCheckingForUserPermissions.

@Test
public void shouldBeAbleToVerifyUnlockStatusOfAPipelineWithoutCheckingForUserPermissions() throws Exception {
    when(goConfigService.isLockable("pipeline-name")).thenReturn(true);
    when(pipelineLockService.lockedPipeline("pipeline-name")).thenReturn(new StageIdentifier("pipeline-name", 10, "10", "stage", "2"));
    when(currentActivityService.isAnyStageActive(new PipelineIdentifier("pipeline-name", 10, "10"))).thenReturn(false);
    assertThat(pipelineUnlockApiService.isUnlockable("pipeline-name"), is(true));
    verify(pipelineLockService, times(0)).unlock("pipeline-name");
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) PipelineIdentifier(com.thoughtworks.go.domain.PipelineIdentifier) Test(org.junit.Test)

Example 25 with StageIdentifier

use of com.thoughtworks.go.domain.StageIdentifier in project gocd by gocd.

the class PipelineDependencyGraphOldTest method shouldProvideMaterialRevisionForAGivenDownStreamPipeline.

@Test
public void shouldProvideMaterialRevisionForAGivenDownStreamPipeline() throws Exception {
    StageInstanceModels stages = new StageInstanceModels();
    stages.add(new StageInstanceModel("stage-0", "21", StageResult.Cancelled, new StageIdentifier("blahUpStream", 23, "stage-0", "21")));
    stages.add(new StageInstanceModel("stage-1", "2", StageResult.Cancelled, new StageIdentifier("blahUpStream", 23, "stage-1", "2")));
    PipelineInstanceModel upStream = PipelineHistoryMother.singlePipeline("blahUpStream", stages);
    PipelineInstanceModel down1 = pim("blahDown1");
    down1.setMaterialConfigs(new MaterialConfigs(dependencyMaterialConfig("blahUpStream", "stage-0")));
    PipelineInstanceModel down2 = pim("blahDown2");
    down2.setMaterialConfigs(new MaterialConfigs(dependencyMaterialConfig("blahUpStream", "stage-1")));
    PipelineDependencyGraphOld graph = new PipelineDependencyGraphOld(upStream, PipelineInstanceModels.createPipelineInstanceModels(down1, down2));
    assertThat(graph.dependencyRevisionFor(down1), is("blahUpStream/23/stage-0/21"));
    assertThat(graph.dependencyRevisionFor(down2), is("blahUpStream/23/stage-1/2"));
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PipelineInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel) StageInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels) StageInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModel) PipelineDependencyGraphOld(com.thoughtworks.go.domain.PipelineDependencyGraphOld) Test(org.junit.Test)

Aggregations

StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)58 Test (org.junit.Test)30 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)12 Pipeline (com.thoughtworks.go.domain.Pipeline)10 Stage (com.thoughtworks.go.domain.Stage)9 StageInstanceModel (com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModel)6 ArrayList (java.util.ArrayList)6 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)5 PipelineState (com.thoughtworks.go.domain.PipelineState)5 Modification (com.thoughtworks.go.domain.materials.Modification)5 StageInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels)5 Username (com.thoughtworks.go.server.domain.Username)4 Date (java.util.Date)4 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)3 JobInstance (com.thoughtworks.go.domain.JobInstance)3 PipelineDependencyGraphOld (com.thoughtworks.go.domain.PipelineDependencyGraphOld)3 PipelineIdentifier (com.thoughtworks.go.domain.PipelineIdentifier)3 DependencyMaterialRevision (com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision)3 PipelineInstanceModel (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel)3 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)3