/** * * @deprecated use add method. This is a test helper */ public void addStage(String name, JobHistory history) { add(new StageInstanceModel(name, "1", history)); }
@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)); }
@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)); }
@Test public void shouldReturnNullIfJobHistoryIsBlank() throws Exception { StageInstanceModel stageHistoryItem = new StageInstanceModel(); stageHistoryItem.setBuildHistory(new JobHistory()); assertThat(stageHistoryItem.getScheduledDate(), is(nullValue())); }
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)); } }
@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())); }
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; } }
public static StageInstanceModels stagePerJob(String baseName, List<JobHistory> histories) { StageInstanceModels stageInstanceModels = new StageInstanceModels(); for (int i = 0; i < histories.size(); i++) { String stageName = baseName + "-" + i; StageInstanceModel stage = new StageInstanceModel(stageName, "1", StageResult.Passed, new StageIdentifier("pipeline", 1, "1", stageName, "1")); stage.setBuildHistory(histories.get(i)); stageInstanceModels.add(stage); stageInstanceModels.latestStage().setApprovedBy("cruise"); } return stageInstanceModels; }
@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)); }
public static PipelineInstanceModel pipelineHistoryItemWithOneStage(String pipelineName, String stageName, Date modifiedDate) { StageInstanceModels stageHistory = new StageInstanceModels(); stageHistory.add(new StageInstanceModel(stageName, "1", StageResult.Passed, new StageIdentifier(pipelineName,1,"1", stageName,"1"))); return singlePipeline(pipelineName, stageHistory, modifiedDate); }
@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)); }
public static PipelineInstanceModel custom(String... stageNames) { PipelineInstanceModel pipelineInstanceModel = PipelineInstanceModel.createEmptyModel(); pipelineInstanceModel.setStageHistory(new StageInstanceModels()); for (String stageName : stageNames) { StageInstanceModel stageHistoryItem = new StageInstanceModel(); stageHistoryItem.setName(stageName); pipelineInstanceModel.getStageHistory().add(stageHistoryItem); } return pipelineInstanceModel; }
@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 shouldProvideMaterialRevisionForAGivenDownStreamPipeline() throws Exception { StageInstanceModels stages = new StageInstanceModels(); stages.add(new StageInstanceModel("stage-0","21", StageResult.Cancelled, new StageIdentifier("blahUpStream",23,"stage-0","21"))); stages.add(new StageInstanceModel("stage-1","2", StageResult.Cancelled, new StageIdentifier("blahUpStream",23,"stage-1","2"))); PipelineInstanceModel upStream = PipelineHistoryMother.singlePipeline("blahUpStream", stages); PipelineInstanceModel down1 = pim("blahDown1"); down1.setMaterialConfigs(new MaterialConfigs(dependencyMaterialConfig("blahUpStream", "stage-0"))); PipelineInstanceModel down2 = pim("blahDown2"); down2.setMaterialConfigs(new MaterialConfigs(dependencyMaterialConfig("blahUpStream", "stage-1"))); PipelineDependencyGraphOld graph = new PipelineDependencyGraphOld(upStream, PipelineInstanceModels.createPipelineInstanceModels(down1,down2)); assertThat(graph.dependencyRevisionFor(down1),is("blahUpStream/23/stage-0/21")); assertThat(graph.dependencyRevisionFor(down2),is("blahUpStream/23/stage-1/2")); }
@Test public void shouldShouldbeAbleToTellIfUpStreamMaterialIsAvailableForTrigger() throws Exception { StageInstanceModels stages = new StageInstanceModels(); stages.add(new StageInstanceModel("stage-0","21", StageResult.Cancelled, new StageIdentifier("blahUpStream",23,"stage-0","21"))); PipelineInstanceModel upStream = PipelineHistoryMother.singlePipeline("blahUpStream", stages); PipelineInstanceModel down1 = pim("blahDown1"); down1.setMaterialConfigs(new MaterialConfigs(dependencyMaterialConfig("blahUpStream", "stage-1"))); PipelineDependencyGraphOld graph = new PipelineDependencyGraphOld(upStream, PipelineInstanceModels.createPipelineInstanceModels(down1)); assertThat(graph.hasUpStreamRevisionFor(down1),is(false)); }
private void assertThatTriggerIsPossibleOnlyIfUpStreamPassed(StageResult upstreamResult) { StageInstanceModels stages = new StageInstanceModels(); stages.add(new StageInstanceModel("stage-0","21", upstreamResult, new StageIdentifier("blahUpStream",23,"stage-0","21"))); PipelineInstanceModel upStream = PipelineHistoryMother.singlePipeline("blahUpStream", stages); PipelineInstanceModel down1 = pim("blahDown1"); down1.setMaterialConfigs(new MaterialConfigs(dependencyMaterialConfig("blahUpStream", "stage-0"))); PipelineDependencyGraphOld graph = new PipelineDependencyGraphOld(upStream, PipelineInstanceModels.createPipelineInstanceModels(down1)); assertThat(graph.hasUpStreamRevisionFor(graph.dependencies().find("blahDown1")),is(upstreamResult== StageResult.Passed)); }
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; }