public JobHistory addJob(String name, JobState state, JobResult result, Date scheduledDate) { add(new JobHistoryItem(name, state, result, scheduledDate)); return this; }
@Test public void shouldBeRunningBasedOnJobState() { assertThat(new JobHistoryItem("", JobState.Assigned, JobResult.Unknown, new Date()).isRunning(),is(true)); assertThat(new JobHistoryItem("", JobState.Building, JobResult.Unknown, new Date()).isRunning(),is(true)); assertThat(new JobHistoryItem("", JobState.Completing, JobResult.Unknown, new Date()).isRunning(),is(true)); assertThat(new JobHistoryItem("", JobState.Preparing, JobResult.Unknown, new Date()).isRunning(),is(true)); assertThat(new JobHistoryItem("", JobState.Scheduled, JobResult.Unknown, new Date()).isRunning(),is(true)); } }
@Test public void shouldBeUnsuccessfullyCompletedWhenFailedOrCancelled() { assertThat(new JobHistoryItem("", JobState.Completed, JobResult.Failed, new Date()).hasUnsuccessfullyCompleted(),is(true)); assertThat(new JobHistoryItem("", JobState.Completed, JobResult.Cancelled, new Date()).hasUnsuccessfullyCompleted(),is(true)); }
@Test public void shouldPassedWhenJobCompletesSuccessfully() { assertThat(new JobHistoryItem("", JobState.Completed, JobResult.Passed, new Date()).hasPassed(),is(true)); }
@Test public void shouldReturnNullWhenNoActiveStage() { StageInstanceModels stages = new StageInstanceModels(); stages.addStage("unit1", JobHistory.withJob("test", JobState.Completed, JobResult.Passed, new Date())); JobHistory history = new JobHistory(); history.add(new JobHistoryItem("test-1", JobState.Completed, JobResult.Failed, new Date())); history.add(new JobHistoryItem("test-2", JobState.Completed, JobResult.Passed, new Date())); stages.add(new StageInstanceModel("unit2", "1", history)); stages.addFutureStage("unit3", false); PipelineInstanceModel model = PipelineInstanceModel.createPipeline("pipeline", -1, "label", BuildCause.createManualForced(), stages); assertThat(model.activeStage(), is(nullValue())); }
@Test public void shouldUnderstandActiveStage() { StageInstanceModels stages = new StageInstanceModels(); stages.addStage("unit1", JobHistory.withJob("test", JobState.Completed, JobResult.Passed, new Date())); JobHistory history = new JobHistory(); history.add(new JobHistoryItem("test-1", JobState.Completed, JobResult.Failed, new Date())); history.add(new JobHistoryItem("test-2", JobState.Building, JobResult.Unknown, new Date())); StageInstanceModel activeStage = new StageInstanceModel("unit2", "1", history); stages.add(activeStage); stages.addFutureStage("unit3", false); PipelineInstanceModel model = PipelineInstanceModel.createPipeline("pipeline", -1, "label", BuildCause.createManualForced(), stages); assertThat(model.activeStage(), is(activeStage)); }