Search in sources :

Example 6 with HgMaterialConfig

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);
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) MaterialUpdateStatusListener(com.thoughtworks.go.server.materials.MaterialUpdateStatusListener) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) HashMap(java.util.HashMap) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) MaterialUpdateSuccessfulMessage(com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 7 with HgMaterialConfig

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));
}
Also used : HashMap(java.util.HashMap) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) ManualBuild(com.thoughtworks.go.server.service.ManualBuild) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) MaterialUpdateStatusNotifier(com.thoughtworks.go.server.materials.MaterialUpdateStatusNotifier) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) MaterialUpdateCompletedTopic(com.thoughtworks.go.server.materials.MaterialUpdateCompletedTopic) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) MaterialUpdateSuccessfulMessage(com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage) Test(org.junit.Test)

Example 8 with HgMaterialConfig

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());
}
Also used : MaterialUpdateStatusListener(com.thoughtworks.go.server.materials.MaterialUpdateStatusListener) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) HashMap(java.util.HashMap) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) MaterialUpdateSuccessfulMessage(com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage) Test(org.junit.Test)

Example 9 with HgMaterialConfig

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());
}
Also used : MaterialUpdateStatusListener(com.thoughtworks.go.server.materials.MaterialUpdateStatusListener) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) HashMap(java.util.HashMap) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) MaterialUpdateSuccessfulMessage(com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage) Test(org.junit.Test)

Example 10 with HgMaterialConfig

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));
}
Also used : Filter(com.thoughtworks.go.config.materials.Filter) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) PluggableSCMMaterialConfig(com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) P4MaterialConfig(com.thoughtworks.go.config.materials.perforce.P4MaterialConfig) TfsMaterialConfig(com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) Test(org.junit.Test)

Aggregations

HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)71 Test (org.junit.Test)60 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)15 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)12 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)11 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)11 P4MaterialConfig (com.thoughtworks.go.config.materials.perforce.P4MaterialConfig)11 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)9 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)8 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)8 TfsMaterialConfig (com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig)8 ServerHealthStateOperationResult (com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult)8 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)7 HashMap (java.util.HashMap)7 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)6 PluggableSCMMaterialConfig (com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig)6 MaterialUpdateStatusListener (com.thoughtworks.go.server.materials.MaterialUpdateStatusListener)5 Filter (com.thoughtworks.go.config.materials.Filter)4 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)4 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)4