use of com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig 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 pipelineConfig1 = new PipelineConfig(new CaseInsensitiveString("pipeline"), new MaterialConfigs());
pipelineConfig1.addMaterialConfig(materialConfig1);
pipelineConfig1.addMaterialConfig(materialConfig2);
when(goConfigService.pipelineConfigNamed(pipelineConfig.name())).thenReturn(pipelineConfig1);
when(goConfigService.hasPipelineNamed(pipelineConfig.name())).thenReturn(true);
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(pipelineConfig1);
}
use of com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig 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.HgMaterialConfig in project gocd by gocd.
the class BuildCauseProducerServiceTest method manualTrigger_shouldNotUpdatePipelineConfigWhenConfigRepoIsNotInMaterials.
@Test
public void manualTrigger_shouldNotUpdatePipelineConfigWhenConfigRepoIsNotInMaterials() {
HgMaterial material1 = new HgMaterial("url", null);
HgMaterialConfig materialConfig1 = new HgMaterialConfig("url", null);
HgMaterialConfig materialConfig2 = new HgMaterialConfig("url2", null);
pipelineConfig.addMaterialConfig(materialConfig1);
pipelineConfig.setOrigin(new RepoConfigOrigin(new ConfigRepoConfig(materialConfig2, "plug"), "revision1"));
when(materialConfigConverter.toMaterial(materialConfig1)).thenReturn(material1);
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(1)).pipelineConfigNamed(pipelineConfig.name());
}
use of com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig 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.HgMaterialConfig in project gocd by gocd.
the class ConfigConverterTest method shouldConvertConfigMaterialWhenConfigRepoIsHgWithEmptyFilter.
@Test
public void shouldConvertConfigMaterialWhenConfigRepoIsHgWithEmptyFilter() {
// this url would be configured inside xml config-repo section
HgMaterialConfig configRepoMaterial = new HgMaterialConfig("url", "folder");
when(context.configMaterial()).thenReturn(configRepoMaterial);
CRConfigMaterial crConfigMaterial = new CRConfigMaterial(null, null, new CRFilter(new ArrayList<>(), true));
MaterialConfig materialConfig = configConverter.toMaterialConfig(crConfigMaterial, context);
assertNull("shouldSetEmptyMaterialNameAsInConfigRepoSourceCode", materialConfig.getName());
HgMaterialConfig hgMaterialConfig = (HgMaterialConfig) materialConfig;
assertThat(hgMaterialConfig.getAutoUpdate(), is(true));
assertThat(hgMaterialConfig.getFilterAsString(), is(""));
assertThat(hgMaterialConfig.getUrl(), is("url"));
assertThat(hgMaterialConfig.filter(), is(new Filter()));
assertThat(hgMaterialConfig.isInvertFilter(), is(false));
}
Aggregations