public static StageInstanceModel custom(String stageName, boolean isAutoApproved) { StageInstanceModel stageHistoryItem = new StageInstanceModel(); stageHistoryItem.setName(stageName); if (isAutoApproved) { stageHistoryItem.setApprovalType(GoConstants.APPROVAL_SUCCESS); } else { stageHistoryItem.setApprovalType(GoConstants.APPROVAL_MANUAL); } assertThat("Should create the correct stub", stageHistoryItem.isAutoApproved(), is(isAutoApproved)); return stageHistoryItem; } }
@Test public void shouldBeManualApproved() throws Exception { StageInstanceModel stageHistoryItem = new StageInstanceModel(); stageHistoryItem.setApprovalType(GoConstants.APPROVAL_MANUAL); assertThat(stageHistoryItem.isAutoApproved(), is(false)); }
@Test public void shouldBeAutoApproved() throws Exception { StageInstanceModel stageHistoryItem = new StageInstanceModel(); stageHistoryItem.setApprovalType(GoConstants.APPROVAL_SUCCESS); assertThat(stageHistoryItem.isAutoApproved(), is(true)); }
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; }
public static StageInstanceModels stageHistory(PipelineConfig pipelineConfig, Date modificationDate) { StageInstanceModels history = new StageInstanceModels(); for (StageConfig stageConfig : pipelineConfig) { StageInstanceModel item = new StageInstanceModel(CaseInsensitiveString.str(stageConfig.name()), "1", buildHistory(stageConfig, modificationDate)); item.setCounter("1"); item.setApprovalType(new InstanceFactory().createStageInstance(stageConfig, new DefaultSchedulingContext("anyone"), md5, new TimeProvider()).getApprovalType()); if (stageConfig.requiresApproval()) { item.setApprovedBy(APPROVED_BY); } else { item.setApprovedBy(GoConstants.DEFAULT_APPROVED_BY); } history.add(item); } return history; }