use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class BuildCauseProducerServiceTest method shouldHandleCaseWhereSpecifiedRevisionDoesNotExist.
@Test
public void shouldHandleCaseWhereSpecifiedRevisionDoesNotExist() throws Exception {
DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("upstream-pipeline"), new CaseInsensitiveString("stage"));
when(specificMaterialRevisionFactory.create(eq("pipeline"), eq(Collections.singletonMap(dependencyMaterial.getPipelineUniqueFingerprint(), "upstream-pipeline/200/stage/1")))).thenThrow(new RuntimeException("Invalid specified revision"));
ManualBuild buildType = new ManualBuild(Username.ANONYMOUS);
final HashMap<String, String> stringStringHashMap = new HashMap<>();
buildCauseProducerService.newProduceBuildCause(pipelineConfig, buildType, new ScheduleOptions(Collections.singletonMap(dependencyMaterial.getPipelineUniqueFingerprint(), "upstream-pipeline/200/stage/1"), stringStringHashMap, new HashMap<>()), new ServerHealthStateOperationResult(), 12345);
verify(mockServerHealthService).update(argThat(hasErrorHealthState("Error while scheduling pipeline: pipeline", "Invalid specified revision")));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class BuildCauseProducerServiceTest method shouldHandleNoModificationExceptionThrownByAutoBuild.
@Test
public void shouldHandleNoModificationExceptionThrownByAutoBuild() {
String pipelineName = "pipeline";
ServerHealthStateOperationResult result = new ServerHealthStateOperationResult();
PipelineConfig config = PipelineConfigMother.pipelineConfig(pipelineName);
Material svnMaterial = MaterialsMother.defaultMaterials().get(0);
DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("up"), new CaseInsensitiveString("s1"));
config.materialConfigs().clear();
config.addMaterialConfig(svnMaterial.config());
config.addMaterialConfig(dependencyMaterial.config());
when(pipelineService.getRevisionsBasedOnDependencies(Matchers.<MaterialRevisions>any(), Matchers.<BasicCruiseConfig>any(), Matchers.<CaseInsensitiveString>any())).thenThrow(new NoModificationsPresentForDependentMaterialException("P/1/S/1"));
when(pipelineScheduleQueue.mostRecentScheduled(pipelineName)).thenReturn(BuildCause.createNeverRun());
Modification modification = ModificationsMother.checkinWithComment("r", "c", new Date(), "f1");
when(materialRepository.findLatestModification(svnMaterial)).thenReturn(ModificationsMother.createSvnMaterialWithMultipleRevisions(1, modification));
when(materialRepository.findLatestModification(dependencyMaterial)).thenReturn(new MaterialRevisions(ModificationsMother.changedDependencyMaterialRevision("up", 1, "1", "s", 1, new Date())));
when(specificMaterialRevisionFactory.create(Matchers.<String>any(), Matchers.<Map<String, String>>any())).thenReturn(MaterialRevisions.EMPTY);
when(goConfigService.upstreamDependencyGraphOf(Matchers.<String>any(), Matchers.<BasicCruiseConfig>any())).thenReturn(new PipelineConfigDependencyGraph(config));
MaterialConfigs knownMaterialConfigs = new MaterialConfigs(svnMaterial.config(), dependencyMaterial.config());
Materials materials = new Materials(svnMaterial, dependencyMaterial);
when(materialConfigConverter.toMaterials(config.materialConfigs())).thenReturn(materials);
when(materialExpansionService.expandMaterialConfigsForScheduling(config.materialConfigs())).thenReturn(knownMaterialConfigs);
when(materialConfigConverter.toMaterials(knownMaterialConfigs)).thenReturn(materials);
AutoBuild autoBuild = new AutoBuild(goConfigService, pipelineService, pipelineName, new SystemEnvironment(), null, mockServerHealthService);
ServerHealthState serverHealthState = buildCauseProducerService.newProduceBuildCause(config, autoBuild, result, 12345);
assertThat(serverHealthState.isSuccess(), is(true));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class BuildCauseProducerServiceTest method shouldHandleCaseWhenExceptionWithoutMessageIsRaised.
@Test
public void shouldHandleCaseWhenExceptionWithoutMessageIsRaised() throws Exception {
DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("upstream-pipeline"), new CaseInsensitiveString("stage"));
when(specificMaterialRevisionFactory.create(eq("pipeline"), eq(Collections.singletonMap(dependencyMaterial.getPipelineUniqueFingerprint(), "upstream-pipeline/200/stage/1")))).thenThrow(new NullPointerException());
ManualBuild buildType = new ManualBuild(Username.ANONYMOUS);
final HashMap<String, String> stringStringHashMap = new HashMap<>();
buildCauseProducerService.newProduceBuildCause(pipelineConfig, buildType, new ScheduleOptions(Collections.singletonMap(dependencyMaterial.getPipelineUniqueFingerprint(), "upstream-pipeline/200/stage/1"), stringStringHashMap, new HashMap<>()), new ServerHealthStateOperationResult(), 12345);
verify(mockServerHealthService).update(argThat(hasErrorHealthState("Error while scheduling pipeline: pipeline", "Details not available, please check server logs.")));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class ValueStreamMapService method traverseUpstream.
private void traverseUpstream(String pipelineName, BuildCause buildCause, ValueStreamMap graph, List<MaterialRevision> visitedNodes) {
for (MaterialRevision materialRevision : buildCause.getMaterialRevisions()) {
Material material = materialRevision.getMaterial();
if (material instanceof DependencyMaterial) {
String upstreamPipeline = ((DependencyMaterial) material).getPipelineName().toString();
DependencyMaterialRevision revision = (DependencyMaterialRevision) materialRevision.getRevision();
graph.addUpstreamNode(new PipelineDependencyNode(upstreamPipeline, upstreamPipeline), new PipelineRevision(revision.getPipelineName(), revision.getPipelineCounter(), revision.getPipelineLabel()), pipelineName);
if (visitedNodes.contains(materialRevision)) {
continue;
}
visitedNodes.add(materialRevision);
DependencyMaterialRevision dmrOfUpstreamPipeline = buildCause.getMaterialRevisions().findDependencyMaterialRevision(upstreamPipeline);
BuildCause buildCauseForUpstreamPipeline = pipelineService.buildCauseFor(dmrOfUpstreamPipeline.getPipelineName(), dmrOfUpstreamPipeline.getPipelineCounter());
traverseUpstream(upstreamPipeline, buildCauseForUpstreamPipeline, graph, visitedNodes);
} else {
graph.addUpstreamMaterialNode(new SCMDependencyNode(material.getFingerprint(), material.getUriForDisplay(), materialRevision.getMaterialType()), material.getName(), pipelineName, materialRevision);
}
}
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class MaterialDatabaseDependencyUpdaterTest method shouldReturnLatestPipelineIfThereHasBeenANewOne.
@Test
public void shouldReturnLatestPipelineIfThereHasBeenANewOne() throws Exception {
DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name"));
stubStageServiceGetHistory(null, stages(9));
updater.updateMaterial(dependencyMaterial);
List<Modification> modification = materialRepository.findLatestModification(dependencyMaterial).getMaterialRevision(0).getModifications();
stubStageServiceGetHistoryAfter(null, 9, stages(10));
updater.updateMaterial(dependencyMaterial);
List<Modification> newModifications = materialRepository.findModificationsSince(dependencyMaterial, new MaterialRevision(dependencyMaterial, modification));
assertThat(newModifications.size(), is(1));
assertThat(newModifications.get(0).getRevision(), is("pipeline-name/10/stage-name/0"));
assertThat(newModifications.get(0).getPipelineLabel(), is("LABEL-10"));
}
Aggregations