Search in sources :

Example 61 with MaterialRevisions

use of com.thoughtworks.go.domain.MaterialRevisions in project gocd by gocd.

the class PipelineServiceTriangleDependencyTest method shouldGetTheRevisionsForDependencyMaterialFromUpStreamPipeline.

@Test
public void shouldGetTheRevisionsForDependencyMaterialFromUpStreamPipeline() throws Exception {
    Date modifiedTime = new Date();
    MaterialRevisions expected = new MaterialRevisions();
    expected.addRevision(dependencyMaterialRevision("up1", 1, "label", "stage", 1, modifiedTime));
    expected.addRevision(dependencyMaterialRevision("common", 3, "label", "first", 1, modifiedTime));
    MaterialRevisions actual = new MaterialRevisions();
    actual.addRevision(changedDependencyMaterialRevision("up1", 1, "label", "stage", 1, modifiedTime));
    actual.addRevision(dependencyMaterialRevision("common", 4, "label", "first", 1, modifiedTime));
    PipelineConfig current = createPipelineConfigWithMaterialConfig("current", new DependencyMaterialConfig(new CaseInsensitiveString("common"), new CaseInsensitiveString("first")), new DependencyMaterialConfig(new CaseInsensitiveString("up1"), new CaseInsensitiveString("first")));
    PipelineConfig up1 = createPipelineConfigWithMaterialConfig("up1", new DependencyMaterialConfig(new CaseInsensitiveString("common"), new CaseInsensitiveString("first")));
    PipelineConfig common = createPipelineConfigWithMaterialConfig("common", MaterialConfigsMother.hgMaterialConfig());
    Pipeline pipeline = PipelineMother.passedPipelineInstance("up1", "stage", "job");
    pipeline.setId(10);
    when(pipelineDao.findPipelineByNameAndCounter("up1", 1)).thenReturn(pipeline);
    MaterialRevisions upStreamPipelinesRevisions = new MaterialRevisions();
    upStreamPipelinesRevisions.addRevision(dependencyMaterialRevision("common", 3, "label", "first", 1, modifiedTime));
    when(materialRepository.findMaterialRevisionsForPipeline(10)).thenReturn(upStreamPipelinesRevisions);
    PipelineConfigDependencyGraph dependencyGraph = new PipelineConfigDependencyGraph(current, new PipelineConfigDependencyGraph(up1, new PipelineConfigDependencyGraph(common)));
    MaterialRevisions finalRevisions = service.getRevisionsBasedOnDependencies(dependencyGraph, actual);
    assertThat(finalRevisions, is(expected));
    for (int i = 0; i < expected.numberOfRevisions(); i++) {
        assertTrue(finalRevisions.getMaterialRevision(i) == actual.getMaterialRevision(i));
    }
}
Also used : PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Date(java.util.Date) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.Test)

Example 62 with MaterialRevisions

use of com.thoughtworks.go.domain.MaterialRevisions in project gocd by gocd.

the class PipelineServiceTriangleDependencyTest method shouldChooseTheRevisionFromSecondWhenThirdIsNotModifiedInspiteOfSecondBeingFirstMaterialInConfig.

@Test
public void shouldChooseTheRevisionFromSecondWhenThirdIsNotModifiedInspiteOfSecondBeingFirstMaterialInConfig() throws Exception {
    // Third <- Second*
    // |     /
    // |   /
    // Last
    // 
    // * indicates changed
    Date date = new Date();
    MaterialRevisionBuilder builder = new MaterialRevisionBuilder(pipelineDao, materialRepository);
    PipelineConfigDependencyGraph graph = builder.depInstance("last", 1, date, builder.depInstance("second", 4, date, builder.svnInstance("2", date)), builder.depInstance("third", 3, date, builder.depInstance("second", 2, date, builder.svnInstance("1", date)))).getGraph();
    MaterialRevisions actual = new MaterialRevisions();
    actual.addRevision(builder.lookingAtDep("second", 4, date).markAsChanged().revision());
    actual.addRevision(builder.lookingAtDep("third", 3, date).revision());
    MaterialRevisions expected = new MaterialRevisions();
    expected.addRevision(builder.depInstance("second", 4, date).getRevision());
    expected.addRevision(builder.depInstance("third", 3, date).getRevision());
    MaterialRevisions finalRevisions = service.getRevisionsBasedOnDependencies(graph, actual);
    assertThat(finalRevisions, is(expected));
    for (int i = 0; i < expected.numberOfRevisions(); i++) {
        assertTrue(finalRevisions.getMaterialRevision(i) == actual.getMaterialRevision(i));
    }
}
Also used : PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) MaterialRevisionBuilder(com.thoughtworks.go.server.functional.helpers.MaterialRevisionBuilder) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Date(java.util.Date) Test(org.junit.Test)

