Search in sources :

Example 51 with ServerHealthStateOperationResult

use of com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult in project gocd by gocd.

the class BuildCauseProducerServiceTest method shouldBeAbleToPassInSpecificRevisionForMaterialsAndScheduleABuild.

@Test
public void shouldBeAbleToPassInSpecificRevisionForMaterialsAndScheduleABuild() throws Exception {
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("upstream-pipeline"), new CaseInsensitiveString("stage"));
    SvnMaterial svnMaterial = new SvnMaterial("url", null, null, false);
    pipelineConfig.addMaterialConfig(dependencyMaterial.config());
    pipelineConfig.addMaterialConfig(svnMaterial.config());
    List<Modification> svnModifications = ModificationsMother.multipleModificationList();
    MaterialConfigs knownMaterialConfigs = new MaterialConfigs(pipelineConfig.materialConfigs());
    MaterialRevision specificMaterialRevision = new MaterialRevision(dependencyMaterial, new Modification(new Date(), "upstream-pipeline/2/stage/1", "MOCK_LABEL-12", null));
    when(specificMaterialRevisionFactory.create(eq("pipeline"), eq(Collections.singletonMap(dependencyMaterial.getPipelineUniqueFingerprint(), "upstream-pipeline/2/stage/1")))).thenReturn(new MaterialRevisions(specificMaterialRevision));
    when(pipelineScheduleQueue.mostRecentScheduled(new CaseInsensitiveString("pipeline"))).thenReturn(BuildCause.createNeverRun());
    when(materialRepository.findLatestModification(svnMaterial)).thenReturn(new MaterialRevisions(new MaterialRevision(svnMaterial, svnModifications)));
    when(materialConfigConverter.toMaterials(pipelineConfig.materialConfigs())).thenReturn(new Materials(dependencyMaterial, svnMaterial));
    when(materialExpansionService.expandMaterialConfigsForScheduling(pipelineConfig.materialConfigs())).thenReturn(knownMaterialConfigs);
    when(materialConfigConverter.toMaterials(knownMaterialConfigs)).thenReturn(new Materials(dependencyMaterial, svnMaterial));
    ManualBuild buildType = new ManualBuild(Username.ANONYMOUS);
    final HashMap<String, String> stringStringHashMap = new HashMap<>();
    buildCauseProducerService.newProduceBuildCause(pipelineConfig, buildType, new ScheduleOptions(Collections.singletonMap(dependencyMaterial.getPipelineUniqueFingerprint(), "upstream-pipeline/2/stage/1"), stringStringHashMap, new HashMap<>()), new ServerHealthStateOperationResult(), 12345);
    verify(pipelineScheduleQueue).schedule(eq(new CaseInsensitiveString("pipeline")), argThat(containsRevisions(new MaterialRevision(svnMaterial, svnModifications), specificMaterialRevision)));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) Materials(com.thoughtworks.go.config.materials.Materials) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) Test(org.junit.jupiter.api.Test)

Example 52 with ServerHealthStateOperationResult

use of com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult in project gocd by gocd.

the class BuildCauseProducerServiceTest method shouldCheckForModificationsWhenManuallyScheduling.

@Test
public void shouldCheckForModificationsWhenManuallyScheduling() throws Exception {
    HgMaterialConfig hgMaterialConfig = hg("url", null);
    HgMaterial hgMaterial = new HgMaterial("url", null);
    SvnMaterial svnMaterial = new SvnMaterial("url", null, null, false);
    SvnMaterialConfig svnMaterialConfig = svn("url", null, null, false);
    pipelineConfig.addMaterialConfig(hgMaterialConfig);
    pipelineConfig.addMaterialConfig(svnMaterialConfig);
    when(materialConfigConverter.toMaterial(hgMaterialConfig)).thenReturn(hgMaterial);
    when(materialConfigConverter.toMaterial(svnMaterialConfig)).thenReturn(svnMaterial);
    ServerHealthStateOperationResult result = new ServerHealthStateOperationResult();
    buildCauseProducerService.manualSchedulePipeline(Username.ANONYMOUS, pipelineConfig.name(), new ScheduleOptions(), result);
    assertThat(result.getServerHealthState().isSuccess(), is(true));
    verify(mockMaterialUpdateService, times(2)).updateMaterial(any(Material.class));
    verify(mockMaterialUpdateStatusNotifier).registerListenerFor(eq(pipelineConfig), any(MaterialUpdateStatusListener.class));
}
Also used : SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) Test(org.junit.jupiter.api.Test)

