use of com.thoughtworks.go.config.CaseInsensitiveString in project gocd by gocd.
the class MaterialUpdateStatusNotifierTest method shouldBeAbleToUnregisterAListenerDuringACallback.
@Test
public void shouldBeAbleToUnregisterAListenerDuringACallback() throws Exception {
final PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("config"), new MaterialConfigs());
Material material = new HgMaterial("url", null);
pipelineConfig.addMaterialConfig(material.config());
MaterialUpdateStatusListener statusListener = new MaterialUpdateStatusListener() {
public void onMaterialUpdate(MaterialUpdateCompletedMessage message) {
materialUpdateStatusNotifier.removeListenerFor(pipelineConfig);
}
public boolean isListeningFor(Material material) {
return true;
}
};
materialUpdateStatusNotifier.registerListenerFor(pipelineConfig, statusListener);
materialUpdateStatusNotifier.onMessage(new MaterialUpdateSuccessfulMessage(material, 123));
assertThat(materialUpdateStatusNotifier.hasListenerFor(pipelineConfig), is(false));
}
use of com.thoughtworks.go.config.CaseInsensitiveString 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));
}
use of com.thoughtworks.go.config.CaseInsensitiveString in project gocd by gocd.
the class SpecificMaterialRevisionFactoryTest method shouldCreateDependencyMaterialForAPipeline.
@Test
public void shouldCreateDependencyMaterialForAPipeline() throws Exception {
DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("upstream"), new CaseInsensitiveString("blah-stage"));
MaterialConfig dependencyMaterialConfig = dependencyMaterial.config();
MaterialRevision expected = new MaterialRevision(dependencyMaterial, new Modification(new Date(), "upstream/4/blah-stage/2", "MOCK_LABEL-12", null));
String upstreamFingerprint = "234fa4";
when(mockGoConfigService.findMaterial(new CaseInsensitiveString("blahPipeline"), upstreamFingerprint)).thenReturn(dependencyMaterialConfig);
when(materialConfigConverter.toMaterial(dependencyMaterialConfig)).thenReturn(dependencyMaterial);
when(mockMaterialChecker.findSpecificRevision(dependencyMaterial, "upstream/4/blah-stage/2")).thenReturn(expected);
MaterialRevisions materialRevisions = specificMaterialRevisionFactory.create("blahPipeline", Collections.singletonMap(upstreamFingerprint, "upstream/4/blah-stage/2"));
assertThat(materialRevisions, is(new MaterialRevisions(expected)));
}
use of com.thoughtworks.go.config.CaseInsensitiveString in project gocd by gocd.
the class SpecificMaterialRevisionFactoryTest method shouldThrowExceptionWhenSpecifiedMaterialDoesNotExist.
@Test
public void shouldThrowExceptionWhenSpecifiedMaterialDoesNotExist() throws Exception {
when(mockGoConfigService.findMaterial(new CaseInsensitiveString("blahPipeline"), "not-exist")).thenReturn(null);
try {
specificMaterialRevisionFactory.create("blahPipeline", Collections.singletonMap("not-exist", "upstream/500/blah-stage/2"));
fail("Should not be able to find material");
} catch (Exception expected) {
assertThat(expected.getMessage(), is("Material with fingerprint [not-exist] for pipeline [blahPipeline] does not exist"));
}
}
use of com.thoughtworks.go.config.CaseInsensitiveString in project gocd by gocd.
the class GoDashboardServiceTest method shouldUpdateCacheForPipelineGivenItsConfig.
@Test
public void shouldUpdateCacheForPipelineGivenItsConfig() throws Exception {
PipelineConfig pipelineConfig = configMother.addPipelineWithGroup(config, "group1", "pipeline1", "stage1", "job1");
PipelineConfigs groupConfig = config.findGroup("group1");
GoDashboardPipeline pipeline = pipeline("pipeline1");
when(goConfigService.findGroupByPipeline(new CaseInsensitiveString("pipeline1"))).thenReturn(groupConfig);
when(dashboardCurrentStateLoader.pipelineFor(pipelineConfig, groupConfig)).thenReturn(pipeline);
service.updateCacheForPipeline(pipelineConfig);
verify(cache).put(pipeline);
}
Aggregations