Search in sources :

Example 51 with DependencyMaterial

use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.

the class DependencyMaterialUpdateNotifierTest method shouldRetryUpdatingMaterialsPreviouslyInProgress_OnMaterialUpdate.

@Test
public void shouldRetryUpdatingMaterialsPreviouslyInProgress_OnMaterialUpdate() {
    Stage stage = StageMother.passedStageInstance("Stage1", "plan", "Pipeline1");
    DependencyMaterial dependencyMaterial = MaterialsMother.dependencyMaterial(stage.getIdentifier().getPipelineName(), stage.getName());
    Set<DependencyMaterialConfig> schedulableMaterialConfigs = new HashSet<>(Arrays.asList((DependencyMaterialConfig) dependencyMaterial.config()));
    when(goConfigService.getSchedulableDependencyMaterials()).thenReturn(schedulableMaterialConfigs);
    when(materialConfigConverter.toMaterial(dependencyMaterial.config())).thenReturn(dependencyMaterial);
    when(materialUpdateService.updateMaterial(dependencyMaterial)).thenReturn(true, false);
    notifier = new DependencyMaterialUpdateNotifier(goConfigService, materialConfigConverter, materialUpdateService, serverHealthService);
    notifier.initialize();
    notifier.stageStatusChanged(stage);
    notifier.onMaterialUpdate(dependencyMaterial);
    verify(materialUpdateService, atMost(3)).updateMaterial(dependencyMaterial);
}
Also used : Stage(com.thoughtworks.go.domain.Stage) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 52 with DependencyMaterial

use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.

the class MaterialCheckerTest method shouldThrowExceptionIfSpecifiedRevisionDoesNotExist.

@Test
public void shouldThrowExceptionIfSpecifiedRevisionDoesNotExist() throws Exception {
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name"));
    Mockito.when(materialRepository.findModificationWithRevision(dependencyMaterial, "pipeline-name/500/stage-name/0")).thenReturn(null);
    try {
        materialChecker.findSpecificRevision(dependencyMaterial, "pipeline-name/500/stage-name/0");
        fail("Should not be able to find revision");
    } catch (Exception expected) {
        assertThat(expected.getMessage(), is(format("Unable to find revision [pipeline-name/500/stage-name/0] for material [%s]", dependencyMaterial)));
    }
}
Also used : DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 53 with DependencyMaterial

use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.

the class MaterialCheckerTest method shouldThrowExceptionIfRevisionIsNotSpecified.

@Test
public void shouldThrowExceptionIfRevisionIsNotSpecified() throws Exception {
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name"));
    try {
        materialChecker.findSpecificRevision(dependencyMaterial, "");
        fail("Should not be able to empty revision");
    } catch (Exception expected) {
        assertThat(expected.getMessage(), is(format("Revision was not specified for material [%s]", dependencyMaterial)));
    }
}
Also used : DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 54 with DependencyMaterial

use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.

the class MaterialCheckerTest method shouldSkipLatestRevisionsForMaterialsThatWereAlreadyChecked.

@Test
public void shouldSkipLatestRevisionsForMaterialsThatWereAlreadyChecked() throws Exception {
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name"));
    SvnMaterial svnMaterial = new SvnMaterial("svnUrl", null, null, false);
    Stage passedStage = StageMother.passedStageInstance("stage-name", "job-name", "pipeline-name");
    Modification dependencyModification = new Modification("Unknown", "Unknown", null, passedStage.completedDate(), "pipeline-name/1[LABEL-1]/stage-name/0");
    Modification svnModification = new Modification("user", "commend", "em@il", new Date(), "1");
    Mockito.when(materialRepository.findLatestModification(svnMaterial)).thenReturn(revisions(dependencyMaterial, svnModification));
    materialChecker.findLatestRevisions(new MaterialRevisions(new MaterialRevision(dependencyMaterial, dependencyModification)), new Materials(dependencyMaterial, svnMaterial));
    Mockito.verify(materialRepository, never()).findLatestModification(dependencyMaterial);
    Mockito.verify(materialRepository).findLatestModification(svnMaterial);
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) Materials(com.thoughtworks.go.config.materials.Materials) Stage(com.thoughtworks.go.domain.Stage) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Date(java.util.Date) Test(org.junit.Test)

Example 55 with DependencyMaterial

use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.

the class MaterialCheckerTest method shouldFindSpecificRevisionForDependentPipeline.

@Test
public void shouldFindSpecificRevisionForDependentPipeline() throws Exception {
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name"));
    Stage passedStage = StageMother.passedStageInstance("stage-name", "job-name", "pipeline-name");
    Modification modification = new Modification("Unknown", "Unknown", null, passedStage.completedDate(), "pipeline-name/1/stage-name/0");
    Mockito.when(materialRepository.findModificationWithRevision(dependencyMaterial, "pipeline-name/1/stage-name/0")).thenReturn(modification);
    MaterialRevision actualRevision = materialChecker.findSpecificRevision(dependencyMaterial, "pipeline-name/1/stage-name/0");
    assertThat(actualRevision.getModifications().size(), is(1));
    assertThat(actualRevision.getModification(0).getModifiedTime(), is(passedStage.completedDate()));
    assertThat(actualRevision.getModification(0).getRevision(), is("pipeline-name/1/stage-name/0"));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) Stage(com.thoughtworks.go.domain.Stage) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Aggregations

DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)97 Test (org.junit.Test)75 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)64 Modification (com.thoughtworks.go.domain.materials.Modification)30 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)29 Date (java.util.Date)22 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)19 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)17 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)16 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)15 Stage (com.thoughtworks.go.domain.Stage)14 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)13 Materials (com.thoughtworks.go.config.materials.Materials)12 Username (com.thoughtworks.go.server.domain.Username)12 Pipeline (com.thoughtworks.go.domain.Pipeline)11 DependencyMaterialRevision (com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision)11 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)10 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)10 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)10 P4Material (com.thoughtworks.go.config.materials.perforce.P4Material)9