Search in sources :

Example 16 with HgMaterial

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

Example 17 with HgMaterial

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

Example 18 with HgMaterial

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));
}
Also used : MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) Test(org.junit.Test)

Example 19 with HgMaterial

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());
}
Also used : ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) 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) Test(org.junit.Test)

Example 20 with HgMaterial

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));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Material(com.thoughtworks.go.domain.materials.Material) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Aggregations

HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)121 Test (org.junit.Test)107 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)34 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)29 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)23 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)23 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)20 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)18 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)16 Material (com.thoughtworks.go.domain.materials.Material)15 P4Material (com.thoughtworks.go.config.materials.perforce.P4Material)10 ServerHealthStateOperationResult (com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult)10 Date (java.util.Date)10 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)9 ScheduleTestUtil (com.thoughtworks.go.server.service.ScheduleTestUtil)9 TimeProvider (com.thoughtworks.go.util.TimeProvider)8 Pagination (com.thoughtworks.go.server.util.Pagination)7 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)6 Modification (com.thoughtworks.go.domain.materials.Modification)6 File (java.io.File)6