public static PipelineInstanceModel singlePipeline(String pipelineName, StageInstanceModel stage) { StageInstanceModels stageInstanceModels = new StageInstanceModels(); stageInstanceModels.add(stage); return singlePipeline(pipelineName, stageInstanceModels, new Date()); }
private PipelineModel addInstanceTo(PipelineModel pipelineModel) { pipelineModel.addPipelineInstance(new PipelineInstanceModel(pipelineModel.getName(), 1, "label", BuildCause.createManualForced(), new StageInstanceModels())); return pipelineModel; } }
private PipelineInstanceModel addEmptyPipelineInstance(String pipelineName, Username username, PipelineConfig pipelineConfig, boolean populateCanRun) { StageInstanceModels stageHistory = new StageInstanceModels(); appendFollowingStagesFromConfig(pipelineName, stageHistory); PipelineInstanceModel model = PipelineInstanceModel.createEmptyPipelineInstanceModel(pipelineName, BuildCause.createWithEmptyModifications(), stageHistory); populatePipelineInstanceModel(username, populateCanRun, pipelineConfig, model); model.setCanRun(true); return model; }
private PipelineInstanceModels findPIMsWithFallbacks(PipelineConfig pipelineConfig, PipelineInstanceModels historyForDashboard) { String pipelineName = str(pipelineConfig.name()); PipelineInstanceModels pipelinesToShow = historyForDashboard.findAll(pipelineName); if (!pipelinesToShow.isEmpty()) { return pipelinesToShow; } if (triggerMonitor.isAlreadyTriggered(pipelineConfig.name())) { return createPipelineInstanceModels(createPreparingToSchedule(pipelineName, new StageInstanceModels())); } return createPipelineInstanceModels(createEmptyPipelineInstanceModel(pipelineName, createWithEmptyModifications(), new StageInstanceModels())); }
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); }
private PipelineInstanceModel hgMaterialWithNoModifications() { MaterialRevisions revisions = new MaterialRevisions(); revisions.addRevision(MaterialsMother.hgMaterial(), new ArrayList<>()); PipelineInstanceModel model = PipelineInstanceModel.createPipeline("pipeline", -1, "label", null, new StageInstanceModels()); model.setLatestRevisions(revisions); return model; }
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; }
private PipelineInstanceModel setUpModificationFor(HgMaterial material) { MaterialRevisions revisions = new MaterialRevisions(); revisions.addRevision(material, HG_MATERIAL_MODIFICATION); return PipelineInstanceModel.createPipeline("pipeline", -1, "label", BuildCause.createWithModifications(revisions, ""), new StageInstanceModels()); }
@Test public void shouldUnderstandPipelineStatusMessage() throws Exception { StageInstanceModels stages = new StageInstanceModels(); stages.addFutureStage("unit1", false); stages.addFutureStage("unit2", false); PipelineInstanceModel pipeline = PipelineInstanceModel.createPreparingToSchedule("pipeline-name", stages); assertThat(pipeline.getPipelineStatusMessage(), Matchers.is("Preparing to schedule (0/2)")); }
@Test public void shouldUnderstandIfReal() { assertThat(PipelineInstanceModel.createEmptyModel().hasHistoricalData(), is(true)); assertThat(PipelineInstanceModel.createEmptyPipelineInstanceModel("pipeline", createWithEmptyModifications(), new StageInstanceModels()).hasHistoricalData(), is(false)); }
@Test public void shouldReturnEarliestDate() { StageInstanceModels history = new StageInstanceModels(); history.add(new StageHistoryItemStub(EARLIEAR_DATE)); history.add(new StageHistoryItemStub(DATE)); assertThat(history.getScheduledDate(), Matchers.is(EARLIEAR_DATE)); }
@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
@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")); }
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 shouldGetCurrentRevisionForMaterialByName() { MaterialRevisions revisions = new MaterialRevisions(); HgMaterial material = MaterialsMother.hgMaterial(); SvnMaterial svnMaterial = MaterialsMother.svnMaterial(); material.setName(new CaseInsensitiveString("hg_material")); revisions.addRevision(svnMaterial, new Modification(new Date(), "1024", "MOCK_LABEL-12", null)); revisions.addRevision(material, HG_MATERIAL_MODIFICATION); BuildCause buildCause = BuildCause.createWithModifications(revisions, ""); PipelineInstanceModel model = PipelineInstanceModel.createPipeline("pipeline", -1, "label", buildCause, new StageInstanceModels()); assertThat(model.getCurrentRevision("hg_material").getRevision(), is("a087402bd2a7828a130c1bdf43f2d9ef8f48fd46")); }
@Test public void shouldGetCurrentMaterialRevisionForMaterial() { MaterialRevisions revisions = new MaterialRevisions(); HgMaterial material = MaterialsMother.hgMaterial(); revisions.addRevision(material, HG_MATERIAL_MODIFICATION); PipelineInstanceModel model = PipelineInstanceModel.createPipeline("pipeline", -1, "label", BuildCause.createWithModifications(revisions, ""), new StageInstanceModels()); assertThat(model.findCurrentMaterialRevisionForUI(material.config()), is(revisions.getMaterialRevision(0))); }
@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 shouldFallbackToPipelineFingerpringWhenGettingCurrentMaterialRevisionForMaterialIsNull() { MaterialRevisions revisions = new MaterialRevisions(); HgMaterial material = MaterialsMother.hgMaterial(); HgMaterial materialWithDifferentDest = MaterialsMother.hgMaterial(); materialWithDifferentDest.setFolder("otherFolder"); revisions.addRevision(material, HG_MATERIAL_MODIFICATION); PipelineInstanceModel model = PipelineInstanceModel.createPipeline("pipeline", -1, "label", BuildCause.createWithModifications(revisions, ""), new StageInstanceModels()); assertThat(model.findCurrentMaterialRevisionForUI(materialWithDifferentDest.config()), is(revisions.getMaterialRevision(0))); }
@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())); }