Example 53 with ServerHealthStateOperationResult

use of com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult in project gocd by gocd.

the class BuildCauseProducerServiceTest method manualTriggerShouldNotTriggerThePipelineIfMaterialUpdateFailed.

@Test
public void manualTriggerShouldNotTriggerThePipelineIfMaterialUpdateFailed() throws Exception {
    HgMaterialConfig hgMaterialConfig = hg("url", null);
    HgMaterial hgMaterial = new HgMaterial("url", null);
    pipelineConfig.addMaterialConfig(hgMaterialConfig);
    when(materialConfigConverter.toMaterial(hgMaterialConfig)).thenReturn(hgMaterial);
    buildCauseProducerService.manualSchedulePipeline(Username.ANONYMOUS, pipelineConfig.name(), new ScheduleOptions(), new ServerHealthStateOperationResult());
    sendMaterialUpdateFailedMessage(extractMaterialListenerInstanceFromRegisterCall(), hgMaterial);
    assertThat(triggerMonitor.isAlreadyTriggered(pipelineConfig.name()), is(false));
}
Also used : HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) Test(org.junit.jupiter.api.Test)

Example 54 with ServerHealthStateOperationResult

use of com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult in project gocd by gocd.

the class BuildCauseProducerServiceTest method shouldUpdateOnlyOnceIfThereAreTwoMaterialsWithSameFingerPrintButDifferentDest.

@Test
public void shouldUpdateOnlyOnceIfThereAreTwoMaterialsWithSameFingerPrintButDifferentDest() {
    HgMaterial material1 = new HgMaterial("url", null);
    HgMaterial material2 = new HgMaterial("url", null);
    HgMaterialConfig materialConfig1 = hg("url", null);
    HgMaterialConfig materialConfig2 = hg("url", null);
    material1.setFolder("folder1");
    material2.setFolder("folder2");
    assertThat(material1.getFingerprint(), is(material2.getFingerprint()));
    pipelineConfig.addMaterialConfig(materialConfig1);
    pipelineConfig.addMaterialConfig(materialConfig2);
    Material[] materials = new Material[] { material1, material2 };
    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(mockMaterialUpdateService, times(1)).updateMaterial(any(Material.class));
    MaterialUpdateStatusListener statusListener = extractMaterialListenerInstanceFromRegisterCall();
    statusListener.onMaterialUpdate(new MaterialUpdateFailedMessage(materials[0], 0, new Exception("Cannot connect to repo")));
    verify(mockMaterialUpdateStatusNotifier).removeListenerFor(pipelineConfig);
}
Also used : HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) Test(org.junit.jupiter.api.Test)

Example 55 with ServerHealthStateOperationResult

use of com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult in project gocd by gocd.

the class ArtifactsDiskSpaceFullCheckerTest method shouldSendEmailAgainIfProblemOccuresAgain.

@Test
public void shouldSendEmailAgainIfProblemOccuresAgain() throws Exception {
    when(goConfigService.adminEmail()).thenReturn("admin@tw.com");
    full.onSetUp();
    // should send email this time
    checker.check(new ServerHealthStateOperationResult());
    full.onTearDown();
    // should not send email
    checker.check(new ServerHealthStateOperationResult());
    full.onSetUp();
    // should send email again
    checker.check(new ServerHealthStateOperationResult());
    verify(emailSender, times(2)).sendEmail(any(SendEmailMessage.class));
}
Also used : SendEmailMessage(com.thoughtworks.go.server.messaging.SendEmailMessage) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) Test(org.junit.jupiter.api.Test)

Aggregations

ServerHealthStateOperationResult (com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult)89 Test (org.junit.jupiter.api.Test)78 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)28 ScheduleOptions (com.thoughtworks.go.server.scheduling.ScheduleOptions)17 HashMap (java.util.HashMap)17 Pipeline (com.thoughtworks.go.domain.Pipeline)16 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)15 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)12 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)12 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)11 Modification (com.thoughtworks.go.domain.materials.Modification)10 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)8 Username (com.thoughtworks.go.server.domain.Username)8 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)6 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)6 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)6 SendEmailMessage (com.thoughtworks.go.server.messaging.SendEmailMessage)6 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)5 Materials (com.thoughtworks.go.config.materials.Materials)5 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)5