public static JobHistory withJob(String name, JobState state, JobResult result, Date scheduledDate) { return new JobHistory().addJob(name, state, result, scheduledDate); } }
public JobHistory addJob(String name, JobState state, JobResult result, Date scheduledDate) { add(new JobHistoryItem(name, state, result, scheduledDate)); return this; }
public Date getScheduledDate() { // All builds in a stage are scheduled at the same time, so this is safe. return this.first().getScheduledDate(); }
public Date getScheduledDate() { if(jobHistory.isEmpty()) { return null; } return jobHistory.getScheduledDate(); }
@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())); }
public StageInstanceModel(String name, String counter, StageResult result, StageIdentifier identifier) { this(name, counter, new JobHistory(), identifier); this.result = result; }
public static JobHistory job(JobState state, JobResult result, Date scheduledDate) { return JobHistory.withJob("firstJob", state, result, scheduledDate); }
@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)); }
public NullStageHistoryItem(String name, boolean isAutoApproved) { super(name, "1", new JobHistory()); this.autoApproved = isAutoApproved; }
@Test public void shouldUnderstandPreviousStageState() { StageInstanceModel item = new StageInstanceModel("foo", "10", JobHistory.withJob("unit", JobState.Assigned, JobResult.Unknown, new Date())); StageInstanceModel previous = new StageInstanceModel("foo", "1", JobHistory.withJob("unit", JobState.Completed, JobResult.Passed, new Date())); assertThat(item.hasPreviousStage(), is(false)); item.setPreviousStage(previous); assertThat(item.hasPreviousStage(), is(true)); assertThat(item.getPreviousStage(), is(previous)); }
public static JobHistory buildHistory(StageConfig stageConfig, Date modificationDate) { JobHistory history = new JobHistory(); for (JobConfig jobConfig : stageConfig.allBuildPlans()) { history.addJob(CaseInsensitiveString.str(jobConfig.name()), JobState.Completed, JobResult.Passed, modificationDate); } return history; }
@Before public void setUp() throws Exception { stageHistory = new StageInstanceModels(); stageHistory.add(new StageInstanceModel(STAGE_UT, "1", new JobHistory())); stageHistory.add(new StageInstanceModel(STAGE_FT, "1", new JobHistory())); stageHistory.add(new StageInstanceModel(STAGE_RELEASE, "1", new JobHistory())); }
private PipelineInstanceModel pipelineNamed(String name) { StageInstanceModels stages = new StageInstanceModels(); stages.add(new StageInstanceModel("dev", "10", JobHistory.withJob("dev", JobState.Completed, JobResult.Failed, new Date()))); return PipelineInstanceModel.createPipeline(name, -1, "1.0", BuildCause.createWithEmptyModifications(), stages); }
@Test public void shouldReturnDateIfJobHistoryIsNotBlank() throws Exception { StageInstanceModel stageHistoryItem = new StageInstanceModel(); JobHistory jobHistory = new JobHistory(); Date date = new Date(1367472329111L); jobHistory.addJob("jobName", JobState.Building, JobResult.Passed, date); stageHistoryItem.setBuildHistory(jobHistory); assertThat(stageHistoryItem.getScheduledDate(), is(date)); } }
@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 shouldUnderstandIfItHasNeverCheckedForRevisions() { StageInstanceModels stages = new StageInstanceModels(); stages.addStage("unit1", JobHistory.withJob("test", JobState.Completed, JobResult.Passed, new Date())); stages.addFutureStage("unit2", false); PipelineInstanceModel pim = PipelineInstanceModel.createPipeline("pipeline", -1, "label", BuildCause.createNeverRun(), stages); pim.setLatestRevisions(MaterialRevisions.EMPTY); assertThat("pim.hasNeverCheckedForRevisions()", pim.hasNeverCheckedForRevisions(), is(true)); } @Test
public static StageInstanceModel toStageInstanceModel(Stage stage) { StageInstanceModel stageInstanceModel = new StageInstanceModel(stage.getName(), String.valueOf(stage.getCounter()), stage.getResult(), stage.getIdentifier()); stageInstanceModel.setApprovalType(stage.getApprovalType()); stageInstanceModel.setApprovedBy(stage.getApprovedBy()); stageInstanceModel.setRerunOfCounter(stage.getRerunOfCounter()); JobHistory jobHistory = new JobHistory(); for (JobInstance jobInstance : stage.getJobInstances()) { jobHistory.addJob(jobInstance.getName(), jobInstance.getState(), jobInstance.getResult(), jobInstance.getScheduledDate()); } stageInstanceModel.setBuildHistory(jobHistory); return stageInstanceModel; }
@Test public void shouldReturnNullIfJobHistoryIsBlank() throws Exception { StageInstanceModel stageHistoryItem = new StageInstanceModel(); stageHistoryItem.setBuildHistory(new JobHistory()); assertThat(stageHistoryItem.getScheduledDate(), is(nullValue())); }
@Test public void shouldUnderstandPipelineStatusMessage() throws Exception { MaterialRevisions revisions = ModificationsMother.modifyOneFile(MaterialsMother.hgMaterials("url"), "revision"); StageInstanceModels stages = new StageInstanceModels(); stages.addStage("unit1", JobHistory.withJob("test", JobState.Completed, JobResult.Passed, new Date())); stages.addFutureStage("unit2", false); PipelineInstanceModel model = PipelineInstanceModel.createPipeline("pipeline", -1, "label", BuildCause.createWithModifications(revisions, ""), stages); assertThat(model.getPipelineStatusMessage(), is("Passed: unit1")); }
@Test public void shouldKnowApproverAsApproverForTheFirstStage() { MaterialRevisions revisions = new MaterialRevisions(); StageInstanceModels models = new StageInstanceModels(); StageInstanceModel firstStage = new StageInstanceModel("dev", "1", new JobHistory()); firstStage.setApprovedBy("some_user"); models.add(firstStage); PipelineInstanceModel model = PipelineInstanceModel.createPipeline("pipeline", -1, "label", BuildCause.createWithModifications(revisions, ""), models); assertThat(model.getApprovedBy(), is("some_user")); assertThat(model.getApprovedByForDisplay(), is("Triggered by some_user")); }