public StageInstanceModel(String name, String counter, StageResult result, StageIdentifier identifier) { this(name, counter, new JobHistory(), identifier); this.result = result; }
public NullStageHistoryItem(String name, boolean isAutoApproved) { super(name, "1", new JobHistory()); this.autoApproved = isAutoApproved; }
public static JobHistory withJob(String name, JobState state, JobResult result, Date scheduledDate) { return new JobHistory().addJob(name, state, result, scheduledDate); } }
@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())); }
@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 shouldReturnNullIfJobHistoryIsBlank() throws Exception { StageInstanceModel stageHistoryItem = new StageInstanceModel(); stageHistoryItem.setBuildHistory(new JobHistory()); assertThat(stageHistoryItem.getScheduledDate(), is(nullValue())); }
@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)); } }
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; }
@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 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")); }
@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 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; }