use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.
the class ValueStreamMapService method traverseUpstream.
private void traverseUpstream(CaseInsensitiveString pipelineName, BuildCause buildCause, ValueStreamMap graph, List<MaterialRevision> visitedNodes) {
for (MaterialRevision materialRevision : buildCause.getMaterialRevisions()) {
Material material = materialRevision.getMaterial();
if (material instanceof DependencyMaterial) {
CaseInsensitiveString upstreamPipeline = ((DependencyMaterial) material).getPipelineName();
DependencyMaterialRevision revision = (DependencyMaterialRevision) materialRevision.getRevision();
graph.addUpstreamNode(new PipelineDependencyNode(upstreamPipeline, upstreamPipeline.toString()), new PipelineRevision(revision.getPipelineName(), revision.getPipelineCounter(), revision.getPipelineLabel()), pipelineName);
if (visitedNodes.contains(materialRevision)) {
continue;
}
visitedNodes.add(materialRevision);
DependencyMaterialRevision dmrOfUpstreamPipeline = buildCause.getMaterialRevisions().findDependencyMaterialRevision(upstreamPipeline.toString());
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.domain.materials.Material in project gocd by gocd.
the class GitPostCommitHookImplementerTest method shouldReturnEmptyListIfParamIsMissingForRepoURL.
@Test
public void shouldReturnEmptyListIfParamIsMissingForRepoURL() throws Exception {
GitMaterial material1 = mock(GitMaterial.class);
when(material1.getUrlArgument()).thenReturn(new UrlArgument("https://machine.local.git"));
Set<Material> materials = new HashSet<>(Arrays.asList(material1));
Set<Material> actual = implementer.prune(materials, new HashMap());
assertThat(actual.size(), is(0));
verifyNoMoreInteractions(material1);
}
use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.
the class GitPostCommitHookImplementerTest method shouldReturnListOfMaterialMatchingThePayloadURL.
@Test
public void shouldReturnListOfMaterialMatchingThePayloadURL() throws Exception {
GitMaterial material1 = mock(GitMaterial.class);
when(material1.getUrlArgument()).thenReturn(new UrlArgument("https://other_repo.local.git"));
GitMaterial material2 = mock(GitMaterial.class);
when(material2.getUrlArgument()).thenReturn(new UrlArgument("https://other_repo.local.git"));
GitMaterial material3 = mock(GitMaterial.class);
when(material3.getUrlArgument()).thenReturn(new UrlArgument("https://machine.local.git"));
GitMaterial material4 = mock(GitMaterial.class);
when(material4.getUrlArgument()).thenReturn(new UrlArgument("https://machine.local.git"));
Set<Material> materials = new HashSet<>(Arrays.asList(material1, material2, material3, material4));
HashMap params = new HashMap();
params.put(GitPostCommitHookImplementer.REPO_URL_PARAM_KEY, "https://machine.local.git");
Set<Material> actual = implementer.prune(materials, params);
assertThat(actual.size(), is(2));
assertThat(actual, hasItem(material3));
assertThat(actual, hasItem(material4));
verify(material1).getUrlArgument();
verify(material2).getUrlArgument();
verify(material3).getUrlArgument();
verify(material4).getUrlArgument();
}
use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.
the class PluggableSCMPostCommitHookImplementerTest method shouldReturnListOfMaterialMatchingTheSCMNameWithCaseInsensitivity.
@Test
public void shouldReturnListOfMaterialMatchingTheSCMNameWithCaseInsensitivity() throws Exception {
PluggableSCMMaterial material1 = new PluggableSCMMaterial(MaterialConfigsMother.pluggableSCMMaterialConfig("material-1", null, null));
PluggableSCMMaterial material2 = new PluggableSCMMaterial(MaterialConfigsMother.pluggableSCMMaterialConfig("material-2", null, null));
PluggableSCMMaterial material3 = new PluggableSCMMaterial(MaterialConfigsMother.pluggableSCMMaterialConfig("material-3", null, null));
PluggableSCMMaterial material4 = new PluggableSCMMaterial(MaterialConfigsMother.pluggableSCMMaterialConfig("material-4", null, null));
Set<Material> materials = new HashSet<>(Arrays.asList(material1, material2, material3, material4));
Map params = new HashMap();
params.put(PluggableSCMPostCommitHookImplementer.SCM_NAME, "SCM-MATERIAL-1");
Set<Material> actual = implementer.prune(materials, params);
assertThat(actual.size(), is(1));
assertThat(actual, hasItem(material1));
}
use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.
the class MaterialUpdateStatusNotifierTest method shouldNotifyListenerWhenItsMaterialIsUpdatedEvenIfAnotherListenerThrowsAnException.
@Test
public void shouldNotifyListenerWhenItsMaterialIsUpdatedEvenIfAnotherListenerThrowsAnException() throws Exception {
Material sharedMaterial = new HgMaterial("url", null);
PipelineConfig pipelineConfig1 = new PipelineConfig(new CaseInsensitiveString("config"), new MaterialConfigs());
pipelineConfig1.addMaterialConfig(sharedMaterial.config());
PipelineConfig pipelineConfig2 = new PipelineConfig(new CaseInsensitiveString("another-config"), new MaterialConfigs());
pipelineConfig2.addMaterialConfig(sharedMaterial.config());
MaterialUpdateStatusListener badListener = Mockito.mock(MaterialUpdateStatusListener.class);
Mockito.doThrow(new RuntimeException("foo")).when(badListener).onMaterialUpdate(new MaterialUpdateSuccessfulMessage(sharedMaterial, 123));
MaterialUpdateStatusListener goodListener = Mockito.mock(MaterialUpdateStatusListener.class);
when(badListener.isListeningFor(sharedMaterial)).thenReturn(true);
when(goodListener.isListeningFor(sharedMaterial)).thenReturn(true);
materialUpdateStatusNotifier.registerListenerFor(pipelineConfig1, badListener);
materialUpdateStatusNotifier.registerListenerFor(pipelineConfig2, goodListener);
materialUpdateStatusNotifier.onMessage(new MaterialUpdateSuccessfulMessage(sharedMaterial, 123));
Mockito.verify(badListener).onMaterialUpdate(new MaterialUpdateSuccessfulMessage(sharedMaterial, 123));
Mockito.verify(goodListener).onMaterialUpdate(new MaterialUpdateSuccessfulMessage(sharedMaterial, 123));
}
Aggregations