Search in sources :

Example 56 with DependencyMaterial

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

the class MaterialCheckerTest method shouldSkipFindingRevisionsSinceForMaterialsThatWereAlreadyChecked.

@Test
public void shouldSkipFindingRevisionsSinceForMaterialsThatWereAlreadyChecked() 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");
    MaterialRevision previousDependantRevision = new MaterialRevision(dependencyMaterial, new Modification("Unknown", "Unknown", null, passedStage.completedDate(), "pipeline-name/1[LABEL-1]/stage-name/0"));
    Modification dependencyModification = new Modification("Unknown", "Unknown", null, passedStage.completedDate(), "pipeline-name/2[LABEL-2]/stage-name/0");
    MaterialRevision previousSvnRevision = new MaterialRevision(svnMaterial, mod(1L));
    Modification svnModification = new Modification("user", "commend", "em@il", new Date(), "2");
    Mockito.when(materialRepository.findModificationsSince(svnMaterial, previousSvnRevision)).thenReturn(modifications(svnModification));
    MaterialRevisions alreadyFoundRevisions = new MaterialRevisions(new MaterialRevision(dependencyMaterial, dependencyModification));
    // will not be used, as no new materials have appeared
    MaterialRevisions latestRevisions = new MaterialRevisions();
    MaterialRevisions revisionsSince = materialChecker.findRevisionsSince(alreadyFoundRevisions, new Materials(dependencyMaterial, svnMaterial), new MaterialRevisions(previousDependantRevision, previousSvnRevision), latestRevisions);
    assertThat(revisionsSince, is(new MaterialRevisions(new MaterialRevision(dependencyMaterial, dependencyModification), new MaterialRevision(svnMaterial, svnModification))));
    Mockito.verify(materialRepository, never()).findLatestModification(dependencyMaterial);
    Mockito.verify(materialRepository).findModificationsSince(svnMaterial, previousSvnRevision);
}
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 57 with DependencyMaterial

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

the class MaterialCheckerTest method shouldUseLatestMaterialDuringCreationOfNewRevisionsSince_bug7486.

@Test
public void shouldUseLatestMaterialDuringCreationOfNewRevisionsSince_bug7486() throws Exception {
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name"));
    PackageMaterial oldPkgMaterial = MaterialsMother.packageMaterial("repo-id", "repo-old-name", "pkg-id", "pkg-old-name", ConfigurationPropertyMother.create("key", false, "value"));
    Stage passedStage = StageMother.passedStageInstance("stage-name", "job-name", "pipeline-name");
    MaterialRevision previousDependantRevision = new MaterialRevision(dependencyMaterial, new Modification("Unknown", "Unknown", null, passedStage.completedDate(), "pipeline-name/1[LABEL-1]/stage-name/0"));
    Modification dependencyModification = new Modification("Unknown", "Unknown", null, passedStage.completedDate(), "pipeline-name/2[LABEL-2]/stage-name/0");
    Modification oldPkgMod = mod(1L);
    MaterialRevision previousPkgRevision = new MaterialRevision(oldPkgMaterial, oldPkgMod);
    PackageMaterial newPkgMaterial = MaterialsMother.packageMaterial("repo-id", "repo-new-name", "pkg-id", "pkg-new-name", ConfigurationPropertyMother.create("key", false, "value"));
    Modification newPkgMod = mod(2L);
    Mockito.when(materialRepository.findModificationsSince(oldPkgMaterial, previousPkgRevision)).thenReturn(modifications(newPkgMod));
    MaterialRevisions alreadyFoundRevisions = new MaterialRevisions(new MaterialRevision(dependencyMaterial, dependencyModification));
    // will not be used, as no new materials have appeared
    MaterialRevisions latestRevisions = new MaterialRevisions();
    MaterialRevisions revisionsSince = materialChecker.findRevisionsSince(alreadyFoundRevisions, new Materials(dependencyMaterial, newPkgMaterial), new MaterialRevisions(previousDependantRevision, previousPkgRevision), latestRevisions);
    assertThat(revisionsSince, is(new MaterialRevisions(new MaterialRevision(dependencyMaterial, dependencyModification), new MaterialRevision(oldPkgMaterial, newPkgMod))));
    // since name is not part of equals
    assertThat(((PackageMaterial) revisionsSince.getMaterialRevision(1).getMaterial()).getPackageDefinition().getName(), is("pkg-new-name"));
    assertThat(((PackageMaterial) revisionsSince.getMaterialRevision(1).getMaterial()).getPackageDefinition().getRepository().getName(), is("repo-new-name"));
    Mockito.verify(materialRepository, never()).findLatestModification(dependencyMaterial);
    Mockito.verify(materialRepository).findModificationsSince(oldPkgMaterial, previousPkgRevision);
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) PackageMaterial(com.thoughtworks.go.config.materials.PackageMaterial) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) 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) Test(org.junit.Test)

