use of com.thoughtworks.go.config.materials.mercurial.HgMaterial in project gocd by gocd.
the class BuildCauseProducerServiceTest method shouldScheduleAfterAllMaterialsAreUpdated.
@Test
public void shouldScheduleAfterAllMaterialsAreUpdated() throws Exception {
HgMaterial hgMaterial = new HgMaterial("url", null);
HgMaterialConfig hgMaterialConfig = new HgMaterialConfig("url", null);
SvnMaterial svnMaterial = new SvnMaterial("url", null, null, false);
SvnMaterialConfig svnMaterialConfig = new SvnMaterialConfig("url", null, null, false);
pipelineConfig.addMaterialConfig(hgMaterialConfig);
pipelineConfig.addMaterialConfig(svnMaterialConfig);
GoConfigService service = mock(GoConfigService.class);
when(service.pipelineConfigNamed(pipelineConfig.name())).thenReturn(pipelineConfig);
when(materialConfigConverter.toMaterial(hgMaterialConfig)).thenReturn(hgMaterial);
when(materialConfigConverter.toMaterial(svnMaterialConfig)).thenReturn(svnMaterial);
MaterialUpdateStatusNotifier notifier = new MaterialUpdateStatusNotifier(mock(MaterialUpdateCompletedTopic.class));
buildCauseProducerService = spy(createBuildCauseProducerService(notifier));
buildCauseProducerService.manualSchedulePipeline(Username.ANONYMOUS, pipelineConfig.name(), new ScheduleOptions(), new ServerHealthStateOperationResult());
final HashMap<String, String> stringStringHashMap = new HashMap<>();
doReturn(ServerHealthState.success(healthStateType)).when(buildCauseProducerService).newProduceBuildCause(eq(pipelineConfig), any(ManualBuild.class), new ScheduleOptions(eq(EMPTY_REVISIONS), stringStringHashMap, new HashMap<>()), any(ServerHealthStateOperationResult.class), eq(12345L));
assertThat(notifier.hasListenerFor(pipelineConfig), is(true));
notifier.onMessage(new MaterialUpdateSuccessfulMessage(hgMaterial, 1111L));
assertThat(notifier.hasListenerFor(pipelineConfig), is(true));
notifier.onMessage(new MaterialUpdateSuccessfulMessage(svnMaterial, 2222L));
assertThat(notifier.hasListenerFor(pipelineConfig), is(false));
verify(buildCauseProducerService).newProduceBuildCause(eq(pipelineConfig), any(ManualBuild.class), eq(new ScheduleOptions()), any(ServerHealthStateOperationResult.class), eq(2222L));
}
use of com.thoughtworks.go.config.materials.mercurial.HgMaterial in project gocd by gocd.
the class BuildCauseProducerServiceTest method manualTrigger_shouldRequestUpdateOfNewMaterials_WhenPipelineConfigInConfigRepo.
@Test
public void manualTrigger_shouldRequestUpdateOfNewMaterials_WhenPipelineConfigInConfigRepo() {
HgMaterial material1 = new HgMaterial("url", null);
HgMaterial material2 = new HgMaterial("url2", null);
HgMaterialConfig materialConfig1 = new HgMaterialConfig("url", null);
HgMaterialConfig materialConfig2 = new HgMaterialConfig("url2", null);
pipelineConfig.addMaterialConfig(materialConfig1);
pipelineConfig.setOrigin(new RepoConfigOrigin(new ConfigRepoConfig(materialConfig1, "plug"), "revision1"));
when(materialConfigConverter.toMaterial(materialConfig1)).thenReturn(material1);
when(materialConfigConverter.toMaterial(materialConfig2)).thenReturn(material2);
buildCauseProducerService.manualSchedulePipeline(Username.ANONYMOUS, pipelineConfig.name(), new ScheduleOptions(new HashMap<>(), new HashMap<>(), new HashMap<>()), new ServerHealthStateOperationResult());
verify(goConfigService, times(1)).pipelineConfigNamed(pipelineConfig.name());
// updated pipeline config
PipelineConfig updatedPipelineConfig = new PipelineConfig(new CaseInsensitiveString("pipeline"), new MaterialConfigs());
updatedPipelineConfig.addMaterialConfig(materialConfig1);
updatedPipelineConfig.addMaterialConfig(materialConfig2);
when(goConfigService.pipelineConfigNamed(pipelineConfig.name())).thenReturn(updatedPipelineConfig);
when(goConfigService.hasPipelineNamed(pipelineConfig.name())).thenReturn(true);
Materials materials = new Materials(material1, material2);
when(materialConfigConverter.toMaterials(updatedPipelineConfig.materialConfigs())).thenReturn(materials);
when(materialExpansionService.expandMaterialConfigsForScheduling(updatedPipelineConfig.materialConfigs())).thenReturn(updatedPipelineConfig.materialConfigs());
when(pipelineScheduleQueue.mostRecentScheduled(updatedPipelineConfig.name().toString())).thenReturn(BuildCause.createNeverRun());
when(materialChecker.findLatestRevisions(any(), eq(materials))).thenReturn(new MaterialRevisions());
MaterialUpdateStatusListener statusListener = extractMaterialListenerInstanceFromRegisterCall();
statusListener.onMaterialUpdate(new MaterialUpdateSuccessfulMessage(material1, 0));
verify(goConfigService, times(2)).pipelineConfigNamed(pipelineConfig.name());
verify(mockMaterialUpdateService, times(1)).updateMaterial(material1);
verify(mockMaterialUpdateService, times(1)).updateMaterial(material2);
statusListener.onMaterialUpdate(new MaterialUpdateSuccessfulMessage(material2, 0));
verify(mockMaterialUpdateStatusNotifier).removeListenerFor(updatedPipelineConfig);
}
use of com.thoughtworks.go.config.materials.mercurial.HgMaterial in project gocd by gocd.
the class BuildCauseProducerServiceTest method shouldAllowTriggeringOfPipelineAfterMaterialUpdate.
@Test
public void shouldAllowTriggeringOfPipelineAfterMaterialUpdate() throws Exception {
HgMaterial hgMaterial = new HgMaterial("url", null);
HgMaterialConfig hgMaterialConfig = new HgMaterialConfig("url", null);
pipelineConfig.addMaterialConfig(hgMaterialConfig);
when(materialConfigConverter.toMaterial(hgMaterialConfig)).thenReturn(hgMaterial);
when(specificMaterialRevisionFactory.create("pipeline", new HashMap<>())).thenReturn(new MaterialRevisions());
when(pipelineScheduleQueue.mostRecentScheduled(CaseInsensitiveString.str(pipelineConfig.name()))).thenReturn(BuildCause.createNeverRun());
when(materialRepository.findLatestModification(hgMaterial)).thenReturn(new MaterialRevisions(new MaterialRevision(hgMaterial, new ArrayList<>())));
buildCauseProducerService.manualSchedulePipeline(Username.ANONYMOUS, pipelineConfig.name(), new ScheduleOptions(), new ServerHealthStateOperationResult());
assertThat(triggerMonitor.isAlreadyTriggered(CaseInsensitiveString.str(pipelineConfig.name())), is(true));
sendMaterialUpdateCompleteMessage(extractMaterialListenerInstanceFromRegisterCall(), hgMaterial);
assertThat(triggerMonitor.isAlreadyTriggered(CaseInsensitiveString.str(pipelineConfig.name())), is(false));
}
use of com.thoughtworks.go.config.materials.mercurial.HgMaterial in project gocd by gocd.
the class BuildCauseProducerServiceTest method manualTrigger_shouldUpdatePipelineConfigWhenMaterialIsConfigRepo.
@Test
public void manualTrigger_shouldUpdatePipelineConfigWhenMaterialIsConfigRepo() {
HgMaterial material1 = new HgMaterial("url", null);
HgMaterialConfig materialConfig1 = new HgMaterialConfig("url", null);
pipelineConfig.addMaterialConfig(materialConfig1);
pipelineConfig.setOrigin(new RepoConfigOrigin(new ConfigRepoConfig(materialConfig1, "plug"), "revision1"));
when(materialConfigConverter.toMaterial(materialConfig1)).thenReturn(material1);
when(goConfigService.hasPipelineNamed(pipelineConfig.name())).thenReturn(true);
buildCauseProducerService.manualSchedulePipeline(Username.ANONYMOUS, pipelineConfig.name(), new ScheduleOptions(new HashMap<>(), new HashMap<>(), new HashMap<>()), new ServerHealthStateOperationResult());
verify(goConfigService, times(1)).pipelineConfigNamed(pipelineConfig.name());
MaterialUpdateStatusListener statusListener = extractMaterialListenerInstanceFromRegisterCall();
statusListener.onMaterialUpdate(new MaterialUpdateSuccessfulMessage(material1, 0));
verify(mockMaterialUpdateStatusNotifier).removeListenerFor(pipelineConfig);
verify(goConfigService, times(2)).pipelineConfigNamed(pipelineConfig.name());
}
use of com.thoughtworks.go.config.materials.mercurial.HgMaterial 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));
}
Aggregations