Example 63 with MaterialRevisions

use of com.thoughtworks.go.domain.MaterialRevisions in project gocd by gocd.

the class PipelineServiceTriangleDependencyTest method shouldGetTheRevisionsFromTheUpStreamPipelineFor2SameMaterial.

@Test
public void shouldGetTheRevisionsFromTheUpStreamPipelineFor2SameMaterial() throws Exception {
    MaterialRevision up1Revision = dependencyMaterialRevision("up1", 1, "label", "stage", 1, new Date());
    up1Revision.markAsChanged();
    MaterialRevisions expected = new MaterialRevisions();
    expected.addRevision(up1Revision);
    expected.addAll(createHgMaterialWithMultipleRevisions(1L, first));
    expected.addAll(createSvnMaterialWithMultipleRevisions(2L, first));
    MaterialRevisions actual = new MaterialRevisions();
    actual.addRevision(up1Revision);
    actual.addAll(createHgMaterialWithMultipleRevisions(1L, third));
    actual.addAll(createSvnMaterialWithMultipleRevisions(2L, third));
    PipelineConfig current = createPipelineConfigWithMaterialConfig("current", new DependencyMaterialConfig(new CaseInsensitiveString("up1"), new CaseInsensitiveString("first")), MaterialConfigsMother.hgMaterialConfig(), MaterialConfigsMother.svnMaterialConfig());
    PipelineConfig up1 = createPipelineConfigWithMaterialConfig("up1", MaterialConfigsMother.hgMaterialConfig(), MaterialConfigsMother.svnMaterialConfig());
    Pipeline pipeline = PipelineMother.passedPipelineInstance("up1", "stage", "job");
    pipeline.setId(10);
    when(pipelineDao.findPipelineByNameAndCounter("up1", 1)).thenReturn(pipeline);
    when(materialRepository.findMaterialRevisionsForPipeline(10)).thenReturn(expected);
    PipelineConfigDependencyGraph dependencyGraph = new PipelineConfigDependencyGraph(current, new PipelineConfigDependencyGraph(up1));
    assertThat(service.getRevisionsBasedOnDependencies(dependencyGraph, actual), is(expected));
}
Also used : PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) ModificationsMother.dependencyMaterialRevision(com.thoughtworks.go.helper.ModificationsMother.dependencyMaterialRevision) ModificationsMother.changedDependencyMaterialRevision(com.thoughtworks.go.helper.ModificationsMother.changedDependencyMaterialRevision) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Date(java.util.Date) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.Test)

Example 64 with MaterialRevisions

use of com.thoughtworks.go.domain.MaterialRevisions in project gocd by gocd.

the class PipelineServiceTriangleDependencyTest method shouldChooseTheRevisionFromSecondWhenThirdIsNotModified.

