public boolean hasPreviousStageBeenScheduled(String stageName) { StageInstanceModel stage = stageHistory.byName(stageName); int index = stageHistory.indexOf(stage); if (index == 0) { return true; } if (index > 0) { return stageHistory.get(index - 1).isScheduled(); } return false; }
public StageInstanceModel latestStage() { if (size() == 0) { return null; } StageInstanceModel latest = first(); for (int i = 1; i < size(); i++) { StageInstanceModel current = get(i); if (!(current instanceof NullStageHistoryItem) && current.getScheduledDate().after(latest.getScheduledDate())) { latest = current; } } return latest; }
public String nextStageName(String stageName) { int index = indexOf(byName(stageName)); if (index > -1 && index < size() - 1) { return get(index + 1).getName(); } return null; }
public boolean hasSameStagesAs(PipelineInstanceModel pipelineInstanceModel) { StageInstanceModels stageHistory = pipelineInstanceModel.getStageHistory(); if (stages.size() != stageHistory.size()) { return false; } for (int i = 0; i < stages.size(); i++) { if (!equals(stages.get(i), stageHistory.get(i))) { return false; } } return true; }
@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 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)); }