/** * * @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 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 StageInstanceModels addFutureStage(String name, boolean isAutoApproved) { add(new NullStageHistoryItem(name, isAutoApproved)); return this; }
@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 singlePipeline(String pipelineName, StageInstanceModel stage) { StageInstanceModels stageInstanceModels = new StageInstanceModels(); stageInstanceModels.add(stage); return singlePipeline(pipelineName, stageInstanceModels, new Date()); }
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 shouldReturnTheLatestStageEvenWhenThereIsANullStage() { Date occuredFirst = new DateTime().minusDays(1).toDate(); Date occuredSecond = new DateTime().toDate(); StageInstanceModels stageInstanceModels = stagePerJob("stage", job(JobResult.Passed, occuredSecond), job(JobResult.Passed, occuredFirst)); NullStageHistoryItem stageHistoryItem = new NullStageHistoryItem("not_yet_run", false); stageInstanceModels.add(stageHistoryItem); PipelineInstanceModel instanceModel = PipelineInstanceModel.createPipeline("pipeline", -1, "label", createWithEmptyModifications(), stageInstanceModels); StageInstanceModel value = stageInstanceModels.get(0); assertThat(instanceModel.latestStage(), is(value)); }
@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 shouldReturnIfAStageIsLatest() { Date occuredFirst = new DateTime().minusDays(1).toDate(); Date occuredSecond = new DateTime().toDate(); StageInstanceModels stageInstanceModels = stagePerJob("stage", job(JobResult.Passed, occuredSecond), job(JobResult.Passed, occuredFirst)); NullStageHistoryItem stageHistoryItem = new NullStageHistoryItem("not_yet_run", false); stageInstanceModels.add(stageHistoryItem); PipelineInstanceModel instanceModel = PipelineInstanceModel.createPipeline("pipeline", -1, "label", createWithEmptyModifications(), stageInstanceModels); assertThat(instanceModel.isLatestStage(stageInstanceModels.get(0)), is(true)); assertThat(instanceModel.isLatestStage(stageInstanceModels.get(1)), is(false)); }
public static PipelineInstanceModel custom(StageInstanceModel... stages) { PipelineInstanceModel pipelineInstanceModel = PipelineInstanceModel.createEmptyModel(); pipelineInstanceModel.setStageHistory(new StageInstanceModels()); for (StageInstanceModel stage : stages) { pipelineInstanceModel.getStageHistory().add(stage); } return pipelineInstanceModel; } }
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 shouldBeSucessfulOnAForceContinuedPass_Red_AND_Green_AND_Has_Not_Run_Yet() { Date occuredFirst = new Date(2008, 12, 13); Date occuredSecond = new Date(2008, 12, 14); StageInstanceModels stageInstanceModels = stagePerJob("stage", job(JobResult.Failed, occuredFirst), job(JobResult.Passed, occuredSecond)); stageInstanceModels.add(new NullStageHistoryItem("stage-3", false)); PipelineInstanceModel instanceModel = PipelineInstanceModel.createPipeline("pipeline", -1, "label", createWithEmptyModifications(), stageInstanceModels); assertThat(instanceModel.isLatestStageUnsuccessful(), is(false)); assertThat(instanceModel.isLatestStageSuccessful(), is(true)); assertThat(instanceModel.isRunning(), is(true)); }
@Test public void shouldReturnStatusOfAfailedRerunAndIncompleteStage() { Date occuredFirst = new Date(2008, 12, 13); Date occuredSecond = new Date(2008, 12, 14); StageInstanceModels stageInstanceModels = stagePerJob("stage", job(JobResult.Failed, occuredSecond), job(JobResult.Passed, occuredFirst)); stageInstanceModels.add(new NullStageHistoryItem("stage-3", false)); PipelineInstanceModel instanceModel = PipelineInstanceModel.createPipeline("pipeline", -1, "label", createWithEmptyModifications(), stageInstanceModels); assertThat(instanceModel.isLatestStageUnsuccessful(), is(true)); assertThat(instanceModel.isLatestStageSuccessful(), is(false)); assertThat(instanceModel.isRunning(), is(true)); }
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); }
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 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)); }