public StageInstanceModels addFutureStage(String name, boolean isAutoApproved) { add(new NullStageHistoryItem(name, isAutoApproved)); return this; }
@Test public void shouldReturnTheLatestStageEvenWhenThereIsANullStage() { Date occuredFirst = new DateTime().minusDays(1).toDate(); Date occuredSecond = new DateTime().toDate(); StageInstanceModels stageInstanceModels = stagePerJob("stage", job(JobResult.Passed, occuredSecond), job(JobResult.Passed, occuredFirst)); NullStageHistoryItem stageHistoryItem = new NullStageHistoryItem("not_yet_run", false); stageInstanceModels.add(stageHistoryItem); PipelineInstanceModel instanceModel = PipelineInstanceModel.createPipeline("pipeline", -1, "label", createWithEmptyModifications(), stageInstanceModels); StageInstanceModel value = stageInstanceModels.get(0); assertThat(instanceModel.latestStage(), is(value)); }
@Test public void shouldReturnFalseIfPreviousStageHasNotBeenScheduled() throws Exception { PipelineInstanceModel twoStages = PipelineHistoryItemMother.custom(new NullStageHistoryItem("stage1"), new StageInstanceModel("stage2", "1", new JobHistory())); assertThat(twoStages.hasPreviousStageBeenScheduled("stage2"), is(false)); PipelineInstanceModel threeStages = PipelineHistoryItemMother.custom(new NullStageHistoryItem("stage1"), new NullStageHistoryItem("stage2"), new StageInstanceModel("stage3", "1", new JobHistory())); assertThat(threeStages.hasPreviousStageBeenScheduled("stage3"), is(false)); }
@Test public void shouldReturnIfAStageIsLatest() { Date occuredFirst = new DateTime().minusDays(1).toDate(); Date occuredSecond = new DateTime().toDate(); StageInstanceModels stageInstanceModels = stagePerJob("stage", job(JobResult.Passed, occuredSecond), job(JobResult.Passed, occuredFirst)); NullStageHistoryItem stageHistoryItem = new NullStageHistoryItem("not_yet_run", false); stageInstanceModels.add(stageHistoryItem); PipelineInstanceModel instanceModel = PipelineInstanceModel.createPipeline("pipeline", -1, "label", createWithEmptyModifications(), stageInstanceModels); assertThat(instanceModel.isLatestStage(stageInstanceModels.get(0)), is(true)); assertThat(instanceModel.isLatestStage(stageInstanceModels.get(1)), is(false)); }
@Test public void shouldBeSucessfulOnAForceContinuedPass_Red_AND_Green_AND_Has_Not_Run_Yet() { Date occuredFirst = new Date(2008, 12, 13); Date occuredSecond = new Date(2008, 12, 14); StageInstanceModels stageInstanceModels = stagePerJob("stage", job(JobResult.Failed, occuredFirst), job(JobResult.Passed, occuredSecond)); stageInstanceModels.add(new NullStageHistoryItem("stage-3", false)); PipelineInstanceModel instanceModel = PipelineInstanceModel.createPipeline("pipeline", -1, "label", createWithEmptyModifications(), stageInstanceModels); assertThat(instanceModel.isLatestStageUnsuccessful(), is(false)); assertThat(instanceModel.isLatestStageSuccessful(), is(true)); assertThat(instanceModel.isRunning(), is(true)); }
@Test public void shouldReturnStatusOfAfailedRerunAndIncompleteStage() { Date occuredFirst = new Date(2008, 12, 13); Date occuredSecond = new Date(2008, 12, 14); StageInstanceModels stageInstanceModels = stagePerJob("stage", job(JobResult.Failed, occuredSecond), job(JobResult.Passed, occuredFirst)); stageInstanceModels.add(new NullStageHistoryItem("stage-3", false)); PipelineInstanceModel instanceModel = PipelineInstanceModel.createPipeline("pipeline", -1, "label", createWithEmptyModifications(), stageInstanceModels); assertThat(instanceModel.isLatestStageUnsuccessful(), is(true)); assertThat(instanceModel.isLatestStageSuccessful(), is(false)); assertThat(instanceModel.isRunning(), is(true)); }