@Test
public void shouldChooseTheRevisionFromSecondWhenThirdIsNotModified() throws Exception {
    // Third <- Second*
    // |     /
    // |   /
    // Last
    // 
    // * indicates changed
    Date date = new Date();
    MaterialRevisionBuilder builder = new MaterialRevisionBuilder(pipelineDao, materialRepository);
    PipelineConfigDependencyGraph graph = builder.depInstance("last", 1, date, builder.depInstance("third", 3, date, builder.depInstance("second", 2, date, builder.svnInstance("1", date))), builder.depInstance("second", 4, date, builder.svnInstance("2", date))).getGraph();
    MaterialRevisions actual = new MaterialRevisions();
    actual.addRevision(builder.lookingAtDep("third", 3, date).revision());
    actual.addRevision(builder.lookingAtDep("second", 4, date).markAsChanged().revision());
    MaterialRevisions expected = new MaterialRevisions();
    expected.addRevision(builder.depInstance("third", 3, date).getRevision());
    expected.addRevision(builder.depInstance("second", 4, date).getRevision());
    MaterialRevisions finalRevisions = service.getRevisionsBasedOnDependencies(graph, actual);
    assertThat(finalRevisions, is(expected));
    for (int i = 0; i < expected.numberOfRevisions(); i++) {
        assertTrue(finalRevisions.getMaterialRevision(i) == actual.getMaterialRevision(i));
    }
}
Also used : PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) MaterialRevisionBuilder(com.thoughtworks.go.server.functional.helpers.MaterialRevisionBuilder) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Date(java.util.Date) Test(org.junit.Test)

Example 65 with MaterialRevisions

use of com.thoughtworks.go.domain.MaterialRevisions in project gocd by gocd.

the class PipelineServiceTriangleDependencyTest method shouldChooseTheRevisionFromSecondInAComplexSituation.

@Test
public void shouldChooseTheRevisionFromSecondInAComplexSituation() throws Exception {
    // hg -> First          git
    // |      \             |
    // |      Third  <- Second*
    // |        |      /
    // |        |    /
    // +------> Last
    // 
    // * indicates changed
    Date date = new Date();
    MaterialRevisionBuilder builder = new MaterialRevisionBuilder(pipelineDao, materialRepository);
    PipelineConfigDependencyGraph graph = builder.depInstance("last", 1, date, builder.hgInstance("rev2", date), builder.depInstance("second", 4, date, builder.svnInstance("2", date)), builder.depInstance("third", 3, date, builder.depInstance("first", 1, date, builder.hgInstance("rev1", date)), builder.depInstance("second", 2, date, builder.svnInstance("1", date)))).getGraph();
    MaterialRevisions actual = new MaterialRevisions();
    actual.addRevision(builder.lookingAtHg("rev2", date).markAsChanged().revision());
    actual.addRevision(builder.lookingAtDep("second", 4, date).markAsChanged().revision());
    actual.addRevision(builder.lookingAtDep("third", 3, date).markAsChanged().revision());
    MaterialRevisions expected = new MaterialRevisions();
    expected.addRevision(builder.hgInstance("rev1", date).getRevision());
    expected.addRevision(builder.depInstance("second", 2, date).getRevision());
    expected.addRevision(builder.depInstance("third", 3, date).getRevision());
    MaterialRevisions finalRevisions = service.getRevisionsBasedOnDependencies(graph, actual);
    assertThat(finalRevisions, is(expected));
    for (int i = 0; i < expected.numberOfRevisions(); i++) {
        assertTrue(finalRevisions.getMaterialRevision(i) == actual.getMaterialRevision(i));
    }
}
Also used : PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) MaterialRevisionBuilder(com.thoughtworks.go.server.functional.helpers.MaterialRevisionBuilder) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Date(java.util.Date) Test(org.junit.Test)

Aggregations

MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)212 Test (org.junit.Test)166 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)111 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)68 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)55 Date (java.util.Date)49 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)46 Modification (com.thoughtworks.go.domain.materials.Modification)38 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)33 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)33 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)31 PipelineConfigDependencyGraph (com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph)31 Materials (com.thoughtworks.go.config.materials.Materials)27 Pipeline (com.thoughtworks.go.domain.Pipeline)20 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)19 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)17 Material (com.thoughtworks.go.domain.materials.Material)16 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)15 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)14 File (java.io.File)12