Search in sources :

Example 1 with MaterialUpdateStatusNotifier

use of com.thoughtworks.go.server.materials.MaterialUpdateStatusNotifier 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)

Aggregations

CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)1 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)1 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)1 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)1 MaterialUpdateCompletedTopic (com.thoughtworks.go.server.materials.MaterialUpdateCompletedTopic)1 MaterialUpdateStatusNotifier (com.thoughtworks.go.server.materials.MaterialUpdateStatusNotifier)1 MaterialUpdateSuccessfulMessage (com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage)1 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)1 ManualBuild (com.thoughtworks.go.server.service.ManualBuild)1 ServerHealthStateOperationResult (com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1