public static JobHistory job(JobState state, JobResult result, Date scheduledDate) { return JobHistory.withJob("firstJob", state, result, scheduledDate); }
@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)); }
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 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)); }
@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")); }
@Test public void shouldReturnIfAnyMaterialHasModifications() { final SvnMaterial svnMaterial = svnMaterial("http://svnurl"); final HgMaterial hgMaterial = hgMaterial("http://hgurl", "hgdir"); MaterialRevisions currentRevisions = ModificationsMother.getMaterialRevisions(new HashMap<Material, String>() {{ put(svnMaterial, "1"); put(hgMaterial, "a"); }}); MaterialRevisions latestRevisions = ModificationsMother.getMaterialRevisions(new HashMap<Material, String>() {{ put(svnMaterial, "1"); put(hgMaterial, "b"); }}); MaterialConfigs materialConfigs = new MaterialConfigs(); materialConfigs.add(svnMaterial.config()); materialConfigs.add(hgMaterial.config()); 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(currentRevisions, ""), stages); model.setLatestRevisions(latestRevisions); model.setMaterialConfigs(materialConfigs); assertThat("svnMaterial hasNewRevisions", model.hasNewRevisions(svnMaterial.config()), is(false)); assertThat("hgMaterial hasNewRevisions", model.hasNewRevisions(hgMaterial.config()), is(true)); assertThat("all materials hasNewRevisions", model.hasNewRevisions(), is(true)); }