Example 58 with DependencyMaterial

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

the class SpecificMaterialRevisionFactoryTest method shouldThrowExceptionWhenSpecifiedRevisionDoesNotExist.

@Test
public void shouldThrowExceptionWhenSpecifiedRevisionDoesNotExist() throws Exception {
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("upstream-pipeline"), new CaseInsensitiveString("blah-stage"));
    when(mockGoConfigService.findMaterial(new CaseInsensitiveString("blahPipeline"), dependencyMaterial.getPipelineUniqueFingerprint())).thenReturn(dependencyMaterial.config());
    when(materialConfigConverter.toMaterial(dependencyMaterial.config())).thenReturn(dependencyMaterial);
    when(mockMaterialChecker.findSpecificRevision(dependencyMaterial, "upstream-pipeline/500/blah-stage/2")).thenThrow(new RuntimeException("revision not found"));
    try {
        specificMaterialRevisionFactory.create("blahPipeline", Collections.singletonMap(dependencyMaterial.getPipelineUniqueFingerprint(), "upstream-pipeline/500/blah-stage/2"));
        fail("Should not be able to find revision");
    } catch (Exception expected) {
        assertThat(expected.getMessage(), is("revision not found"));
    }
}
Also used : DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 59 with DependencyMaterial

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

the class AutoBuildTriangleDependencyTest method should_useTriangleDependencyResolution_whenFainInIsOptedOut.

@Test
public void should_useTriangleDependencyResolution_whenFainInIsOptedOut() throws Exception {
    SystemEnvironment systemEnvironment = mock(SystemEnvironment.class);
    when(systemEnvironment.enforceRevisionCompatibilityWithUpstream()).thenReturn(false);
    String pipelineName = "downstream";
    PipelineConfigDependencyGraph dependencyGraph = mock(PipelineConfigDependencyGraph.class);
    MaterialRevisions originalRevisions = mock(MaterialRevisions.class);
    MaterialRevisions recomputedRevisions = mock(MaterialRevisions.class);
    when(originalRevisions.isEmpty()).thenReturn(false);
    when(originalRevisions.hasDependencyMaterials()).thenReturn(true);
    when(goConfigService.upstreamDependencyGraphOf(pipelineName, cruiseConfig)).thenReturn(dependencyGraph);
    when(pipelineService.getRevisionsBasedOnDependencies(dependencyGraph, originalRevisions)).thenReturn(recomputedRevisions);
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("pipeline"), new CaseInsensitiveString("stage"));
    when(dependencyGraph.unsharedMaterialConfigs()).thenReturn(new MaterialConfigs(dependencyMaterial.config()));
    when(originalRevisions.findRevisionFor(dependencyMaterial)).thenReturn(new MaterialRevision(dependencyMaterial, new Modification()));
    AutoBuild autoBuild = new AutoBuild(goConfigService, pipelineService, pipelineName, systemEnvironment, materialChecker);
    AutoBuild spyAutoBuild = spy(autoBuild);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return true;
        }
    }).when(spyAutoBuild).hasAnyUnsharedMaterialChanged(dependencyGraph, originalRevisions);
    BuildCause buildCause = spyAutoBuild.onModifications(originalRevisions, false, null);
    verify(pipelineService).getRevisionsBasedOnDependencies(dependencyGraph, originalRevisions);
    verify(pipelineService, never()).getRevisionsBasedOnDependencies(any(MaterialRevisions.class), any(BasicCruiseConfig.class), any(CaseInsensitiveString.class));
    assertThat(buildCause.getMaterialRevisions(), is(recomputedRevisions));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) Modification(com.thoughtworks.go.domain.materials.Modification) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) Test(org.junit.Test)

Example 60 with DependencyMaterial

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

the class MaterialRevisionsJsonBuilderTest method shouldRenderDependencyMaterialRevision.

@Test
public void shouldRenderDependencyMaterialRevision() {
    String revision = "cruise/10/dev/1";
    MaterialRevisions revisions = new MaterialRevisions(new MaterialRevision(new DependencyMaterial(new CaseInsensitiveString("cruise"), new CaseInsensitiveString("dev")), new Modification(new Date(), revision, "MOCK_LABEL-12", null)));
    MaterialRevisionsJsonBuilder jsonBuilder = new MaterialRevisionsJsonBuilder(new TrackingTool());
    revisions.accept(jsonBuilder);
    JsonValue revisionsJson = JsonUtils.from(jsonBuilder.json());
    assertThat(revisionsJson.getString(0, "revision_href"), is("pipelines/" + revision));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) JsonValue(com.thoughtworks.go.util.JsonValue) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Date(java.util.Date) TrackingTool(com.thoughtworks.go.config.TrackingTool) 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